Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. System Tray Problem...

System Tray Problem...

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vladimir Georgiev
    wrote on last edited by
    #1

    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

    A M 2 Replies Last reply
    0
    • V Vladimir Georgiev

      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

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • V Vladimir Georgiev

        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

        M Offline
        M Offline
        Michael Pauli
        wrote on last edited by
        #3

        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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

        M 1 Reply Last reply
        0
        • M Michael Pauli

          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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

          M Offline
          M Offline
          Michael Pauli
          wrote on last edited by
          #4

          ...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. ><((((º> ·.¸¸.· ><((((º> ·.¸¸.· ><((((º>

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups