Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将WindowPos设置在其他窗口的上方_C#_Winforms_Winapi_User32 - Fatal编程技术网

C# 将WindowPos设置在其他窗口的上方

C# 将WindowPos设置在其他窗口的上方,c#,winforms,winapi,user32,C#,Winforms,Winapi,User32,所以,我有一份申请。我希望它始终位于目标应用程序正上方一个z级别。它只是将在标题栏中显示一条状态消息,这很难看,但这是我必须满足的要求 像这样: 我研究了WM\u NCPAINT,但在项目的这一阶段(原型设计/提案)这并不是一个切实可行的解决方案 我在user32.dll中发现了SetWindowPos()函数: [DllImport("user32.dll", SetLastError = true)] static extern bool SetWindowPos(IntPtr hWnd,

所以,我有一份申请。我希望它始终位于目标应用程序正上方一个z级别。它只是将在标题栏中显示一条状态消息,这很难看,但这是我必须满足的要求

像这样:

我研究了
WM\u NCPAINT
,但在项目的这一阶段(原型设计/提案)这并不是一个切实可行的解决方案

我在
user32.dll
中发现了
SetWindowPos()
函数:

[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, Swp uFlags);
并通过以下方式钩住(所有应用程序的)所有z级相关事件:

这似乎在某种程度上起了作用。但是,由于我只能设置为直接位于目标应用程序的后面,因此我必须调用两次
SetWindowPos()
,以实现此目的,一次获取目标程序的z级别,一次交换两个:

    private void ZOrderChanged(IntPtr hWinEventHook, uint eventType, IntPtr lParam, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
    {
        SetWindowPos(Handle, _foxViewHWnd, 0, 0, 0, 0, Swp.Noactivate | Swp.Nomove | Swp.Nosize);
        SetWindowPos(_foxViewHWnd, Handle, 0, 0, 0, 0, Swp.Noactivate | Swp.Nomove | Swp.Nosize);
    }

这是低效的,闪烁和代码气味的气味,有人知道如何避免吗?

您不是在寻找窗口所有权吗?当我的目标应用程序是完全外部的时,窗口所有权是否适用?(以notepad.exe为例)你没有解释为什么要这样做,这当然是一件很遗憾的事。要求解决您未指定的问题是子问题optimal@DavidHeffernan请查看我的更新,我将查看您的链接,因此我已尝试:
SetWindowLongPtr(_-foxViewHWnd,-8,Handle)这似乎不起作用
    private void ZOrderChanged(IntPtr hWinEventHook, uint eventType, IntPtr lParam, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
    {
        SetWindowPos(Handle, _foxViewHWnd, 0, 0, 0, 0, Swp.Noactivate | Swp.Nomove | Swp.Nosize);
        SetWindowPos(_foxViewHWnd, Handle, 0, 0, 0, 0, Swp.Noactivate | Swp.Nomove | Swp.Nosize);
    }