如何保持我最顶层的窗口? [英] How to keep my topmost window on top?

查看:192
本文介绍了如何保持我最顶层的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会先解释为什么我需要它,因为我预计第一个响应将是你为什么需要它?我想检测何时鼠标光标在屏幕的边缘,我不想使用钩子。因此,我创建了一个像素宽的TOPMOST不可见窗口。



我在Win XP上使用C ++,所以当窗口创建时(CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT ...)一切正常。



不幸的是,如果用户移动另一个最顶层的窗口,例如我的窗口上的任务栏,我不会得到鼠标移动。



尝试解决这个问题类似于建议的方法:
如何保持MDI窗口始终在顶部



我尝试使用

首先检查WM_WINDOWPOSCHANGED中最顶层窗口的Z顺序。

  case WM_WINDOWPOSCHANGED:
WINDOWPOS * pWP =(WINDOWPOS *)lParam;

- > hwnd指向我的窗口,pWP-> hwndInsertAfter是0,这意味着我的窗口在Z的顶部,即使它被任务栏覆盖,然后我尝试:



case WM_WINDOWPOSCHANGED:
HWND topWndHndl = GetNextWindow(myHandle,GW_HWNDPREV)
GetWindowText(topWndHndl,pszMem,cTxtLen + 1);

我总是得到默认IME窗口在我的窗口顶部。即使尝试使我的窗口与SetWindowPos()或BringWindowToTop(),顶部,默认IME保持在顶部。我不知道什么是默认IME,以及如何检测任务栏是否在我的窗口顶部。



所以我的问题是:如何检测我的最顶层窗口不是最顶层的窗口,如何保持顶部?



PS我知道一个暴力的方法定期把我的窗口顶部的工作,但是是丑陋的,可能有一些不必要的推断与通知窗口例如。 (将我的窗口顶部隐藏通知窗口。)



感谢您的时间和建议!

解决方案

TopMost,总是一个棘手的事情。没有办法重写另一个指定为TopMost的窗口。





还有一个重复的这是


I will first explain why I need it, because I anticipate that the first response will be "Why do you need it?". I want to detect when the mouse cursor is on an edge of the screen and I don't want to use hooks. Hence, I created one pixel wide TOPMOST invisible window.

I am using C++ on Win XP, so when the window is created (CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT ...) everything works fine.

Unfortunately, if a user moves another topmost window, for example the taskbar over my window, I don't get mouse movements.

I tried to solve this similarly to approaches suggested in: How To Keep an MDI Window Always on Top

I tried to check for Z-order of my topmost window in WM_WINDOWPOSCHANGED first with

case WM_WINDOWPOSCHANGED :
    WINDOWPOS* pWP = (WINDOWPOS*)lParam;

yet pWP->hwnd points to my window and pWP->hwndInsertAfter is 0, which should mean that my window is on the top of the Z, even though it is covered with the taskbar. Then I tried:

case WM_WINDOWPOSCHANGED :
    HWND topWndHndl = GetNextWindow(myHandle, GW_HWNDPREV)
    GetWindowText(topWndHndl, pszMem, cTxtLen + 1);

and I'll always get that the "Default IME" window is on top of my window. Even if try to bring my window to the top with SetWindowPos() or BringWindowToTop (), "Default IME" stays on the top. I don't know what is "Default IME" and how to detect if the taskbar is on top of my window.

So my question is: How to detect that my topmost window is not the top topmost window anymore and how to keep it on the top?

P.S. I know that a "brute force" approach of periodically bringing my window to the top works, yet is ugly and could have some unwanted inference with the notification window for example. (Bringing my window to the top will hide the notification window.)

Thank you on your time and suggestions!

解决方案

TopMost, is always a tricky thing. There is no way to override another window that specifies itself as TopMost.

Raymond Chen has a good article on this.

Also a duplicate of this.

这篇关于如何保持我最顶层的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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