Can't create tray icon from modeless dialog
-
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 -
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 appreciatedWhy 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
-
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 appreciatedDoes GetLastError() give you any useful info? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Does GetLastError() give you any useful info? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
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
-
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
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:
-
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:
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
-
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
-
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 appreciatedRoyce 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
-
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
Heh that's the least of my problems....I need to read the posts more closely! :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
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
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
-
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
-
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
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.
-
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
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.
-
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
Yes, the hwnd is valid.
-
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.
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