admin管理员组文章数量:1130349
最近在用Qt写一个gui程序,其中有个置顶QWidget需要响应鼠标移动事件以激活自身,在linux下使用activateWindow()就可以达到目的。但是windows下就没这么简单了,windows不允许应用程序中断用户正在操作的其它应用,也就意味着activateWindow()失效了。那么就真的没有办法了吗?经上网搜索,发现可以使用win32 API的几个函数实现,下面分享下我的解决办法:
1.声明需要使用的函数指针变量
/*user32.dll*/
typedef unsigned int (_stdcall*GetWindowThreadProcessId)(WId id, unsigned int *lpdwProcessId);
GetWindowThreadProcessId getWindowThreadProcessId;
typedef WId (_stdcall*GetForegroundWindow)();
GetForegroundWindow getForegroundWindow;
typedef bool (_stdcall*SetForegroundWindow)(WId id);
SetForegroundWindow setForegroundWindow;
typedef WId (_stdcall*SetFocus)(WId id);
SetFocus setFocus;
typedef bool (_stdcall*AttachThreadInput)(unsigned int idAttach, unsigned int idAttachTo, bo
最近在用Qt写一个gui程序,其中有个置顶QWidget需要响应鼠标移动事件以激活自身,在linux下使用activateWindow()就可以达到目的。但是windows下就没这么简单了,windows不允许应用程序中断用户正在操作的其它应用,也就意味着activateWindow()失效了。那么就真的没有办法了吗?经上网搜索,发现可以使用win32 API的几个函数实现,下面分享下我的解决办法:
1.声明需要使用的函数指针变量
/*user32.dll*/
typedef unsigned int (_stdcall*GetWindowThreadProcessId)(WId id, unsigned int *lpdwProcessId);
GetWindowThreadProcessId getWindowThreadProcessId;
typedef WId (_stdcall*GetForegroundWindow)();
GetForegroundWindow getForegroundWindow;
typedef bool (_stdcall*SetForegroundWindow)(WId id);
SetForegroundWindow setForegroundWindow;
typedef WId (_stdcall*SetFocus)(WId id);
SetFocus setFocus;
typedef bool (_stdcall*AttachThreadInput)(unsigned int idAttach, unsigned int idAttachTo, bo版权声明:本文标题:Windows下,Qt激活指定句柄的窗口 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1763928587a2972288.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论