SHARE
TWEET

_GetHwndFromTrayWnd

BugFix Apr 24th, 2019 (edited) 246 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WinAPISys.au3>
  2.  
  3.  
  4. ; BEISPIEL:
  5. #include <WinAPI.au3>
  6. #include <WindowsConstants.au3>
  7.  
  8. ; Hwnd für ToolbarWindow32, Instance 1 (neben der Uhr)
  9. ;~ Local $hToolbar = _GetHwndFromTrayWnd('ToolbarWindow32')
  10.  
  11. ; Hwnd für Tasklist (neben Start-Button)
  12. Local $hTaskList = _GetHwndFromTrayWnd('MSTaskListWClass')
  13.  
  14. ;~ TEST:
  15. ;~ ConsoleWrite(WinSetState($hTaskList, '', @SW_HIDE) & @CRLF)
  16. ;~ Sleep(2000)
  17. ;~ ConsoleWrite(WinSetState($hTaskList, '', @SW_SHOW) & @CRLF)
  18.  
  19. ;~ REDRAW:
  20. _WinAPI_RedrawWindow($hTaskList, 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
  21.  
  22.  
  23. ; #FUNCTION# ====================================================================================================================
  24. ; Name ..........: _GetHwndFromTrayWnd
  25. ; Description ...: Handle eines Fensters des Shell_TrayWnd mit Classname (optional Instanz) abfragen oder alle Handle mit Classname und Instanz ausgeben
  26. ; Parameters ....: $_sClass     Das Handle für den übergebenen Classname wird ausgegeben (Default = 'all', alle Handle mit Classname und Instanz)
  27. ; ...............: $_iInstance  [optional] Die gesuchte Instanz des Klassenfensters (Default = 1)
  28. ; Return values .: Erfolg       Handle des gesuchten Klassenfensters oder Liste mit allen Handles + Classnames + Instance
  29. ; ...............: Fehler       0xDEAD - Classname und/oder Instance nicht zutreffend
  30. ; Author ........: BugFix
  31. ; ===============================================================================================================================
  32. Func _GetHwndFromTrayWnd($_sClass='all', $_iInstance=1)
  33.     If $_sClass = 'all' Then
  34.         Local $hTrayWnd = WinGetHandle('[CLASS:Shell_TrayWnd]')
  35.         Local $aChildren = _WinAPI_EnumChildWindows($hTrayWnd, False)
  36.         Local $iInstance = 1, $sAllOutput = ''
  37.         If IsArray($aChildren) Then
  38.             For $i = 1 To $aChildren[0][0]
  39.                 If $aChildren[$i-1][1] = $aChildren[$i][1] Then
  40.                     $iInstance += 1
  41.                 Else
  42.                     $iInstance = 1
  43.                 EndIf
  44.                 $sAllOutput &= StringFormat('%s\t[CLASS:%s; INSTANCE:%s]\n', $aChildren[$i][0], $aChildren[$i][1], $iInstance)
  45.             Next
  46.             Return $sAllOutput
  47.         EndIf
  48.     Else
  49.         Local $hWnd = ControlGetHandle('[Class:Shell_TrayWnd]', '', StringFormat('[Class:%s; Instance:%s]', $_sClass, $_iInstance))
  50.         If IsHWnd($hWnd) Then Return $hWnd
  51.     EndIf
  52.     Return 0xDEAD
  53. EndFunc
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top