//---------------------------------------------------------------------------- // File: shellico.txt //---------------------------------------------------------------------------- // You are allowed to distribute this document unmodified for free, // without paying me any fee. // The information in this document is provided AS IS, // without any warranties or guarantees. // // All undocumented Windows features used/described in this document // are discovered by me, Nick N. Repin. // // Copyright (c) Nikolay N. Repin (Nick N. Repin), 1998 //---------------------------------------------------------------------------- // Enumeration of all System Tray icons info. // [This file consist of several modules] //---------------------------------------------------------------------------- //********************************************************************* // Part 1. Enumerates all Systray icons info and display icons. // Injectes itself into the Explorer's address space. // // Consist of 2 modules: sh.cpp & shdll.cpp. //********************************************************************* / //---------------------------------------------------------------------------- // File: sh.cpp. // Compile & link with shdll.dll. // Run it in window, not in the full-screen mode. // // Creates the console, attached to the Explorer. // The icons info will be printed on this console. // Icons will be painted on the console window caption // at 200-pixels offset from the left. // Console will be automatically destroyed after 10 sec. //---------------------------------------------------------------------------- #define STRICT #include #include #include void _import SetTrayHook(); void main(void) { SetTrayHook(); Sleep(15000); SetTrayHook(); } //---------------------------------------------------------------------------- // File: shdll.cpp. // Compile in dll mode. //---------------------------------------------------------------------------- #define STRICT #include #include #include bool IsNT() { OSVERSIONINFO v; v.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); ::GetVersionEx(&v); return v.dwPlatformId==VER_PLATFORM_WIN32_NT; } bool isNT=IsNT(); void _export SetTrayHook(); void enumerateIcons(); void out(char* p=0); LRESULT CALLBACK MsgProc(int,WPARAM,LPARAM); HINSTANCE hInstance; HHOOK hHook=0; HWND SysTray=0; HWND NotifyWnd=0; DWORD dwExplorerThreadId=0,dwExplorerProcessId=0; char msg[256]; HANDLE hCon=0; HWND wCon=0; BOOL WINAPI DllEntryPoint(HINSTANCE hInstDll,DWORD fdwReason,LPVOID) { switch(fdwReason) { case DLL_PROCESS_ATTACH: hInstance=hInstDll; break; case DLL_THREAD_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_DETACH: break; } return TRUE; } void SetTrayHook() { if(hHook==NULL) { SysTray=FindWindow("Shell_TrayWnd",NULL); NotifyWnd=FindWindowEx(SysTray,0,"TrayNotifyWnd",0); dwExplorerThreadId=GetWindowThreadProcessId(SysTray, &dwExplorerProcessId); hHook=SetWindowsHookEx(WH_CALLWNDPROC,HOOKPROC(MsgProc), hInstance,dwExplorerThreadId); //PostThreadMessage(dwExplorerThreadId,WM_NULL,0,0); } else { UnhookWindowsHookEx(hHook); hHook=NULL; } return; } bool isFirst=true; LRESULT CALLBACK MsgProc(int nCode,WPARAM wParam,LPARAM lParam) { if(isFirst) { isFirst=false; isNT=IsNT(); SysTray=FindWindow("Shell_TrayWnd",NULL); NotifyWnd=FindWindowEx(SysTray,0,"TrayNotifyWnd",0); // To display messages AllocConsole(); hCon=CreateFile("CONOUT$",GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0); SetConsoleMode(hCon,ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT); CONSOLE_SCREEN_BUFFER_INFO bi; GetConsoleScreenBufferInfo(hCon,&bi); bi.dwSize.Y=200; SetConsoleScreenBufferSize(hCon,bi.dwSize); SetConsoleTitle("Nick's console"); wCon=FindWindow(0,"Nick's console"); out("We are in the Explorer!\r\n"); wsprintf(msg,"Console wnd=%X\r\n\r\n",wCon); out(); enumerateIcons(); Sleep(10000); // Wait 10 sec CloseHandle(hCon); FreeConsole(); } return CallNextHookEx(hHook,nCode,wParam,lParam); } struct TWIconDataT { DWORD imageIndex; // image index, -1 if no image in iconList union { NOTIFYICONDATAW dw; NOTIFYICONDATAA da; }; }; typedef TWIconDataT* pTWIconDataT; struct TWIconsInfoT { int Cnt; pTWIconDataT* iconData; }; struct TWDataT { DWORD unknown[7]; TWIconsInfoT* iconsInfo; HIMAGELIST iconList; }; typedef pTWIconDataT WINAPI (*COMCTL32_332_T) (TWIconsInfoT* info,int index); COMCTL32_332_T COMCTL32_332; void enumerateIcons() { // Load useful function HINSTANCE hLib=LoadLibrary("COMCTL32.DLL"); COMCTL32_332=(COMCTL32_332_T) GetProcAddress(hLib,LPCSTR(332)); TWDataT* twd=(TWDataT*)GetWindowLong(NotifyWnd,0); wsprintf(msg,"Proc=%X, NotifyWnd=%X, data=%X\r\n",COMCTL32_332, NotifyWnd,twd); out(); int cnt=twd->iconsInfo->Cnt; // icons count if(cnt==0) { out("No tray icons!\r\n"); return; } wsprintf(msg,"Icons count=%d",cnt); out(); int x=200; // Offset for icon painting for(int i=cnt-1;i>=0;i--) { wsprintf(msg,"\r\n\r\n# %d *****************\r\n",i); out(); pTWIconDataT p=COMCTL32_332(twd->iconsInfo,i); wsprintf(msg,"ImageIndex=%d\r\n",p->imageIndex); out(); wsprintf(msg,"hWnd=%X\r\n",p->dw.hWnd); out(); wsprintf(msg,"uID=%d\r\n",p->dw.uID); out(); wsprintf(msg,"uFlags=%d\r\n",p->dw.uFlags); out(); wsprintf(msg,"uCallbackMessage=%d\r\n",p->dw.uCallbackMessage); out(); wsprintf(msg,"hIcon=%X\r\n",p->dw.hIcon); out(); memset(msg,0,sizeof(msg)); strcpy(msg,"szTip="); if(isNT) wcstombs(msg+strlen(msg),p->dw.szTip,sizeof(p->dw.szTip)/2); else strcpy(msg+strlen(msg),p->da.szTip); out(); HICON icon=ImageList_GetIcon(twd->iconList,p->imageIndex,ILD_NORMAL); wsprintf(msg,"Real icon=%X\r\n",icon); // Draw icon HDC dc=GetWindowDC(wCon); ImageList_Draw(twd->iconList,p->imageIndex,dc,x,4,ILD_NORMAL); ReleaseDC(wCon,dc); x+=30; } } void out(char* p) { DWORD dwWritten; if(p) strcpy(msg,p); WriteConsole(hCon,msg,strlen(msg),&dwWritten,0); } //********************************************************************* // Part 2. Console program to enumerate Systray icons info. // Windows95/98. //********************************************************************* #include #include #include #include struct TWIconDataT { DWORD internalId; // image index, -1 if no image in iconList NOTIFYICONDATA d; }; typedef TWIconDataT* pTWIconDataT; struct TWIconsInfoT { int Cnt; pTWIconDataT* iconData; }; struct TWDataT { DWORD unknown[7]; TWIconsInfoT* iconsInfo; HIMAGELIST iconList; }; void main(void) { InitCommonControls(); HWND stw=FindWindow("Shell_TrayWnd",0); if(!stw) { cout<<"System tray not found!"<=0;i--) { cout<=0;i--) { cout<hwnd,0x418,0,0); } //--------------------------------------------------------------------------- // Returns pointer to IconInfoT struct. iIndex is icon index, from zero // to getIconCount()-1. bFlag must be true. pIconInfoT getIconInfo(pTrayDataT pData,int iIndex,bool bFlag) { ControlDataT s; s.sz=sizeof(s); s.dwFlags=bFlag ? 0x80000010 : 0x10; s.pIconInfo=0; SendMessageW(pData->hwnd,0x43F,iIndex,LPARAM(&s)); return s.pIconInfo; } //--------------------------------------------------------------------------- // Returns index of icon image in the image list. int getImageIndex(pTrayDataT pData,int iIndex) { ControlDataT s; s.sz=sizeof(s); s.dwFlags=0x80000001; SendMessageW(pData->hwnd,0x43F,iIndex,LPARAM(&s)); return s.iImage; } //--------------------------------------------------------------------------- // Sets tip for icon. void setTip(pTrayDataT pData,int iIndex,LPWSTR pTip) { ControlDataT s; s.sz=sizeof(s); s.dwFlags=0x80000002; s.pTip=pTip; s.szTip=MAXDWORD; SendMessageW(pData->hwnd,0x440,iIndex,LPARAM(&s)); } //--------------------------------------------------------------------------- // Gets tip for icon. void getTip(pTrayDataT pData,int iIndex,LPWSTR pTip,DWORD szTip) { ControlDataT s; s.sz=sizeof(s); s.dwFlags=0x80000002; s.pTip=pTip; s.szTip=szTip; SendMessageW(pData->hwnd,0x43F,iIndex,LPARAM(&s)); } //--------------------------------------------------------------------------- void enumerate() { // As usually. HWND hTrayNotifyWnd= FindWindowEx(FindWindow("Shell_TrayWnd",0),0,"TrayNotifyWnd",0); pTrayDataT pData=(pTrayDataT) GetWindowLong(hTrayNotifyWnd,0); int cnt=getIconCount(pData); for(int i=cnt-1;i>=0;i--) { pIconInfoT pInfo=getIconInfo(pData,i,true); int imageIndex=getImageIndex(pData,i); // ImageList_GetIcon(pData->hIList,imageIndex,....) // getTip(...) } } //--------------------------------------------------------------------------- //- EOF: shico2k.cpp --------------------------------------------------------