|
|
Comments and Discussions
|
|
 |

|
Hello, first of all congratulations by this excellent article and my vote 5, I am in a small project with c # where I need this functionality but my knowledge of c++ is poor, reason why it costs to me to translate it, would be possibility of a version c #.
Thanks in advance
|
|
|
|

|
Here's some code to get the process IDs of icons from your 32-bit application running on a 64-bit OS. You can actually read memory of a 64-bit process from a 32-bit process, as long as the addresses are below the 4GB barrier.
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
BOOL IsWow64()
{
static bool isset = false;
static BOOL bIsWow64 = FALSE;
if (isset) {
return bIsWow64;
}
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
if(NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
return FALSE;
}
}
isset = true;
return bIsWow64;
}
typedef struct _TBBUTTON64 {
int iBitmap;
int idCommand;
BYTE fsState;
BYTE fsStyle;
BYTE bReserved[6];
DWORD64 dwData;
DWORD64 iString;
} TBBUTTON64, NEAR* PTBBUTTON64, *LPTBBUTTON64;
typedef const TBBUTTON64 *LPCTBBUTTON64;
bool EnumSystemTray() {
bool bFound = false;
HWND trayWnd = FindWindow(_T("Shell_TrayWnd"), NULL);
if (trayWnd) {
trayWnd = FindWindowEx(trayWnd, NULL,_T("TrayNotifyWnd"), NULL);
if (trayWnd) {
trayWnd = FindWindowEx(trayWnd, NULL,_T("SysPager"), NULL);
if (trayWnd) {
trayWnd = FindWindowEx(trayWnd, NULL,_T("ToolbarWindow32"), NULL);
bFound = true;
}
}
}
ASSERT(bFound);
DWORD dwTrayPid;
GetWindowThreadProcessId(trayWnd, &dwTrayPid);
int count = (int) SendMessage(trayWnd, TB_BUTTONCOUNT, 0, 0);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwTrayPid);
if (!hProcess) {
return true;
}
BOOL bIsWow64 = IsWow64();
SIZE_T dwSize = bIsWow64 ? sizeof(TBBUTTON64) : sizeof(TBBUTTON);
LPVOID lpData = VirtualAllocEx(hProcess, NULL, dwSize, MEM_COMMIT, PAGE_READWRITE);
if (!lpData) {
return true;
}
for (int i = 0; i < count; i++) {
HWND hwnd32;
SendMessage(trayWnd, TB_GETBUTTON, i, (LPARAM)lpData);
if ( bIsWow64 ) {
TBBUTTON64 tbb;
if (!ReadProcessMemory(hProcess, lpData, (LPVOID)&tbb, sizeof(TBBUTTON64), NULL)) {
continue;
}
DWORD64 hwnd;
if (!ReadProcessMemory(hProcess, (LPCVOID)tbb.dwData, (LPVOID)&hwnd, sizeof(DWORD64), NULL)) {
continue;
}
hwnd32 = (HWND)hwnd;
} else {
TBBUTTON tbb;
if (!ReadProcessMemory(hProcess, lpData, (LPVOID)&tbb, sizeof(TBBUTTON), NULL)) {
continue;
}
DWORD32 hwnd;
if (!ReadProcessMemory(hProcess, (LPCVOID)tbb.dwData, (LPVOID)&hwnd, sizeof(DWORD32), NULL)) {
continue;
}
hwnd32 = (HWND)hwnd;
}
DWORD dwProcessId = 0;
GetWindowThreadProcessId(hwnd32, &dwProcessId);
}
VirtualFreeEx(hProcess, lpData, NULL, MEM_RELEASE);
return true;
}
modified on Monday, August 15, 2011 7:32 AM
|
|
|
|

|
I just need the same code!
|
|
|
|
|

|
Just for s&g I changed it allow Windows 7 -- still works... somewhat.
It enumerates the visible icons but, any on the overflow window are not shown.
|
|
|
|

|
What to do the code can work in Win7 or vista?
|
|
|
|

