- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个作为服务运行的应用程序,以及一个监控该服务的辅助应用程序。监控应用程序使用 NOTIFYICONDATA
存在于系统托盘中,工作正常。
我目前正在尝试做的是,当应用程序注意到服务已停止时,我想显示一条通知(类似于笔记本电脑的电池电量不足)。我的代码基于 this article .我必须执行的功能如下:
void CALLBACK checkit( HWND hwnd, UINT umsg, UINT timerid, DWORD dwtime ) {
if ( isServiceRunning() ) {
if ( nidApp.dwInfoFlags != NIIF_NONE ) {
Log( "dwInfoFlags != NIFF_NONE" );
nidApp.dwInfoFlags = NIIF_NONE;
strcpy_s( nidApp.szInfoTitle, sizeof( nidApp.szInfoTitle ), "" );
strcpy_s( nidApp.szInfo, sizeof( nidApp.szInfoTitle ), "" );
Log( "%d", Shell_NotifyIcon( NIM_MODIFY, &nidApp ) );
}
} else {
if ( nidApp.dwInfoFlags != NIIF_WARNING ) {
Log( "dwInfoFlags != NIIF_WARNING" );
nidApp.dwInfoFlags = NIIF_WARNING;
strcpy_s( nidApp.szInfoTitle, sizeof( nidApp.szInfoTitle ), "Service Stopped" );
strcpy_s( nidApp.szInfo, sizeof( nidApp.szInfo ), "The " PROGRAM_NAME " service has been stopped. Any runs in progress have been terminated." );
nidApp.uTimeout = 10000;
Log( "%d", Shell_NotifyIcon( NIM_MODIFY, &nidApp ) );
}
}
}
此函数每五秒调用一次。使用日志,我能够看到 dwInfoFlags
设置正确,并且 Shell_NotifyIcon
返回 TRUE
,但是没有显示任何通知。我确定我一定遗漏了什么,但我无法弄清楚它是什么。
nidApp
在 CPP 文件的顶部定义为 NOTIFYICONDATA nidApp;
设置如下:
hMainIcon = LoadIcon( hInstance, (LPCTSTR)MAKEINTRESOURCE( IDI_ICON1 ) );
nidApp.cbSize = sizeof( NOTIFYICONDATA ); // sizeof the struct in bytes
nidApp.hWnd = (HWND)hWnd; //handle of the window which will process this app. messages
nidApp.uID = IDI_ICON1; //ID of the icon that willl appear in the system tray
nidApp.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_GUID | NIF_SHOWTIP; //ORing of all the flags
nidApp.hIcon = hMainIcon; // handle of the Icon to be displayed, obtained from LoadIcon
nidApp.uCallbackMessage = WM_USER_SHELLICON;
nidApp.uVersion = NOTIFYICON_VERSION_4;
nidApp.guidItem = myGUID;
strcpy_s( nidApp.szTip, sizeof( nidApp.szTip ), PROGRAM_NAME " Service Controller" );
Shell_NotifyIcon( NIM_ADD, &nidApp );
Shell_NotifyIcon( NIM_SETVERSION, &nidApp );
最佳答案
您应该将 nidApp.uFlags
设置为 NIF_INFO
以显示通知。现在,您正在调用 Shell_NotifyIcon
,并使用与用于创建通知图标相同的标志。
关于c++ - NOTIFYICONDATA 图标通知c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47639441/
我有一个作为服务运行的应用程序,以及一个监控该服务的辅助应用程序。监控应用程序使用 NOTIFYICONDATA 存在于系统托盘中,工作正常。 我目前正在尝试做的是,当应用程序注意到服务已停止时,我想
根据 http://msdn.microsoft.com/en-us/library/bb773352(v=vs.85).aspx 处 NOTIFYICONDATA 结构的 guidItem 成员的描
szTip 字段长度为 128 个字符,并且是 unicode。它是 TCHAR 类型,类型定义为 WCHAR。所以我不知道为什么以下代码片段无法编译。 nid.szTip = _T("ToolTip
我正在阅读 MSDN 中的 NOTIFYICONDATA 文档。 它说 NOTIFYICONDATA 结构有一个 cbSize 成员应该设置为该结构的大小,但是 NOTIFYICONDATA 结构的大
我是一名优秀的程序员,十分优秀!