Icon in system tray
-
Hi, I am re-posting this because I am still having this problem and I am desperate to figure it out. I am trying to create a tray icon. I downloaded Chris Maunder's project and it works for me in my test dialog which is modal. Now I am trying to get it to work in a modeless dialog that ultimately I want to be hidden. I cannot get the tray icon create logic to work. The call to ::Shell_NotifyIcon() fails but I have no idea why. The NOTIFYICONDATA struct seems to be filled in correctly and GetLastError() returns 0. I have tried it with and without a visible modeless dialog. I need the tray icon only to let my user know that my service is running. My code is below. I call the logic to create the icon below:
m_iconTray.Create( this, WM_ICON_NOTIFY, // Icon notify message to use _T("AutoFileHandler is running"), // tooltip to use ::LoadIcon( NULL, IDI_ASTERISK ), // Icon to use IDR_TRAYICON ); // ID of tray icon
The Icon Create() logic:m_tnd.cbSize = sizeof(NOTIFYICONDATA); m_tnd.hWnd = pParent->GetSafeHwnd()? pParent->GetSafeHwnd() : m_hWnd; m_tnd.uID = uID; m_tnd.hIcon = icon; m_tnd.uFlags = NIF_ICON | NIF_TIP; // NIF_MESSAGE; m_tnd.uCallbackMessage = uCallbackMessage; _tcscpy(m_tnd.szTip, szToolTip); // Set the tray icon VERIFY(m_bEnabled = ::Shell_NotifyIcon(NIM_ADD, &m_tnd));
Any help appreciated -
Hi, I am re-posting this because I am still having this problem and I am desperate to figure it out. I am trying to create a tray icon. I downloaded Chris Maunder's project and it works for me in my test dialog which is modal. Now I am trying to get it to work in a modeless dialog that ultimately I want to be hidden. I cannot get the tray icon create logic to work. The call to ::Shell_NotifyIcon() fails but I have no idea why. The NOTIFYICONDATA struct seems to be filled in correctly and GetLastError() returns 0. I have tried it with and without a visible modeless dialog. I need the tray icon only to let my user know that my service is running. My code is below. I call the logic to create the icon below:
m_iconTray.Create( this, WM_ICON_NOTIFY, // Icon notify message to use _T("AutoFileHandler is running"), // tooltip to use ::LoadIcon( NULL, IDI_ASTERISK ), // Icon to use IDR_TRAYICON ); // ID of tray icon
The Icon Create() logic:m_tnd.cbSize = sizeof(NOTIFYICONDATA); m_tnd.hWnd = pParent->GetSafeHwnd()? pParent->GetSafeHwnd() : m_hWnd; m_tnd.uID = uID; m_tnd.hIcon = icon; m_tnd.uFlags = NIF_ICON | NIF_TIP; // NIF_MESSAGE; m_tnd.uCallbackMessage = uCallbackMessage; _tcscpy(m_tnd.szTip, szToolTip); // Set the tray icon VERIFY(m_bEnabled = ::Shell_NotifyIcon(NIM_ADD, &m_tnd));
Any help appreciatedIs there anything on the modeless dialog? I had an interactive service that displayed a tray icon without any problem. The service called the following
CreateEx (0, AfxRegisterWndClass (0), "", WS\_POPUP, 0, 0, 10, 10, NULL, 0); m\_notifyIconData.cbSize = sizeof (NOTIFYICONDATA); m\_notifyIconData.hWnd = m\_hWnd; m\_notifyIconData.uID = 1; m\_notifyIconData.uFlags = NIF\_ICON | NIF\_MESSAGE | NIF\_TIP; m\_notifyIconData.uCallbackMessage = WM\_APP; m\_notifyIconData.hIcon = ::LoadIcon (AfxGetResourceHandle (), MAKEINTRESOURCE (IDI\_ICONTRAY)); m\_notifyIconData.uVersion = NOTIFYICON\_VERSION; strcpy\_s (m\_notifyIconData.szTip, 64, "Service Name"); Shell\_NotifyIcon (NIM\_ADD, &m\_notifyIconData);
where m_hWnd was returned by the CreateEx call. The service regularly called a message pump on the m_hWnd
MSG msg; while (PeekMessage (&msg, NULL, 0 ,0, PM\_REMOVE)) { TranslateMessage (&msg); DispatchMessage (&msg); }
The window procedure for the m_hWnd received WM_ messages so I could process a double click and the right-click. NOTE - my responsiveness to answer any questions about this will be really bad this weekend since I have lots of time-consuming plans. Good luck Judy
-
Hi, I am re-posting this because I am still having this problem and I am desperate to figure it out. I am trying to create a tray icon. I downloaded Chris Maunder's project and it works for me in my test dialog which is modal. Now I am trying to get it to work in a modeless dialog that ultimately I want to be hidden. I cannot get the tray icon create logic to work. The call to ::Shell_NotifyIcon() fails but I have no idea why. The NOTIFYICONDATA struct seems to be filled in correctly and GetLastError() returns 0. I have tried it with and without a visible modeless dialog. I need the tray icon only to let my user know that my service is running. My code is below. I call the logic to create the icon below:
m_iconTray.Create( this, WM_ICON_NOTIFY, // Icon notify message to use _T("AutoFileHandler is running"), // tooltip to use ::LoadIcon( NULL, IDI_ASTERISK ), // Icon to use IDR_TRAYICON ); // ID of tray icon
The Icon Create() logic:m_tnd.cbSize = sizeof(NOTIFYICONDATA); m_tnd.hWnd = pParent->GetSafeHwnd()? pParent->GetSafeHwnd() : m_hWnd; m_tnd.uID = uID; m_tnd.hIcon = icon; m_tnd.uFlags = NIF_ICON | NIF_TIP; // NIF_MESSAGE; m_tnd.uCallbackMessage = uCallbackMessage; _tcscpy(m_tnd.szTip, szToolTip); // Set the tray icon VERIFY(m_bEnabled = ::Shell_NotifyIcon(NIM_ADD, &m_tnd));
Any help appreciatedIn addition to Judy's reply... Have you checked all the relevant members of the NOTIFYICONDATA struct? With a breapoint on the Shell_NotifyIcon() call, what are the values of the hWnd, hIcon, uID, and szTip members? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
In addition to Judy's reply... Have you checked all the relevant members of the NOTIFYICONDATA struct? With a breapoint on the Shell_NotifyIcon() call, what are the values of the hWnd, hIcon, uID, and szTip members? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
The struct values are: hWnd = 0x001A0230 hIcon = 0x0001000b uID = 107 szTip = "AutoFileHandler is running" The window has a static control and a button on it. More tomorrow.
-
The struct values are: hWnd = 0x001A0230 hIcon = 0x0001000b uID = 107 szTip = "AutoFileHandler is running" The window has a static control and a button on it. More tomorrow.
hmm... Are you doing this from a service or is it not working in a regular app? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
hmm... Are you doing this from a service or is it not working in a regular app? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
I have it working in dialog app, but I need to get it working in my service app.
-
I have it working in dialog app, but I need to get it working in my service app.