|
The right method is to use internal Shell Structures and code injection in Explorer address space.
Internal Shell Structures had been published on Advanced Win32 newsgroup (news://comp.os.ms-windows.programmer.win32 or http://tinyurl.com/cmhb5g[^])
|
|
|
|

|
I have created a similar program using VB.Net. I enumerate the system tray icons using the same method. I do this to automatically activate one of the programs associated with a system tray icon.
It works in both 32 bit and 64 bits Vista, so I expect that this program will also.
|
|
|
|

|
Sometimes when I use the right click button, the menu corresponding to the tray icon appears but also remains sticky even if I click elsewhere. Anyone having an idea why it is so or how to avoid this behavior?
|
|
|
|

|
Before showing the menu, call SetForegroundWindow on the owner window of the icon so the menu can be dismissed.
Maybe there's a better way, but this works in my applications.
|
|
|
|

|
I need to hide or unhide certain bluetooth applications' icons that are there in system tray based on whether bluetooth is on/off. Can we hide/unhide the system tray icons? It's an urgent requirement!!
modified on Thursday, February 5, 2009 1:12 AM
|
|
|
|

|
why the "GetIconInfo" return ZERO in some system's Trayicons that they is exist?
|
|
|
|

|
Looks like TRAYDATA is NOTIFYICONDATA without the cbsize field.
GETMODULEFILENAMEEX is an easier way to get the normal path from the device path.
Still works in Vista.
I'm doing it with managed code, but the TBBUTTON size varies between x64 and x86 - which is a pain as I can't see a way to lay it out that works with both.
|
|
|
|

|
Hello,
I'd like to use this code in vb.net but have now idea what to get with it. Unfortunately i have no experience with C++ so if anyone could create a dll from this to be able to use these functions (to get the icons and manipulate them) from vb.net would be really appreciated.
Anyways, just needed to delete the windows version checking and works on Vista, too - i tried it.
Thanks;
GQ
|
|
|
|

|
hi, i need to hide a particular tray icon from the system tray instead of using the reg key NoTrayItemsDisplay. i am with win32 api C style...
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|

|
Some icons' handle of tray buttions are invalid ?
When I ran the binary file(ShellTrayInfo.exe), I found that some tray buttons' icon were incorrect, such as MSN(Windows Live Messenger),Kaspersky Antivirus, etc.
After I debuged those codes, I found that some icons' handle of tray buttions are invalid.
In those cases, we will fail to call the GetIconInfo API and the error code got by GetLastError is 1402.
Is there any difference in those applications?
How can I solve this problem?
Hope to receive your reply soon.
Thanks in advance!
Kevin.
|
|
|
|

|
This app seem to work on Vista. I had to put it in compatibility mode to bypass the version check, but I was able to reposition icons etc.
Maybe make the version check forward compatible? Only disallowing older OS's which is known not to work?
|
|
|
|

|
I'm looking for a commandline utility to just list the icons and tooltips in the system tray and spit it out to a file or stdout so I can parse it. Before I try to tackle modifying this app's code to do what I want, is there already something like what I'm looking for?
Thanks!
|
|
|
|
|

|
After last month's disastrous HD crash, I wanted to start keeping tabs on the temperatures for both of my HD drives. I use HDD Thermometer, a great free tool that shows the temps (one for each HDD) in the tray. Unfortunately, at startup the temps sometimes do not appear next to each other. Your utility is the perfect answer!
I agree with 5h17h34d - having Shell Tray Info run at startup would be very nice.
Thanks!
Best wishes,
Hans
|
|
|
|

|
I've been meaning to update the source to VC++ 2005, and I guess when I do that I'll also add an installer that'll add this to the startup. Though I could avoid the installer and add an option within the app that'll allow people to specify if they want it to run on startup - it's always good to avoid installers.
Regards,
Nish
Fly on your way like an eagle
Fly as high as the sun
On your wings like an eagle
Fly and touch the sun
|
|
|
|

|
Nishant Sivakumar wrote: I could avoid the installer and add an option within the app that'll allow people to specify if they want it to run on startup
I agree - an option within the app would be better.
|
|
|
|

|
Like this little app except the fact that I must redo it after
every boot.
Perhaps I am missing something obvious?
Thank you for this little gem of a program for a utility
junky like me!
SH
|
|
|
|

|
My thoughts exactly!
Actually, a simple 'auto alphabetic sort' every 5 minutes or so would be enough.
Since the source code is supplied, it should be an easy thing.
I'm currently too busy/lazy to do this, but if there are people out there who REALLY want this, I'll consider it (PM me with request).
|
|
|
|

|
hi guys i am getting some errors while Compiling, can anyone help me out,
the errors are
Cerror C2552: 'tifo' : non-aggregates cannot be initialized with initializer list
Cerror C2275: 'TRAYDATA' : illegal use of this type as an expression
error C2275: 'wchar_t' : illegal use of this type as an expression
these 3 can be solved by using atlbase.h but what about the rest
error C2065: 'USES_CONVERSION' : undeclared identifier
error C2065: 'W2T' : undeclared identifier
error C2593: 'operator =' is ambiguous
ya one more thing
GetProcessImageFileName is it in psapi, then which is the correct version and can somepne post the 3 files, psapi.h psapi.lib n psapi.dll
because i m getting the error if i comment all the pervious errors
unresolved external symbol _GetProcessImageFileNameW@12
Thanks a lot
Swarup
|
|
|
|

|
i want to know how i can make static executable file.
Murtaza Tahir Ali Dhari
|
|
|
|

|
please help me some code this "program stilmulator Calculator same Windows"
i like design Web
|
|
|
|

|
Did you ever find out why some icons (MSN Messenger for example) do not draw properly?
I am having the same problem in a similar project and i dont know why some icons dont return a valid hIcon.
|
|
|
|

|
I am attempting to write a function to determine if my tray icon is still present. It irritates me greatly when explorer crashes and drops my icon and I feel it is a poor solution to simply delete and re-add the icon periodically as has been suggested to me. I am implementing this in a non-MFC application, so I am afraid I cannot use the CProcessData class you have used in your example. I was wondering if you could explain how to obtain the specific TRAYDATA object for each icon without using the CProcessData class. Here is my code:
bool IsTrayIconPresent(UINT uid) {
TBBUTTON tb = {0};
TRAYDATA td = {0};
HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
if(hWnd) {
hWnd = ::FindWindowEx(hWnd, NULL, "TrayNotifyWnd", NULL);
if(hWnd) {
hWnd = ::FindWindowEx(hWnd, NULL, "SysPager", NULL);
if(hWnd) {
hWnd = ::FindWindowEx(hWnd, NULL, "ToolbarWindow32", NULL);
}
}
}
if(!hWnd) //error could not find Toolbar
return false;
int count = (int)::SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0);
for(int i=0;i |
|
|
|

|
spamna wrote: I am implementing this in a non-MFC application, so I am afraid I cannot use the CProcessData class you have used in your example.
CProcessData is not MFC dependent. You can use it for non-MFC projects too.
|
|
|
|

|
Thank you for your quick reply. I saw your class name was prefixed with "C" and assumed it was MFC. Here is the resulting code in case anyone else wanted a simple and quick snippet to determine if their tray icon was still in the tray:
//determines if the icon with given uid is present in the tray
bool IsTrayIconPresent(UINT uid) {
register int i;
int count;
TBBUTTON tb = {0};
TRAYDATA td = {0};
DWORD dwTrayPid = 0;
HANDLE hTrayProc = 0;
LPVOID lpData = 0;
HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
if(hWnd) {
hWnd = ::FindWindowEx(hWnd, NULL, "TrayNotifyWnd", NULL);
if(hWnd) {
hWnd = ::FindWindowEx(hWnd, NULL, "SysPager", NULL);
if(hWnd) {
hWnd = ::FindWindowEx(hWnd, NULL, "ToolbarWindow32", NULL);
}
}
}
if(!hWnd) //error could not find Toolbar
return false;
//get the pid
if(GetWindowThreadProcessId(hWnd, &dwTrayPid) == NULL)
return false;
//open the corrent process
if((hTrayProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwTrayPid)) == NULL)
return false;
//virtualalloc
if((lpData = VirtualAllocEx(hTrayProc, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE)) == NULL)
goto cleanup;
count = (int)::SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0);
for(i=0;i
Thanks for this excellent article. Now I have to figure out how to manipulate buttons on the taskbar = P
Regards,
Nate
|
|
|
|

|
Hello.
You do not need to periodically query the Tray area to know if your icon is still present. There's a better way.
Every time explorer.exe crashes, it destroys and recreates the Taskbar.
As soon as the Taskbar window has been fully rebuilt, the System broadcasts a special message to all the applications that have requested to receive the notification.
The message is:
"TaskbarCreated" (<-- case sensitive)
and you request the notification simply by calling:
UINT iMyMsg = RegisterWindowMessage ("TaskbarCreated");
where iMyMsg is your own variable that receives the Sistem-wide value uniquely identifiyng the "TaskbarCreated" message.
Then, inside your WndProc() you handle this message like any other.
For example:
LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == iMyMsg)
{
// The Windows Taskbar has just been rebuilt.
// Do your stuff here (like adding a new tray icon).
.
.
.
}
// Other WM_*** messages, as usual.
switch (Msg)
{
case ...
}
return DefWindowProc (hWnd, Msg, wParam, lParam);
}
Being the Taskbar brand new, there's no old tray icon to remove.
Simply add a new one.
A few notes:
You need to request the "TaskbarCreated" message notification only once.
Requesting it multiple times is useless, and always returns the same identifier.
If different apps request the notification, they all get returned the same identifier.
There's no way (and no mean) to unregister the message once your app terminates. So don't worry about it.
Hope it helps.
Regards,
Ciao ciao
[edit:]
I forgot to mention that the "TaskbarCreated" message hasn't changed since Win98. I don't know about Win95.
Ciao ciao
|
|
|
|

|
Nishant Sivakumar wrote: CProcessData is not MFC dependent. You can use it for non-MFC projects too.
How so?
|
|
|
|

|
Hi,
GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO. The calling application must manage these bitmaps and delete them when they are no longer necessary.
//---- old code ---
//
int iconindex = 0;
ICONINFO iinfo;
if(GetIconInfo(tray.hIcon,&iinfo) != 0)
{
iconindex = m_Image16List.Add(tray.hIcon);
}
//--- new code ----
//
int iconindex = 0;
ICONINFO iinfo;
if(GetIconInfo(tray.hIcon,&iinfo) != 0)
{
iconindex = m_Image16List.Add(tray.hIcon);
if (iinfo.hbmMask != NULL)
DeleteObject(iinfo.hbmMask);
if (iinfo.hbmColor != NULL)
DeleteObject(iinfo.hbmColor);
}
Cheers,
michi
|
|
|
|

|
after starting the binary direct this error message will shown:
GetProcessImageFileNameA not in PSAPI.DLL
I use WinXP (without any servicepack) german edition
|
|
|
|

|
Country Man wrote: GetProcessImageFileNameA not in PSAPI.DLL
I use WinXP (without any servicepack) german edition
You'd need the Unicode build.
|
|
|
|

|
Hi,
First, excuse my bad english, it's not my native language (I'm French).
Then, is it possible, starting with your code, to create a function which could hide/unhide any process' icon in the system tray too (not only in the taskbar)???
How must I do?
Regards.
|
|
|
|

