System Tray Problem...
-
I have problems with the message handler of a system tray icon. I am writing an SDI application, and it adds the icon with no problems, but my custom message handler does not get the messages sent to the icon. I have successfully done this in a Dialog App some years ago, and now it does not work in the SDI one. I try to move this functionallity to the App, View, Frame classes - but nothing happens. I use VC++ 6.0 under Windows XP. Are there any catches here? What do I do wrong??? Really appreciate the help. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
-
I have problems with the message handler of a system tray icon. I am writing an SDI application, and it adds the icon with no problems, but my custom message handler does not get the messages sent to the icon. I have successfully done this in a Dialog App some years ago, and now it does not work in the SDI one. I try to move this functionallity to the App, View, Frame classes - but nothing happens. I use VC++ 6.0 under Windows XP. Are there any catches here? What do I do wrong??? Really appreciate the help. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
All you need to do is create your own message MY_MSG (or something like that), then attach this message to the callbackmsg (of the trayicon), then place the message in the message map of your mainframe and implement the function you attached to the message.
-
I have problems with the message handler of a system tray icon. I am writing an SDI application, and it adds the icon with no problems, but my custom message handler does not get the messages sent to the icon. I have successfully done this in a Dialog App some years ago, and now it does not work in the SDI one. I try to move this functionallity to the App, View, Frame classes - but nothing happens. I use VC++ 6.0 under Windows XP. Are there any catches here? What do I do wrong??? Really appreciate the help. "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
I'v made a well working fct. for this: inline const bool SetTrayIcon( CWnd *pWnd, CONST DWORD dwMessage, CONST DWORD dwMessage_NIM, CONST UINT uId_Icon, LPCTSTR lpszTTT, CONST UINT uId_Callback) // In the tray, show specific icon. Return T on succes and F if not. // // To add the icon use: NIM_ADD for NIM msg. // To change the icon use: NIM_MODIFY for NIM msg. // To remove the icon use: NIM_ADD for NIM msg. // { NOTIFYICONDATA nid; nid.cbSize = sizeof(NOTIFYICONDATA); nid.hWnd = pWnd->GetSafeHwnd(); nid.uID = uId_Callback; nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; nid.uCallbackMessage = dwMessage; nid.hIcon = (HICON)::AfxGetApp()->LoadIcon(uId_Icon); ::lstrcpyn(nid.szTip, lpszTTT, sizeof(nid.szTip)); bool bResult = (::Shell_NotifyIcon(dwMessage_NIM, &nid) != 0); if(nid.hIcon) ::DestroyIcon(nid.hIcon); return bResult; } And then you go: BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd) // Callback handler for tray icon. ON_MESSAGE(WM_NOTIFYICON, OnTrayIconNotification) END_MESSAGE_MAP() And: LRESULT CCalFrameWnd::OnTrayIconNotification(WPARAM, LPARAM lParam) // Called back on notifications to the tray icon. { switch(lParam) { case WM_LBUTTONDBLCLK: { // Do stuff. break; } case WM_LBUTTONDOWN: { // Do stuff. break; } case WM_RBUTTONDOWN: { // Do stuff. break; } // etc. } return 0L; } Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
-
I'v made a well working fct. for this: inline const bool SetTrayIcon( CWnd *pWnd, CONST DWORD dwMessage, CONST DWORD dwMessage_NIM, CONST UINT uId_Icon, LPCTSTR lpszTTT, CONST UINT uId_Callback) // In the tray, show specific icon. Return T on succes and F if not. // // To add the icon use: NIM_ADD for NIM msg. // To change the icon use: NIM_MODIFY for NIM msg. // To remove the icon use: NIM_ADD for NIM msg. // { NOTIFYICONDATA nid; nid.cbSize = sizeof(NOTIFYICONDATA); nid.hWnd = pWnd->GetSafeHwnd(); nid.uID = uId_Callback; nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; nid.uCallbackMessage = dwMessage; nid.hIcon = (HICON)::AfxGetApp()->LoadIcon(uId_Icon); ::lstrcpyn(nid.szTip, lpszTTT, sizeof(nid.szTip)); bool bResult = (::Shell_NotifyIcon(dwMessage_NIM, &nid) != 0); if(nid.hIcon) ::DestroyIcon(nid.hIcon); return bResult; } And then you go: BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd) // Callback handler for tray icon. ON_MESSAGE(WM_NOTIFYICON, OnTrayIconNotification) END_MESSAGE_MAP() And: LRESULT CCalFrameWnd::OnTrayIconNotification(WPARAM, LPARAM lParam) // Called back on notifications to the tray icon. { switch(lParam) { case WM_LBUTTONDBLCLK: { // Do stuff. break; } case WM_LBUTTONDOWN: { // Do stuff. break; } case WM_RBUTTONDOWN: { // Do stuff. break; } // etc. } return 0L; } Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>
...I forgot some examples: // Setup tray icon. ::SetTrayIcon(this, WM_NOTIFYICON, NIM_ADD, m_uId_TrayIconActive, (LPCTSTR)GetBaloonInfo()); // Refresh baloon for tray icon. ::SetTrayIcon(this, WM_NOTIFYICON, NIM_MODIFY, m_uId_TrayIconActive, (LPCTSTR)GetBaloonInfo()); // Remove tray icon. ::SetTrayIcon(this, WM_NOTIFYICON, NIM_DELETE, m_uId_TrayIconActive); And you have: inline const bool SetTrayIcon( CWnd*, CONST DWORD, CONST DWORD, CONST UINT, LPCTSTR lpszTTTEx = _T(""), CONST UINT uId_CallbackEx = 0); Regards, Michael Mogensen, mm it-consult dk. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>