`
caobihole
  • 浏览: 952829 次
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;FileName:TrayIcon.asm
;Function:Demothewaytoenumtheiconsinsystemtray
;Author:PurpleEndurer |紫郢剑侠㊣(PurpleEndurer@163.com)
;DevEnv:Win2000proSP4,MASM32v8
;
;log
;----------------------------------------------------------------------------------
;2007-09-29CanrununderWinXP
;2007-09-22Created!
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

.386
.modelflat,stdcall
optioncasemap: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

GetSysTrayToolBarHandleproto
EnumSubCtlproto:HWND,:LPARAM
GetSysTrayIconCountproto
EnumSysTrayIconproto

.data
g_szAppNamedb"EnumSysTrayIcon",0
g_szTaskBarClsdb"Shell_TrayWnd",0
g_szSysPagerClsdb"SysPager",0;WinXPneed!
g_szTrayNotifyWndClsdb"TrayNotifyWnd",0
g_szToolbarWindow32Clsdb"ToolbarWindow32",0
g_szFailGetSysTraydb"Failtogetsystemtray!",0
g_hSysTrayHANDLE?
g_dwTrayIconCountdword?
g_stTbButtonTBBUTTON<>
g_szIconTextdbMAX_PATHdup(?)

.code
start:
invokeGetSysTrayToolBarHandle
testeax,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
;/////////////////////////////////////////////////////////////////////////////////
GetSysTrayToolBarHandleproc
;---Getthehandleoftaskbar
invokeFindWindow,addrg_szTaskBarCls,NULL
cmpeax,NULL
je@GetSysTrayToolBarHandleRet;fail

;HWNDFindWindowEx(
;HWNDhwndParent,//handletoparentwindow
;HWNDhwndChildAfter,//handletoachildwindow
;LPCTSTRlpszClass,//pointertoclassname
;LPCTSTRlpszWindow//pointertowindowname
;);

;---GetthehandleofTrayNotifyWndintaskbar
invokeFindWindowEx,eax,NULL,addrg_szTrayNotifyWndCls,NULL
cmpeax,NULL
je@GetSysTrayToolBarHandleRet

;---(WinXPOnly)Getthehandleofg_szSysPagerinTrayNotifyWnd
pusheax
invokeFindWindowEx,eax,NULL,addrg_szSysPagerCls,NULL
.if(eax==NULL)
popeax
.else
popedi
.endif

;---GetthehandleofToolbarWindow32inTrayNotifyWnd
invokeFindWindowEx,eax,NULL,addrg_szToolbarWindow32Cls,NULL

@GetSysTrayToolBarHandleRet:
ret
GetSysTrayToolBarHandleendp


;/////////////////////////////////////////////////////////////////////////////////
;Function:EnumtheChildwindowintaskbar
;/////////////////////////////////////////////////////////////////////////////////
EnumSubCtlprocprochWnd:HWND,lParam:LPARAM
invokeGetClassName,hWnd,addrg_szIconText,sizeofg_szIconText
invokeMessageBox,NULL,addrg_szIconText,addrg_szIconText,MB_OK

moveax,TRUE
ret
EnumSubCtlendp


;/////////////////////////////////////////////////////////////////////////////////
;Function:Getthecountoficoninsystemtray
;/////////////////////////////////////////////////////////////////////////////////
GetSysTrayIconCountproc
invokeSendMessage,g_hSysTray,TB_BUTTONCOUNT,0,0
movg_dwTrayIconCount,eax
ret
GetSysTrayIconCountendp

;///////////////////////////////////////////////////////////////////////
;Function:Enumtheiconinsystemtray
;///////////////////////////////////////////////////////////////////////
EnumSysTrayIconproc
localdwProcID,dwReaded:dword
localhProcess:HANDLE
localpMem:dword

invokeGetSysTrayIconCount

invokeGetWindowThreadProcessId,g_hSysTray,addrdwProcID
invokeOpenProcess,PROCESS_VM_OPERATIONorPROCESS_VM_READorPROCESS_VM_WRITE,FALSE,dwProcID
movhProcess,eax
invokeVirtualAllocEx,hProcess,NULL,1024,MEM_RESERVEorMEM_COMMIT,PAGE_READWRITE
movpMem,eax

xoreax,eax
.while(eax<g_dwTrayIconCount)
pusheax

invokeSendMessage,g_hSysTray,TB_GETBUTTON,eax,pMem
invokeReadProcessMemory,hProcess,pMem,addrg_stTbButton,sizeofg_stTbButton,addrdwReaded

invokeSendMessage,g_hSysTray,TB_GETBUTTONTEXT,g_stTbButton.idCommand,pMem

inceax;Iffail,thereturnvalueis-1
jz@F;Fail,skip

invokeReadProcessMemory,hProcess,pMem,addrg_szIconText,sizeofg_szIconText,addrdwReaded
invokeMessageBox,NULL,addrg_szIconText,addrg_szAppName,NULL
@@:
popeax
inceax
.endw

invokeVirtualFreeEx,hProcess,pMem,0,MEM_RELEASE
invokeCloseHandle,hProcess

ret
EnumSysTrayIconendp

endstart
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics