Reputation: 65
I have an application which runs as a service, as well as a secondary application which monitors the service. The monitoring application exists in the system tray using NOTIFYICONDATA
, which works fine.
What I am currently trying to do, is when the application notices that the services has stopped, I want to display a notification (similar to as if the battery is running low on a laptop). I am basing my code off of this article. The function I have to do this is as follows:
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 ) );
}
}
}
This function is called every five seconds. Using the logs, I am able to see that the dwInfoFlags
is set properly, and Shell_NotifyIcon
returns TRUE
, however, no notification is displayed. I'm sure I must be missing something, but I cannot figure out what it is.
nidApp
is defined at the top of the CPP file as NOTIFYICONDATA nidApp;
as is setup as follows:
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 );
Upvotes: 2
Views: 2830
Reputation: 37550
You should set nidApp.uFlags
to NIF_INFO
to display notification. Right now you are calling Shell_NotifyIcon
with the same flags as were used to create notification icon.
Upvotes: 4