name22

Extract Icons from Window Handle

May 30th, 2013
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WindowsConstants.au3>
  2. #include <GUIConstants.au3>
  3. #include <WinAPI.au3>
  4.  
  5. ;WinAPIEx.au3:
  6. Global Const $GCL_CBCLSEXTRA = -20
  7. Global Const $GCL_CBWNDEXTRA = -18
  8. Global Const $GCL_HBRBACKGROUND = -10
  9. Global Const $GCL_HCURSOR = -12
  10. Global Const $GCL_HICON = -14
  11. Global Const $GCL_HICONSM = -34
  12. Global Const $GCL_HMODULE = -16
  13. Global Const $GCL_MENUNAME = -8
  14. Global Const $GCL_STYLE = -26
  15. Global Const $GCL_WNDPROC = -24
  16.  
  17. ; -Author: name22 (www.autoit.de)
  18.  
  19. $hWnd = GUICreate("Searching...", 256, 256)
  20. GUISetState()
  21.  
  22. $hDC_Window = _WinAPI_GetDC($hWnd)
  23.  
  24. $aList = WinList()
  25.  
  26. For $i = 1 To $aList[0][0]
  27.     If BitAND(WinGetState($aList[$i][1]), 3) = 3 Then
  28.         $hIcon = _SendMessage($aList[$i][1], $WM_GETICON, 2, 0, 0, Default, Default, "HANDLE")
  29.  
  30.         If Not $hIcon Then $hIcon = _SendMessage($aList[$i][1], $WM_GETICON, 0, 0, 0, Default, Default, "HANDLE")
  31.  
  32.         If Not $hIcon Then $hIcon = _WinAPI_GetClassLongEx($aList[$i][1], $GCL_HICON)
  33.  
  34.         If Not $hIcon Then $hIcon = _WinAPI_GetClassLongEx($aList[$i][1], $GCL_HICONSM)
  35.  
  36.         If $hIcon Then
  37.             WinSetTitle($hWnd, "", $aList[$i][0])
  38.             _SendMessage($hWnd, $WM_ERASEBKGND, $hDC_Window)
  39.             _WinAPI_DrawIconEx($hDC_Window, 64, 64, $hIcon, 128, 128, 0, 0, 3)
  40.             _WinAPI_DestroyIcon($hIcon)
  41.             Sleep(1000)
  42.         EndIf
  43.     EndIf
  44. Next
  45.  
  46. While True
  47.     Switch GUIGetMsg()
  48.         Case $GUI_EVENT_CLOSE
  49.             ExitLoop
  50.     EndSwitch
  51. WEnd
  52.  
  53.  
  54. ; #FUNCTION# ====================================================================================================================
  55. ; Name...........: _WinAPI_GetClassLongEx
  56. ; Description....: Retrieves the specified value associated with the specified window.
  57. ; Syntax.........: _WinAPI_GetClassLongEx ( $hWnd, $iIndex )
  58. ; Parameters.....: $hWnd   - Handle to the window.
  59. ;                  $iIndex - The value to retrieve. This parameter can be one of the following values.
  60. ;
  61. ;                            $GCL_CBCLSEXTRA
  62. ;                            $GCL_CBWNDEXTRA
  63. ;                            $GCL_HBRBACKGROUND
  64. ;                            $GCL_HCURSOR
  65. ;                            $GCL_HICON
  66. ;                            $GCL_HICONSM
  67. ;                            $GCL_HMODULE
  68. ;                            $GCL_MENUNAME
  69. ;                            $GCL_STYLE
  70. ;                            $GCL_WNDPROC
  71. ;
  72. ; Return values..: Success - The requested value.
  73. ;                  Failure - 0 and sets the @error flag to non-zero.
  74. ; Author.........: Yashied
  75. ; Modified.......:
  76. ; Remarks........: None
  77. ; Related........:
  78. ; Link...........: @@MsdnLink@@ GetClassLong
  79. ; Example........: Yes
  80. ; ===============================================================================================================================
  81.  
  82. Func _WinAPI_GetClassLongEx($hWnd, $iIndex)
  83.  
  84.     Local $Ret
  85.  
  86.     If @AutoItX64 Then
  87.         $Ret = DllCall('user32.dll', 'ulong_ptr', 'GetClassLongPtrW', 'hwnd', $hWnd, 'int', $iIndex)
  88.     Else
  89.         $Ret = DllCall('user32.dll', 'ulong', 'GetClassLongW', 'hwnd', $hWnd, 'int', $iIndex)
  90.     EndIf
  91.     If (@error) Or (Not $Ret[0]) Then
  92.         Return SetError(1, 0, 0)
  93.     EndIf
  94.     Return $Ret[0]
  95. EndFunc   ;==>_WinAPI_GetClassLongEx
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×