|
NOTIFYICONDATA tbc;
tbc.cbSize=sizeof(NOTIFYICONDATA);
tbc.hWnd=m_TifoVec[index].hwnd;
tbc.uID=m_TifoVec[index].uID;
tbc.uCallbackMessage=m_TifoVec[index].uCallbackMessage;
tbc.uFlags=NIF_STATE;
tbc.dwState=NIS_HIDDEN;
tbc.dwStateMask=NIS_HIDDEN ;
Shell_NotifyIcon(NIM_DELETE ,&tbc);
this is one code another is
::SendMessage(hwnd, TB_DELETEBUTTON, index, 0);
try let me know.
|
|
|
|

|
This is excellent - with this and my Taskbar Sorter[^], I can spend hours rearranging everything to be just the way I like it!
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|

|
Thanks Paul
|
|
|
|

|
Can't say it's something i've wanted to do too often, but always nice to know it *can* be done.
You must be careful in the forest
Broken glass and rusty nails
If you're to bring back something for us
I have bullets for sale...
|
|
|
|

|
Thanks Shog
|
|
|
|

|
If there were some tips to older W9x Systems, it could have been execellent.
Try this @ home. (B&B)
|
|
|
|

|
I am sorry about that - I don't know how this is implemented internally in pre-XP OSes.
|
|
|
|

|
Kool Source Code,I too trying to make same thing from last sunday, Now I will use your Source Code .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|

|
ThatsAlok wrote:
Kool Source Code,I too trying to make same thing from last sunday, Now I will use your Source Code
Glad to hear that
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
A tool with full source code that enumerates tray icons and allows you to reposition them as well as send mouse messages.
| Type | Article |
| Licence | CPOL |
| First Posted | 26 Jun 2005 |
| Views | 201,512 |
| Bookmarked | 83 times |
|
|