简体   繁体   English

仅C ++系统托盘程序

[英]C++ system tray only program

After checking Microsoft's documentation on system tray icons (that I could find): 在检查了Microsoft关于系统任务栏图标的文档(我可以找到)之后:

Shell_NotifyIconA function Shell_NotifyIconA函数

NOTIFYICONDATAA structure NOTIFYICONDATAA结构

I've noticed that a window handle (HWND) is REQUIRED. 我注意到需要一个窗口句柄(HWND)。 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? 我将如何去做呢?

The Windows 7 SDK contains an example called NotificationIcon . Windows 7 SDK包含一个名为NotificationIcon的示例。 This example contains a line 本示例包含一行

ShowWindow(hwnd, nCmdShow);

in its wWinMain function. 在其wWinMain函数中。 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. 正如其他人指出的那样,该程序需要一个程序窗口,即使该窗口不可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM