MS Windows-在托盘通知图标上显示菜单时主窗口没有响应(使用隐藏窗口处理消息)
我实现了一个类,这个类将显示一个托盘图标。为了处理来自图标的消息,我必须创建一个隐藏窗口。
一切正常,除非您单击图标外部,图标不会消失。我通过添加下面的代码解决了这个问题:
SetForegroundWindow(message-only-hiden-window) // 添加 TrackPopupMenu()
解决方案:要纠正第一个行为,您需要在调用 TrackPopupMenu 或 TrackPopupMenuEx 之前将当前窗口设为前台窗口。
现在我得到了预期的结果:如果您单击托盘图标之外,菜单就会消失。
现在的问题是,在调用 SetForegroundWindow(message-only-hiden-window) 之后,主应用程序窗口将没有响应(无法调整大小移动),我可以看到主窗口实际上在间谍++中获取了这些消息。 如果没有调用 SetForegroundWindow(message-only-hiden-window),请记住这一点。美好的。但菜单不会消失。
有人有类似情况的经验吗? 如何实现一个根本没有前台窗口的托盘图标?
任何形式的帮助将不胜感激。如果你想要源代码我可以发邮件给你。
I implemented an class, this class will show an tray icon. to handle the message from the icon, I have to create a hidden window.
Eevery thing works fine, except if You click outside of the icon, icon will not disappear. I have fixed this by adding code below:
SetForegroundWindow(message-only-hiden-window) // added
TrackPopupMenu()
RESOLUTION:To correct the first behavior, you need to make the current window the foreground window before calling TrackPopupMenu or TrackPopupMenuEx.
Now I get the expect result: the menu can disappear if you click outside of the tray icon.
The problem is now, after the call of SetForegroundWindow(message-only-hiden-window) the main app window will no responding(cannot resize move) I can see the main window actually get those messages in spy++.
Keep this the mind if no call on SetForegroundWindow(message-only-hiden-window). Fine. Except the menu will not disappear.
Anyone has experience on similar situation?
How do you implement an tray icon which has no foreground window at all?
Any kind of help will be appreciated. If you wanna the source code I can email you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。我忘记在仅消息窗口中返回 DefWindowProc。棘手的
resolved. I have forgot return DefWindowProc in the message only window. tricky