本帖最后由 happytc 于 2011-12-17 00:05 编辑
回复 3# xiaogou5852
闲得无聊,帮你写个了,你试试用用。
#include <SendMessage.au3>
#include <Memory.au3>
Global Const $_WM_USER = 0X400
TrayIconState("联众大厅", 0)
Func TrayIconState($sTrayName, $iState)
Local $hTray, $hToolbar, $iCnt, $iCmdApp, $sText, $iCmd
$hTray = WinGetHandle("[CLASS:Shell_TrayWnd]")
$hToolbar = ControlGetHandle($hTray, "", "[CLASSNN:ToolbarWindow321]")
$iCnt = _SendMessage($hToolbar, $_WM_USER + 24, 0, 0)
$iCmdApp = -1
For $i = 0 To $iCnt - 1
$iCmd = _getCommand($hToolbar, $i)
$sText = _getText($hToolbar, $iCmd)
If StringInStr($sText, $sTrayName) Then
$iCmdApp = $iCmd
ExitLoop
EndIf
Next
If $iCmdApp > -1 Then
If $iState Then
_SendMessage($hToolbar, $_WM_USER + 17, $iCmdApp, 0x00000004)
Else
_SendMessage($hToolbar, $_WM_USER + 17, $iCmdApp, 0x00000008)
EndIf
EndIf
EndFunc
Func _getCommand($hWnd, $iIndex)
Local Const $tagBUTTON = "int Bitmap;int Command;byte State;byte Style;align;dword_ptr Param;int_ptr String"
Local $tButton, $pButton, $iButton, $tMem, $pMem
$tButton = DllStructCreate($tagBUTTON)
$pButton = DllStructGetPtr($tButton)
$iButton = DllStructGetSize($tButton)
$pMem = _MemInit($hWnd, $iButton, $tMem)
_MemWrite($tMem, $pButton, $pMem, $iButton)
_SendMessage($hWnd, $_WM_USER + 23, $iIndex, $pMem)
_MemRead($tMem, $pMem, $pButton, $iButton)
_MemFree($tMem)
Return DllStructGetData($tButton, "Command")
EndFunc
Func _getText($hWnd, $iCmd)
Local $iBuffer, $tBuffer, $pBuffer, $tMem, $pMem
$iBuffer = _SendMessage($hWnd, $_WM_USER + 75, $iCmd)
$tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]")
$iBuffer *= 2
$pBuffer = DllStructGetPtr($tBuffer)
$pMem= _MemInit($hWnd, $iBuffer, $tMem)
_SendMessage($hWnd, $_WM_USER + 75, $iCmd, $pMem)
_MemRead($tMem, $pMem, $pBuffer, $iBuffer)
_MemFree($tMem)
Return DllStructGetData($tBuffer, "Text")
EndFunc
|