IsHide:=True, Program:="QQ.exe" F1:: TrayIconInfo:=TrayIcon_GetInfo(Program) for Section,element In TrayIconInfo { TrayIcon_Hide(element.idCmd, element.Tray, IsHide),IsHide:=!IsHide } Return TrayIcon_Remove(hWnd, uId) { VarSetCapacity(NID, szNID := ((A_IsUnicode ? 2 : 1) * 384 + A_PtrSize*5 + 40),0) NumPut( szNID, NID, 0 ) NumPut( hWnd, NID, A_PtrSize ) NumPut( uId, NID, A_PtrSize*2 ) Return DllCall("Shell32.dll\Shell_NotifyIcon", UInt,0x2, UInt,&NID) } TrayIcon_Delete(idx, sTray:="Shell_TrayWnd") { d := A_DetectHiddenWindows DetectHiddenWindows, On idxTB := TrayIcon_GetTrayBar() SendMessage, 0x0416, idx, 0, ToolbarWindow32%idxTB%, ahk_class %sTrayPlace% ; TB_DELETEBUTTON = 0x0416 SendMessage, 0x001A, 0, 0, , ahk_class %sTrayPlace% DetectHiddenWindows, %d% } TrayIcon_Hide(idCmd, sTray:="Shell_TrayWnd", bHide:=True) { d := A_DetectHiddenWindows DetectHiddenWindows, On idxTB := TrayIcon_GetTrayBar() SendMessage, 0x0404, idCmd, bHide, ToolbarWindow32%idxTB%, ahk_class %sTray% ; TB_HIDEBUTTON SendMessage, 0x001A, 0, 0, , ahk_class %sTray% DetectHiddenWindows, %d% } TrayIcon_GetInfo(sExeName := "") { d := A_DetectHiddenWindows DetectHiddenWindows, On oTrayInfo := [] For key,sTray in ["Shell_TrayWnd", "NotifyIconOverflowWindow"] { idxTB := TrayIcon_GetTrayBar(sTray) WinGet, pidTaskbar, PID, ahk_class %sTray% hProc := DllCall("OpenProcess", UInt,0x38, Int,0, UInt,pidTaskbar) pRB := DllCall("VirtualAllocEx", Ptr,hProc, Ptr,0, UPtr,20, UInt,0x1000, UInt,0x04) szBtn := VarSetCapacity(btn, (A_Is64bitOS ? 32 : 20), 0) szNfo := VarSetCapacity(nfo, (A_Is64bitOS ? 32 : 24), 0) szTip := VarSetCapacity(tip, 128 * 2, 0) ; TB_BUTTONCOUNT = 0x0418 SendMessage, 0x0418, 0, 0, ToolbarWindow32%idxTB%, ahk_class %sTray% Loop, %ErrorLevel% { ; TB_GETBUTTON 0x0417 SendMessage, 0x0417, A_Index-1, pRB, ToolbarWindow32%idxTB%, ahk_class %sTray% DllCall("ReadProcessMemory", Ptr,hProc, Ptr,pRB, Ptr,&btn, UPtr,szBtn, UPtr,0) iBitmap := NumGet(btn, 0, "Int") idCmd := NumGet(btn, 4, "Int") fsState := NumGet(btn, 8, "UChar") fsStyle := NumGet(btn, 9, "UChar") dwData := NumGet(btn, (A_Is64bitOS ? 16 : 12), "UPtr") iString := NumGet(btn, (A_Is64bitOS ? 24 : 16), "Ptr") DllCall("ReadProcessMemory", Ptr,hProc, Ptr,dwData, Ptr,&nfo, UPtr,szNfo, UPtr,0) hWnd := NumGet(nfo, 0, "Ptr") uId := NumGet(nfo, (A_Is64bitOS ? 8 : 4), "UInt") msgId := NumGet(nfo, (A_Is64bitOS ? 12 : 8), "UPtr") hIcon := NumGet(nfo, (A_Is64bitOS ? 24 : 20), "Ptr") WinGet, nPid, PID, ahk_id %hWnd% WinGet, sProcess, ProcessName, ahk_id %hWnd% WinGetClass, sClass, ahk_id %hWnd% If ( !sExeName || sExeName == sProcess || sExeName == nPid ) { DllCall("ReadProcessMemory", Ptr,hProc, Ptr,iString, Ptr,&tip, UPtr,szTip, UPtr,0) oTrayInfo.Push({ "idx" : A_Index-1 , "idcmd" : idCmd , "pid" : nPid , "uid" : uId , "msgid" : msgId , "hicon" : hIcon , "hwnd" : hWnd , "class" : sClass , "process" : sProcess , "tooltip" : StrGet(&tip, "UTF-16") , "tray" : sTray }) } } DllCall("VirtualFreeEx", Ptr,hProc, Ptr,pRB, UPtr,0, UInt,0x8000) DllCall("CloseHandle", Ptr,hProc) } DetectHiddenWindows, %d% Return oTrayInfo } TrayIcon_GetTrayBar(sTray:="Shell_TrayWnd") { d := A_DetectHiddenWindows DetectHiddenWindows, On WinGet, ControlList, ControlList, ahk_class %sTray% RegExMatch(ControlList, "(?<=ToolbarWindow32)\d+(?!.*ToolbarWindow32)", nTB) Loop, %nTB% { ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class %sTray% hParent := DllCall( "GetParent", Ptr, hWnd ) WinGetClass, sClass, ahk_id %hParent% If !(sClass == "SysPager" || sClass == "NotifyIconOverflowWindow" ) Continue idxTB := A_Index Break } DetectHiddenWindows, %d% Return idxTB }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)