;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;FileName:TrayIcon.asm
;Function:Demothewaytoenumtheiconsinsystemtray
;Author:PurpleEndurer |紫郢剑侠㊣(PurpleEndurer@163.com)
;DevEnv:Win2000proSP4,MASM32v8
;
;log
;----------------------------------------------------------------------------------
;2007-09-29CanrununderWinXP
;2007-09-22Created!
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.386
.model flat, stdcall
option casemap: none
include/masm32/ include/windows.inc
include/masm32/ include/kernel32.inc
includelib/masm32/ lib/kernel32.lib
include/masm32/ include/user32.inc
includelib/masm32/ lib/user32.lib
GetSysTrayToolBarHandle proto
EnumSubCtl proto:HWND,:LPARAM
GetSysTrayIconCount proto
EnumSysTrayIcon proto
.data
g_szAppName db "EnumSysTrayIcon",0
g_szTaskBarCls db "Shell_TrayWnd",0
g_szSysPagerCls db "SysPager",0 ;WinXPneed!
g_szTrayNotifyWndCls db "TrayNotifyWnd",0
g_szToolbarWindow32Cls db "ToolbarWindow32",0
g_szFailGetSysTray db "Failtogetsystemtray!",0
g_hSysTrayHANDLE?
g_dwTrayIconCount dword?
g_stTbButtonTBBUTTON<>
g_szIconText dbMAX_PATHdup(?)
.code
start:
invokeGetSysTrayToolBarHandle
test eax, eax ;.ifeax==NULL
.ifZERO?
invokeMessageBox,NULL, addrg_szFailGetSysTray, addrg_szAppName,MB_ICONERROR
.else
movg_hSysTray, eax
invokeEnumSysTrayIcon
.endif
invokeExitProcess,NULL
;////////////////////////////////////////////////////////////////////////////////
;Function:GetthehandleToolbarWindow32ofinsystemtray
;Shell_TrayWnd->TrayNotifyWnd->(WinXP:SysPager)->ToolbarWindow32
;Onput:iffaileax=NULL,elseeax=handle
;/////////////////////////////////////////////////////////////////////////////////
GetSysTrayToolBarHandle proc
;---Getthehandleoftaskbar
invokeFindWindow, addrg_szTaskBarCls,NULL
cmp eax,NULL
je@GetSysTrayToolBarHandleRet ;fail
;HWNDFindWindowEx(
;HWNDhwndParent,//handletoparentwindow
;HWNDhwndChildAfter,//handletoachildwindow
;LPCTSTRlpszClass,//pointertoclassname
;LPCTSTRlpszWindow//pointertowindowname
;);
;---GetthehandleofTrayNotifyWndintaskbar
invokeFindWindowEx, eax,NULL, addrg_szTrayNotifyWndCls,NULL
cmp eax,NULL
je@GetSysTrayToolBarHandleRet
;---(WinXPOnly)Getthehandleofg_szSysPagerinTrayNotifyWnd
push eax
invokeFindWindowEx, eax,NULL, addrg_szSysPagerCls,NULL
.if( eax==NULL)
pop eax
.else
pop edi
.endif
;---GetthehandleofToolbarWindow32inTrayNotifyWnd
invokeFindWindowEx, eax,NULL, addrg_szToolbarWindow32Cls,NULL
@GetSysTrayToolBarHandleRet:
ret
GetSysTrayToolBarHandle endp
;/////////////////////////////////////////////////////////////////////////////////
;Function:EnumtheChildwindowintaskbar
;/////////////////////////////////////////////////////////////////////////////////
EnumSubCtl proc prochWnd:HWND,lParam:LPARAM
invokeGetClassName,hWnd, addrg_szIconText,sizeofg_szIconText
invokeMessageBox,NULL, addrg_szIconText, addrg_szIconText,MB_OK
mov eax, TRUE
ret
EnumSubCtl endp
;/////////////////////////////////////////////////////////////////////////////////
;Function:Getthecountoficoninsystemtray
;/////////////////////////////////////////////////////////////////////////////////
GetSysTrayIconCount proc
invokeSendMessage,g_hSysTray,TB_BUTTONCOUNT,0,0
movg_dwTrayIconCount, eax
ret
GetSysTrayIconCount endp
;///////////////////////////////////////////////////////////////////////
;Function:Enumtheiconinsystemtray
;///////////////////////////////////////////////////////////////////////
EnumSysTrayIcon proc
localdwProcID,dwReaded: dword
localhProcess:HANDLE
localpMem: dword
invokeGetSysTrayIconCount
invokeGetWindowThreadProcessId,g_hSysTray, addrdwProcID
invokeOpenProcess,PROCESS_VM_OPERATION orPROCESS_VM_READ orPROCESS_VM_WRITE, FALSE,dwProcID
movhProcess, eax
invokeVirtualAllocEx,hProcess,NULL,1024,MEM_RESERVE orMEM_COMMIT,PAGE_READWRITE
movpMem, eax
xor eax, eax
.while( eax<g_dwTrayIconCount)
push eax
invokeSendMessage,g_hSysTray,TB_GETBUTTON, eax,pMem
invokeReadProcessMemory,hProcess,pMem, addrg_stTbButton,sizeofg_stTbButton, addrdwReaded
invokeSendMessage,g_hSysTray,TB_GETBUTTONTEXT,g_stTbButton.idCommand,pMem
inc eax ;Iffail,thereturnvalueis-1
jz@F ;Fail,skip
invokeReadProcessMemory,hProcess,pMem, addrg_szIconText,sizeofg_szIconText, addrdwReaded
invokeMessageBox,NULL, addrg_szIconText, addrg_szAppName,NULL
@@:
pop eax
inc eax
.endw
invokeVirtualFreeEx,hProcess,pMem,0,MEM_RELEASE
invokeCloseHandle,hProcess
ret
EnumSysTrayIcon endp
endstart
;FileName:TrayIcon.asm
;Function:Demothewaytoenumtheiconsinsystemtray
;Author:PurpleEndurer |紫郢剑侠㊣(PurpleEndurer@163.com)
;DevEnv:Win2000proSP4,MASM32v8
;
;log
;----------------------------------------------------------------------------------
;2007-09-29CanrununderWinXP
;2007-09-22Created!
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.386
.model flat, stdcall
option casemap: none
include/masm32/ include/windows.inc
include/masm32/ include/kernel32.inc
includelib/masm32/ lib/kernel32.lib
include/masm32/ include/user32.inc
includelib/masm32/ lib/user32.lib
GetSysTrayToolBarHandle proto
EnumSubCtl proto:HWND,:LPARAM
GetSysTrayIconCount proto
EnumSysTrayIcon proto
.data
g_szAppName db "EnumSysTrayIcon",0
g_szTaskBarCls db "Shell_TrayWnd",0
g_szSysPagerCls db "SysPager",0 ;WinXPneed!
g_szTrayNotifyWndCls db "TrayNotifyWnd",0
g_szToolbarWindow32Cls db "ToolbarWindow32",0
g_szFailGetSysTray db "Failtogetsystemtray!",0
g_hSysTrayHANDLE?
g_dwTrayIconCount dword?
g_stTbButtonTBBUTTON<>
g_szIconText dbMAX_PATHdup(?)
.code
start:
invokeGetSysTrayToolBarHandle
test eax, eax ;.ifeax==NULL
.ifZERO?
invokeMessageBox,NULL, addrg_szFailGetSysTray, addrg_szAppName,MB_ICONERROR
.else
movg_hSysTray, eax
invokeEnumSysTrayIcon
.endif
invokeExitProcess,NULL
;////////////////////////////////////////////////////////////////////////////////
;Function:GetthehandleToolbarWindow32ofinsystemtray
;Shell_TrayWnd->TrayNotifyWnd->(WinXP:SysPager)->ToolbarWindow32
;Onput:iffaileax=NULL,elseeax=handle
;/////////////////////////////////////////////////////////////////////////////////
GetSysTrayToolBarHandle proc
;---Getthehandleoftaskbar
invokeFindWindow, addrg_szTaskBarCls,NULL
cmp eax,NULL
je@GetSysTrayToolBarHandleRet ;fail
;HWNDFindWindowEx(
;HWNDhwndParent,//handletoparentwindow
;HWNDhwndChildAfter,//handletoachildwindow
;LPCTSTRlpszClass,//pointertoclassname
;LPCTSTRlpszWindow//pointertowindowname
;);
;---GetthehandleofTrayNotifyWndintaskbar
invokeFindWindowEx, eax,NULL, addrg_szTrayNotifyWndCls,NULL
cmp eax,NULL
je@GetSysTrayToolBarHandleRet
;---(WinXPOnly)Getthehandleofg_szSysPagerinTrayNotifyWnd
push eax
invokeFindWindowEx, eax,NULL, addrg_szSysPagerCls,NULL
.if( eax==NULL)
pop eax
.else
pop edi
.endif
;---GetthehandleofToolbarWindow32inTrayNotifyWnd
invokeFindWindowEx, eax,NULL, addrg_szToolbarWindow32Cls,NULL
@GetSysTrayToolBarHandleRet:
ret
GetSysTrayToolBarHandle endp
;/////////////////////////////////////////////////////////////////////////////////
;Function:EnumtheChildwindowintaskbar
;/////////////////////////////////////////////////////////////////////////////////
EnumSubCtl proc prochWnd:HWND,lParam:LPARAM
invokeGetClassName,hWnd, addrg_szIconText,sizeofg_szIconText
invokeMessageBox,NULL, addrg_szIconText, addrg_szIconText,MB_OK
mov eax, TRUE
ret
EnumSubCtl endp
;/////////////////////////////////////////////////////////////////////////////////
;Function:Getthecountoficoninsystemtray
;/////////////////////////////////////////////////////////////////////////////////
GetSysTrayIconCount proc
invokeSendMessage,g_hSysTray,TB_BUTTONCOUNT,0,0
movg_dwTrayIconCount, eax
ret
GetSysTrayIconCount endp
;///////////////////////////////////////////////////////////////////////
;Function:Enumtheiconinsystemtray
;///////////////////////////////////////////////////////////////////////
EnumSysTrayIcon proc
localdwProcID,dwReaded: dword
localhProcess:HANDLE
localpMem: dword
invokeGetSysTrayIconCount
invokeGetWindowThreadProcessId,g_hSysTray, addrdwProcID
invokeOpenProcess,PROCESS_VM_OPERATION orPROCESS_VM_READ orPROCESS_VM_WRITE, FALSE,dwProcID
movhProcess, eax
invokeVirtualAllocEx,hProcess,NULL,1024,MEM_RESERVE orMEM_COMMIT,PAGE_READWRITE
movpMem, eax
xor eax, eax
.while( eax<g_dwTrayIconCount)
push eax
invokeSendMessage,g_hSysTray,TB_GETBUTTON, eax,pMem
invokeReadProcessMemory,hProcess,pMem, addrg_stTbButton,sizeofg_stTbButton, addrdwReaded
invokeSendMessage,g_hSysTray,TB_GETBUTTONTEXT,g_stTbButton.idCommand,pMem
inc eax ;Iffail,thereturnvalueis-1
jz@F ;Fail,skip
invokeReadProcessMemory,hProcess,pMem, addrg_szIconText,sizeofg_szIconText, addrdwReaded
invokeMessageBox,NULL, addrg_szIconText, addrg_szAppName,NULL
@@:
pop eax
inc eax
.endw
invokeVirtualFreeEx,hProcess,pMem,0,MEM_RELEASE
invokeCloseHandle,hProcess
ret
EnumSysTrayIcon endp
endstart
本文介绍了一个使用MASM32实现的示例程序,该程序可以枚举Windows系统托盘中的图标。通过查找任务栏窗口、TrayNotifyWnd及ToolbarWindow32等窗口句柄,进而获取系统托盘图标数量并读取每个图标的详细信息。
1792

被折叠的 条评论
为什么被折叠?



