SetWindowPos不会将应用程序置于顶部 [英] SetWindowPos does not bring the app to top

查看:57
本文介绍了SetWindowPos不会将应用程序置于顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对SetWindowPos函数有一个奇怪的问题.此功能用于通过以下代码在应用程序上方显示:

I have a strange problem with SetWindowPos function. This function is used to bring app on top with the following code:

              if(!SetWindowPos(this.Handle,HWND_TOPMOST,0,0,0,0,NO_FOCUS_FLAGS))
               b Log.LogError("SetWindowPos HWND_TOPMOST返回false");

                    if(!SetWindowPos(this.Handle,HWND_NOTOPMOST,0,0,0,0,NO_FOCUS_FLAGS))
               b Log.LogError("SetWindowPos HWND_NOTOPMOST返回false");

                    if (!SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, NO_FOCUS_FLAGS))
                        Log.LogError("SetWindowPos HWND_TOPMOST returned false");

                    if (!SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, NO_FOCUS_FLAGS))
                        Log.LogError("SetWindowPos HWND_NOTOPMOST returned false");

在大多数情况下,我可以从Windows查看正常事件堆栈:

And in most cases I am able to see the normal events stack from Windows:

WndProc():m-msg = 0x46(WM_WINDOWPOSCHANGING)hwnd = 0x21016 wparam = 0x0 lparam = 0x20d688结果= 0x0
WndProc():m-msg = 0x14(WM_ERASEBKGND)hwnd = 0x21016 wparam = 0xffffffffc60128f1 lparam = 0x0结果= 0x0
WndProc():m-msg = 0x135(WM_CTLCOLORBTN)hwnd = 0x21016 wparam = 0xffffffff950128ae lparam = 0x40f2e结果= 0x0
WndProc():m-msg = 0x47(WM_WINDOWPOSCHANGED)hwnd = 0x21016 wparam = 0x0 lparam = 0x20d688结果= 0x0
WndProc():m-msg = 0x46(WM_WINDOWPOSCHANGING)hwnd = 0x21016 wparam = 0x0 lparam = 0x20d688结果= 0x0
WndProc():m-msg = 0x135(WM_CTLCOLORBTN)hwnd = 0x21016 wparam = 0xffffffffc60128f1 lparam = 0x40f2e结果= 0x0
WndProc():m-msg = 0x47(WM_WINDOWPOSCHANGED)hwnd = 0x21016 wparam = 0x0 lparam = 0x20d688结果= 0x0

WndProc(): m - msg=0x46 (WM_WINDOWPOSCHANGING) hwnd=0x21016 wparam=0x0 lparam=0x20d688 result=0x0
WndProc(): m - msg=0x14 (WM_ERASEBKGND) hwnd=0x21016 wparam=0xffffffffc60128f1 lparam=0x0 result=0x0
WndProc(): m - msg=0x135 (WM_CTLCOLORBTN) hwnd=0x21016 wparam=0xffffffff950128ae lparam=0x40f2e result=0x0
WndProc(): m - msg=0x47 (WM_WINDOWPOSCHANGED) hwnd=0x21016 wparam=0x0 lparam=0x20d688 result=0x0
WndProc(): m - msg=0x46 (WM_WINDOWPOSCHANGING) hwnd=0x21016 wparam=0x0 lparam=0x20d688 result=0x0
WndProc(): m - msg=0x135 (WM_CTLCOLORBTN) hwnd=0x21016 wparam=0xffffffffc60128f1 lparam=0x40f2e result=0x0
WndProc(): m - msg=0x47 (WM_WINDOWPOSCHANGED) hwnd=0x21016 wparam=0x0 lparam=0x20d688 result=0x0

但是有时我得到以下信息:

However sometimes I got the following:

WndProc():m-msg = 0x46(WM_WINDOWPOSCHANGING)hwnd = 0x104f4 wparam = 0x0 lparam = 0x3ad6cc结果= 0x0
WndProc():m-msg = 0x14(WM_ERASEBKGND)hwnd = 0x104f4 wparam = 0x26012ce9 lparam = 0x0结果= 0x0
WndProc():m-msg = 0x135(WM_CTLCOLORBTN)hwnd = 0x104f4 wparam = 0x90127a1 lparam = 0x105de结果= 0x0
WndProc():m-msg = 0x46(WM_WINDOWPOSCHANGING)hwnd = 0x104f4 wparam = 0x0 lparam = 0x3ad6cc结果= 0x0

WndProc(): m - msg=0x46 (WM_WINDOWPOSCHANGING) hwnd=0x104f4 wparam=0x0 lparam=0x3ad6cc result=0x0
WndProc(): m - msg=0x14 (WM_ERASEBKGND) hwnd=0x104f4 wparam=0x26012ce9 lparam=0x0 result=0x0
WndProc(): m - msg=0x135 (WM_CTLCOLORBTN) hwnd=0x104f4 wparam=0x90127a1 lparam=0x105de result=0x0
WndProc(): m - msg=0x46 (WM_WINDOWPOSCHANGING) hwnd=0x104f4 wparam=0x0 lparam=0x3ad6cc result=0x0

在这种情况下,SetWindowPos()返回成功,但应用程序未置于顶部.

In this case the SetWindowPos() returned success, but application was not bring to top.

这个问题很难重现,我无法轻松地对其进行测试.

This issue is too hard to reproduce and I can't test it so easily.

有人知道WM_WINDOWPOSCHANGED的缺失意味着什么吗?

Does anyone know what means missing of WM_WINDOWPOSCHANGED?

我该如何解决这个问题?

How can I address this issue?

预先感谢!

推荐答案

您似乎正在尝试玩最顶级的游戏.不要玩最顶级的游戏:

It's looks like you might be trying to play the topmost game. Don't play the topmost game:

最高/阶梯游戏

为什么要使用WndowsAPI调用将窗口设置为最顶部?除了尝试玩topmsot游戏并碰到一个更高阶梯的人.
这是Visual C#论坛,那么为什么不只对窗体或窗口使用Visual C#函数呢?

Why are you using the WndowsAPI calls to set the window topmost anyway? Aside from trying to play the topmsot game and running into someone with an even higher ladder.
This is the Visual C# forum, so why not just use the Visual C# function for the form or window?


这篇关于SetWindowPos不会将应用程序置于顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