【问题标题】:How to top window in WIN8/WIN10WIN8/WIN10如何置顶窗口
【发布时间】:2017-11-03 06:32:00
【问题描述】:

我尝试使用 SetWindowPos,但有人告诉我这样做是错误的。

WIN32程序,WIN8/WIN10如何置顶窗口? 比如任务管理器。

【问题讨论】:

  • 你的句子听不懂
  • 高度相关,可能重复:stackoverflow.com/questions/39246590/…
  • 你不能制作像任务管理器这样的窗口。只有操作系统才能做到这一点。
  • SetWindowPos 没什么大不了的。任何一种“我的窗户比其他任何东西都重要”的态度,97.2% 的时间都是错误的。 99.9% 在 SO 被问及。

标签: c++ windows winapi


【解决方案1】:

使窗口“最顶层”的两种方法。

当您使用CreateWindowEx 创建窗口时,将WS_EX_TOPMOST 指定为扩展样式。

CreateWindowEx(WS_EX_TOPMOST, ...);

对于现有窗口,使用 SetWindowPos:

DWORD flags = SWP_NOMOVE | SWP_NOSIZE;
SetWindowPos(hwnd, HWND_TOPMOST, 0,0,0,0, flags);

无论哪种方式都可以。

【讨论】:

  • @selble DWORD dwType = GetWindowLongPtrW(hwnd, GWL_EXSTYLE); dwType |= WS_EX_TOPMOST; SetWindowLongPtrW(hwnd, GWL_EXSTYLE, dwType); SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
  • @daijiepei - 是的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多