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

简介: MASM32编程访问系统托盘区图标/07-09-29更新
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; FileName: TrayIcon.asm
;   Function: Demo the way to enum the icons in system tray
;       Author: Purple Endurer | 紫郢剑侠㊣ (​​PurpleEndurer@163.com​​​)
;     DevEnv: Win2000 pro SP4, MASM32 v8
;
;  log
; ----------------------------------------------------------------------------------
; 2007-09-29  Can run under Win XP
; 2007-09-22  Created!
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


.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    
;WinXP need!

g_szTrayNotifyWndCls 
db 
"TrayNotifyWnd", 0

g_szToolbarWindow32Cls 
db 
"ToolbarWindow32", 0

g_szFailGetSysTray 
db 
"Fail to get system tray!", 0

g_hSysTray      HANDLE ?

g_dwTrayIconCount 
dword ?

g_stTbButton TBBUTTON <>

g_szIconText 
db MAX_PATH dup (?)


.code

start:

invoke GetSysTrayToolBarHandle

test   
eax, 
eax 
; .if  eax==NULL

.if ZERO?

    
invoke MessageBox, NULL, 
addr g_szFailGetSysTray, 
addr g_szAppName, MB_ICONERROR

.else

    
mov     g_hSysTray, 
eax

    
invoke EnumSysTrayIcon

.endif

invoke ExitProcess,NULL


;

; Function: Get the handle ToolbarWindow32 of in system tray

;           Shell_TrayWnd -> TrayNotifyWnd -> (WinXP:SysPager) -> ToolbarWindow32

;    Onput: if  fail eax=NULL, else eax = handle

;/

GetSysTrayToolBarHandle 
proc

   
;--- Get the handle of task bar

   
invoke FindWindow, 
addr g_szTaskBarCls, NULL

   
cmp     
eax, NULL

   
je         @GetSysTrayToolBarHandleRet 
; fail


     
; HWND FindWindowEx(

     
;     HWND hwndParent,    // handle to parent window

     
;     HWND hwndChildAfter,    // handle to a child window 

     
;     LPCTSTR lpszClass,    // pointer to class name

     
;     LPCTSTR lpszWindow    // pointer to window name

     
; );


    
;--- Get the handle of TrayNotifyWnd in task bar

    
invoke FindWindowEx, 
eax, NULL,  
addr  g_szTrayNotifyWndCls,   NULL

    
cmp    
eax, NULL

    
je         @GetSysTrayToolBarHandleRet


    
;--- (WinXP Only) Get the handle of g_szSysPager in TrayNotifyWnd 

    
push 
eax

    
invoke FindWindowEx, 
eax, NULL,  
addr  g_szSysPagerCls, NULL

    
.if    (
eax==NULL)

        
pop 
eax

    
.else

        
pop 
edi

    
.endif


    
;--- Get the handle of ToolbarWindow32 in TrayNotifyWnd

    
invoke FindWindowEx, 
eax, NULL,  
addr  g_szToolbarWindow32Cls,   NULL


@GetSysTrayToolBarHandleRet:

    
ret

GetSysTrayToolBarHandle 
endp



;/

; Function: Enum the Child window in task bar

;/

EnumSubCtl 
proc 
proc  hWnd: HWND, lParam: LPARAM

    
invoke GetClassName, hWnd, 
addr g_szIconText, sizeof g_szIconText

    
invoke MessageBox, NULL, 
addr g_szIconText, 
addr g_szIconText, MB_OK


    
mov     
eax, 
TRUE

    
ret

EnumSubCtl 
endp



;/

; Function: Get the count of icon in system tray

;/

GetSysTrayIconCount 
proc

    
invoke SendMessage,g_hSysTray, TB_BUTTONCOUNT, 0, 0

    
mov     g_dwTrayIconCount, 
eax    

    
ret

GetSysTrayIconCount 
endp


;///

; Function: Enum the icon in system tray

;///

EnumSysTrayIcon 
proc

    
local dwProcID, dwReaded: 
dword

    
local hProcess: HANDLE

    
local pMem: 
dword


    
invoke GetSysTrayIconCount


    
invoke GetWindowThreadProcessId, g_hSysTray, 
addr dwProcID

    
invoke OpenProcess, PROCESS_VM_OPERATION 
or PROCESS_VM_READ 
or PROCESS_VM_WRITE, 
FALSE, dwProcID

    
mov    hProcess, 
eax

    
invoke VirtualAllocEx, hProcess,  NULL, 1024, MEM_RESERVE 
or MEM_COMMIT,  PAGE_READWRITE

    
mov    pMem, 
eax


    
xor      
eax, 
eax

    
.while (
eax < g_dwTrayIconCount)

        
push   
eax


        
invoke SendMessage, g_hSysTray, TB_GETBUTTON, 
eax,  pMem

        
invoke ReadProcessMemory, hProcess, pMem, 
addr g_stTbButton, sizeof g_stTbButton,  
addr dwReaded


        
invoke SendMessage, g_hSysTray, TB_GETBUTTONTEXT, g_stTbButton.idCommand,  pMem


        
inc       
eax  
; If fail, the return value is  -1

        
jz         @F   
; Fail, skip


        
invoke ReadProcessMemory, hProcess,  pMem,   
addr g_szIconText, sizeof g_szIconText, 
addr dwReaded

        
invoke MessageBox, NULL, 
addr g_szIconText, 
addr g_szAppName, NULL

@@:

        
pop      
eax

        
inc       
eax

    
.endw


    
invoke VirtualFreeEx, hProcess, pMem,  0,  MEM_RELEASE

    
invoke CloseHandle, hProcess


    
ret

EnumSysTrayIcon 
endp


end
相关文章
Qt实用技巧:QtCreator编辑区关闭右侧不必要的警告提示
Qt实用技巧:QtCreator编辑区关闭右侧不必要的警告提示
Qt实用技巧:QtCreator编辑区关闭右侧不必要的警告提示
|
缓存 小程序 开发工具
解决微信开发工具的调试器加载错误,从任务栏打开工具可能导致该问题,请不要从任务栏启动工具。 和调试器控制台显示为空,刷新出不来的问题。
解决微信开发工具的调试器加载错误,从任务栏打开工具可能导致该问题,请不要从任务栏启动工具。 和调试器控制台显示为空,刷新出不来的问题。
651 0
QT应用编程: QSlider设置滚动块定位到鼠标点击的地方
QT应用编程: QSlider设置滚动块定位到鼠标点击的地方
570 0
QT应用编程: QSlider设置滚动块定位到鼠标点击的地方
MFC怎么用代码改变CComboBox的下拉方式?
MFC怎么用代码改变CComboBox的下拉方式?
176 0
|
测试技术
MFC中为菜单或按钮添加快捷键功能
1、新建一快捷键资源,ACCELERATOR,关联相应的ID号,下图所示中,其中,第一个ID为自定义快捷键ID,按CTRL+R,此时响应该ID以应的消息响应函数, 第二个ID为菜单ID,此时按CTRL+V,调出ID_NETWORK_PING菜单对应的响应函数。
1392 0