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. Can't create tray icon from modeless dialog

Can't create tray icon from modeless dialog

Scheduled Pinned Locked Moved C / C++ / MFC
linuxhelpquestion
15 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
    Royce Fickling 0
    wrote on last edited by
    #1

    Hi, 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: 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

    D M L 3 Replies Last reply
    0
    • R Royce Fickling 0

      Hi, 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: 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

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Why does the dialog need to be modeless?

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      R 1 Reply Last reply
      0
      • R Royce Fickling 0

        Hi, 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: 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

        Does GetLastError() give you any useful info? Mark

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

        D 1 Reply Last reply
        0
        • M Mark Salsbery

          Does GetLastError() give you any useful info? Mark

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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Not according to his post. I did not find anything on MSDN that says GetLastError() is even used.

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          M L 2 Replies Last reply
          0
          • D David Crow

            Not according to his post. I did not find anything on MSDN that says GetLastError() is even used.

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

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

            What do you mean?  I meant after the failed Shell_NotifyIcon call. The docs for Shell_NotifyIcon state: "You can call GetLastError for more specific information about a failure case." That's what I meant.  But now I see the OP stated it returned 0  :doh: :)

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

            D 1 Reply Last reply
            0
            • M Mark Salsbery

              What do you mean?  I meant after the failed Shell_NotifyIcon call. The docs for Shell_NotifyIcon state: "You can call GetLastError for more specific information about a failure case." That's what I meant.  But now I see the OP stated it returned 0  :doh: :)

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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              What are you doing looking at newer documentation, Mark? :doh:

              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              M 1 Reply Last reply
              0
              • D David Crow

                Not according to his post. I did not find anything on MSDN that says GetLastError() is even used.

                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                DavidCrow wrote:

                I did not find anything on MSDN that says GetLastError() is even used.

                WTF David? "You can call GetLastError for more specific information about a failure case."[^]

                led mike

                D 1 Reply Last reply
                0
                • R Royce Fickling 0

                  Hi, 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: 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

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  Royce Fickling wrote:

                  Now I am trying to get it to work in a modeless dialog

                  When are you running the code you posted? m_tnd.hWnd = pParent->GetSafeHwnd()? pParent->GetSafeHwnd() : m_hWnd; I assume a valid HWND is required, have you checked that you have one?

                  led mike

                  R 2 Replies Last reply
                  0
                  • D David Crow

                    What are you doing looking at newer documentation, Mark? :doh:

                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

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

                    Heh that's the least of my problems....I need to read the posts more closely! :)

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

                    1 Reply Last reply
                    0
                    • L led mike

                      DavidCrow wrote:

                      I did not find anything on MSDN that says GetLastError() is even used.

                      WTF David? "You can call GetLastError for more specific information about a failure case."[^]

                      led mike

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      I know that, Mike. I was looking at my Oct '01 copy of MSDN. It's a bit aged.

                      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      L 1 Reply Last reply
                      0
                      • D David Crow

                        I know that, Mike. I was looking at my Oct '01 copy of MSDN. It's a bit aged.

                        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        L Offline
                        L Offline
                        led mike
                        wrote on last edited by
                        #11

                        Sorry, I would not have posted if I had seen Marks, I got web lagged. :rose:

                        led mike

                        1 Reply Last reply
                        0
                        • L led mike

                          Royce Fickling wrote:

                          Now I am trying to get it to work in a modeless dialog

                          When are you running the code you posted? m_tnd.hWnd = pParent->GetSafeHwnd()? pParent->GetSafeHwnd() : m_hWnd; I assume a valid HWND is required, have you checked that you have one?

                          led mike

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

                          Yes, the dialog's hwnd is valid. I have called the icon create method from OnInitDialog() after the CDialog::OnInitDialog() call. I have also called it from OnShowWindow(), but both fail.

                          1 Reply Last reply
                          0
                          • D David Crow

                            Why does the dialog need to be modeless?

                            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

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

                            This dialog must be modeless because it is to be displayed by a Windows service and I don't want my service to hang or be killed by the OS. This dialog will appear only if the user attempts to shutdown the system if my service is still doing critical processing.

                            L 1 Reply Last reply
                            0
                            • L led mike

                              Royce Fickling wrote:

                              Now I am trying to get it to work in a modeless dialog

                              When are you running the code you posted? m_tnd.hWnd = pParent->GetSafeHwnd()? pParent->GetSafeHwnd() : m_hWnd; I assume a valid HWND is required, have you checked that you have one?

                              led mike

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

                              Yes, the hwnd is valid.

                              1 Reply Last reply
                              0
                              • R Royce Fickling 0

                                This dialog must be modeless because it is to be displayed by a Windows service and I don't want my service to hang or be killed by the OS. This dialog will appear only if the user attempts to shutdown the system if my service is still doing critical processing.

                                L Offline
                                L Offline
                                led mike
                                wrote on last edited by
                                #15

                                Royce Fickling wrote:

                                This dialog will appear only if the user attempts to shutdown the system if my service is still doing critical processing.

                                I've written many Services down through the years and never even considered doing something like that. I'm not even sure if it makes sense in the larger scheme of things. I'm also not sure it is supported during shutdown because as I stated I would never even consider doing something like that.

                                led mike

                                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