MASM32编程访问系统托盘区图标/07-09-29更新

本文介绍了一个使用MASM32实现的示例程序,该程序可以枚举Windows系统托盘中的图标。通过查找任务栏窗口、TrayNotifyWnd及ToolbarWindow32等窗口句柄,进而获取系统托盘图标数量并读取每个图标的详细信息。
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值