C++ system tray only program

泄露秘密 提交于 2021-02-11 07:41:17

问题


After checking Microsoft's documentation on system tray icons (that I could find):

Shell_NotifyIconA function

NOTIFYICONDATAA structure

I've noticed that a window handle (HWND) is REQUIRED. This is very bad for what I'm trying to accomplish, as I'm looking to create a program that only reacts to the system tray: it doesn't "minimize" the window to the tray, it just uses notifications (clicking/right clicking on the icon) to interact.

How would I go about doing this?


回答1:


The Windows 7 SDK contains an example called NotificationIcon. This example contains a line

ShowWindow(hwnd, nCmdShow);

in its wWinMain function. The effect of this call is that you see a program window.

Just change this line to

ShowWindow(hwnd, SW_HIDE);

to hide the program window and only display the icon in the system tray. As others have pointed out the program needs a program window, even if it is not visible.



来源:https://stackoverflow.com/questions/54332515/c-system-tray-only-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!