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. Icon in system tray

Icon in system tray

Scheduled Pinned Locked Moved C / C++ / MFC
helplinuxquestion
7 Posts 4 Posters 0 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.
  • R Offline
    R Offline
    RoyceF
    wrote on last edited by
    #1

    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

    J M 2 Replies Last reply
    0
    • R RoyceF

      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

      J Offline
      J Offline
      JudyL_MD
      wrote on last edited by
      #2

      Is 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

      1 Reply Last reply
      0
      • R RoyceF

        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

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        R 1 Reply Last reply
        0
        • M Mark Salsbery

          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:

          R Offline
          R Offline
          Royce Fickling 0
          wrote on last edited by
          #4

          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.

          M 1 Reply Last reply
          0
          • R Royce Fickling 0

            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.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            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:

            R 1 Reply Last reply
            0
            • M Mark Salsbery

              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:

              R Offline
              R Offline
              Royce Fickling 0
              wrote on last edited by
              #6

              I have it working in dialog app, but I need to get it working in my service app.

              M 1 Reply Last reply
              0
              • R Royce Fickling 0

                I have it working in dialog app, but I need to get it working in my service app.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Ok now that I'm caught up... :) Have you done everything required here[^]? Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                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