|
|
|
Re: Help needed to launch each of the system tray icons present
Started by VC++ help at 03-19-2006 9:46 PM. Topic has 2 replies.
|
|
03-19-2006, 9:46 PM
|
VC++ help
Joined on 03-20-2006
Posts 2
|
Help needed to launch each of the system tray icons present
|
|
|
|
|
I have to write a module in VC++ 6.0 that will do the foll:-
Launch Icons from the system tray and log the pass or fail result.
Kindly suggest me how i need to go ahead to enumerate all icons present in the System Tray and launch each of them, one after the other. launching may be in amy order.
A reply at the earliest will be very helpful as i need to finish this within 4 days.
Thanks in advance.
Sincerely Giftsana
|
|
|
|
|
Report
|
|
|
|
03-19-2006, 11:08 PM
|
Yasir
Joined on 03-15-2006
Posts 44
|
Re: Help needed to launch each of the system tray icons present
|
|
|
|
|
The following code is used to locate this window (routine FindWindow/FindWindowEx stuff)
HWND FindTrayToolbarWindow()
{
HWND hWnd = ::FindWindow(_T("Shell_TrayWnd"), NULL);
if(hWnd)
{
hWnd = ::FindWindowEx(hWnd,NULL,_T("TrayNotifyWnd"), NULL);
if(hWnd)
{
hWnd = ::FindWindowEx(hWnd,NULL,_T("SysPager"), NULL);
if(hWnd)
{
hWnd = ::FindWindowEx(hWnd, NULL,_T("ToolbarWindow32"), NULL);
}
}
}
return hWnd;
}
Now I retrieve the count of tray icons :-
int count = (int)::SendMessage(m_hTrayWnd, TB_BUTTONCOUNT, 0, 0);
The number won't match the number of visible icons because of some hidden icons inserted by Explorer + the Hide Inactive Icons setting may be enabled.
BTW to retrieve toolbar info for each button, I use my CProcessData class. [CProcessData is a template class that makes it easy to use data allocated in a different process, and is useful when making inter-process SendMessage/PostMessage calls]
The dwData member of each TBBUTTON structure of the toolbar points to an undocumented structure. The first few bytes of the structure are as follows (on XP anyway) :-
struct TRAYDATA
{
HWND hwnd;
UINT uID;
UINT uCallbackMessage;
DWORD Reserved[2];
HICON hIcon;
};
There's more info, but I am not sure what the rest of it means. Reserved[0] has something to do with the visibility state of an icon when the Hide Inactive Icons setting is enabled, but it's behavior was too sporadic for me to give it a proper meaning and since I didn't really want that info, I didn't bother too much. All my Google searches on this undocumented structure resulted in nothing. It's times like this when you wish Windows provided full source code :-(
Anyway here's the code
CProcessData data(dwTrayPid);
TBBUTTON tb = {0};
TRAYDATA tray = {0};
TrayItemInfo tifo = {0};
for(int i=0; i(&tray,(LPCVOID)tb.dwData);
DWORD dwProcessId = 0;
GetWindowThreadProcessId(tray.hwnd,&dwProcessId);
tifo.sProcessPath = GetFilenameFromPid(dwProcessId);
wchar_t TipChar;
wchar_t sTip[1024] = {0};
wchar_t* pTip = (wchar_t*)tb.iString;
if(!(tb.fsState&TBSTATE_HIDDEN))
{
int x = 0;
do
{
if(x == 1023)
{
wcscpy(sTip,L"[ToolTip was either too long or not set]");
break;
}
data.ReadData(&TipChar, (LPCVOID)pTip++);
}while(sTip[x++] = TipChar);
}
else
wcscpy(sTip,L"[Hidden Icon]");
USES_CONVERSION;
tifo.sTip = W2T(sTip);
tifo.hwnd = tray.hwnd;
tifo.uCallbackMessage = tray.uCallbackMessage;
tifo.uID = tray.uID;
tifo.bVisible = !(tb.fsState & TBSTATE_HIDDEN);
int iconindex = 0;
ICONINFO iinfo;
if(GetIconInfo(tray.hIcon,&iinfo) != 0)
{
iconindex = m_Image16List.Add(tray.hIcon);
}
Use this and enjoy
Cheers
Yasir
|
|
|
|
|
Report
|
|
|
|
04-03-2006, 7:03 PM
|
VC++ help
Joined on 03-20-2006
Posts 2
|
Re: Help needed to launch each of the system tray icons present
|
|
|
|
|
|
Hello Yasir
Thanks for the reply. I got a solution to this and implemented it 2 weeks back.
Thanks again.
Sincerely
Giftsana
|
|
|
|
|
Report
|
|
|
|
| |
|