Advertisement
Guest User

Untitled

a guest
Jul 8th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.14 KB | None | 0 0
  1. #include-once
  2. #include <WinAPIConstants.au3>
  3.  
  4. Global Const $DWM_TNP_RECTDESTINATION = 0x00000001
  5. ;~ Global Const $DWM_TNP_RECTSOURCE = 0x00000002
  6. Global Const $DWM_TNP_OPACITY = 0x00000004
  7. Global Const $DWM_TNP_VISIBLE = 0x00000008
  8. Global Const $DWM_TNP_SOURCECLIENTAREAONLY = 0x00000010
  9.  
  10.  
  11.  
  12. HotKeySet('{ESC}',Exit1)
  13. Func Exit1()
  14.     Exit
  15. EndFunc
  16.  
  17. $targetGUI = HWnd(0x000000000002004C)
  18.  
  19. $hGUI1 = GUICreate('Preview 1',400,400)
  20. GUISetState(@SW_SHOW,$hGUI1)
  21. $handle1 = RegisterWindowLivePreview($targetGUI,$hGUI1)
  22.  
  23.  
  24. $hGUI2 = GUICreate('Preview 2',400,400)
  25. GUISetState(@SW_SHOW,$hGUI2)
  26. $handle2 = RegisterWindowLivePreview($targetGUI,$hGUI2)
  27.  
  28.  
  29. While 1
  30.     Sleep(100)
  31. WEnd
  32.  
  33.  
  34.  
  35. Func RegisterWindowLivePreview($hWindow,$hLivePreviewGui, $iClientAreaOnly = False, $iLivePreviewWidth = Default, $iLivePreviewHeight = Default, _
  36.                                         $iLivePreviewRectX = 0, $iLivePreviewRectY = 0)
  37.  
  38.  
  39.     If $iLivePreviewWidth = Default Or $iLivePreviewHeight = Default Then
  40.  
  41.         Local $aPos = WinGetPos($hLivePreviewGui)
  42.         If @error Then
  43.             ConsoleWrite("Can't get size of the GUI where the live preview will be draw." & @CRLF)
  44.             Return SetError(1)
  45.         EndIf
  46.  
  47.         If $iLivePreviewWidth = Default Then $iLivePreviewWidth = $aPos[2]
  48.         If $iLivePreviewHeight = Default Then $iLivePreviewHeight = $aPos[3]
  49.  
  50.     EndIf
  51.  
  52.     Local $hDwmLivePreviewHandle = _DWM_Thumbnail_Register($hLivePreviewGui, $hWindow)
  53.     If @error Then
  54.         ConsoleWrite("Registration of Thumbnail failed." & @CRLF)
  55.         Return SetError(2)
  56.     EndIf
  57.     ConsoleWrite($hDwmLivePreviewHandle & @CRLF)
  58.     If Not _DwmQueryThumbnailSourceSize($hDwmLivePreviewHandle) Then
  59.         ConsoleWrite("Thumbnail Source Size could not be determined." & @CRLF)
  60.         _DWM_Thumbnail_Unregister($hDwmLivePreviewHandle)
  61.         Return SetError(3)
  62.     EndIf
  63.  
  64.     _DWM_Thumbnail_Update_Properties($hDwmLivePreviewHandle, $iLivePreviewRectX, $iLivePreviewRectY, $iLivePreviewWidth, $iLivePreviewHeight)
  65.     If @error Then
  66.         ConsoleWrite("Failed to _DWM_Thumbnail_Update_Properties" & @CRLF)
  67.         _DWM_Thumbnail_Unregister($hDwmLivePreviewHandle)
  68.         Return SetError(4)
  69.     EndIf
  70.  
  71.     Return $hDwmLivePreviewHandle
  72.  
  73. EndFunc
  74.  
  75.  
  76.  
  77.  
  78. Func _DWM_Thumbnail_Register($hwnd, $hWndOw)
  79.  
  80.     $tID = DllStructCreate('dword')
  81.     $aRet = DllCall("dwmapi.dll", "int", "DwmRegisterThumbnail", "hwnd", $hwnd, "hwnd", $hWndOw, "ptr*", DllStructGetPtr($tID))
  82.     If Not IsArray($aRet) Then
  83.         Return SetError(1, 0, 0) ; Register thumbnail failed
  84.     EndIf
  85.  
  86.     Return $aRet[3]
  87. EndFunc   ;==>_DWM_Thumbnail_Register
  88.  
  89.  
  90.  
  91. Func _DwmQueryThumbnailSourceSize($hThumbID)
  92.     #cs
  93.         http://msdn.microsoft.com/en-us/library/aa969520%28VS.85%29.aspx
  94.         HRESULT DwmQueryThumbnailSourceSize(
  95.         HTHUMBNAIL hThumbnail,
  96.         PSIZE pSize
  97.         );
  98.         typedef struct tagSIZE {
  99.         LONG cx;
  100.         LONG cy;
  101.         }SIZE, *PSIZE;
  102.     #ce
  103.  
  104.     $tSize = DllStructCreate("int X;int Y")
  105.     $aRet = DllCall("dwmapi.dll", "hwnd", "DwmQueryThumbnailSourceSize", "hwnd", $hThumbID, "ptr", DllStructGetPtr($tSize))
  106.  
  107.  
  108.     If IsArray($aRet) And $aRet[0] = $S_OK Then
  109.         $i_hwnd_Thumbnail_Width = DllStructGetData($tSize, 1)
  110.         $i_hwnd_Thumbnail_Height = DllStructGetData($tSize, 2)
  111.         Return True
  112.     Else
  113.  
  114. ;~      if Not IsArray($aRet) Then
  115. ;~          _FileWriteLog('WindowTopLog.log', "DwmAPI.au3 - L45 - _DwmQueryThumbnailSourceSize - $aRet is not array - return false")
  116. ;~      Else
  117. ;~          _FileWriteLog('WindowTopLog.log', "DwmAPI.au3 - L47 - _DwmQueryThumbnailSourceSize - $aRet[0] = " & $aRet[0])
  118. ;~      EndIf
  119.         Return False
  120.     EndIf
  121. EndFunc   ;==>_DwmQueryThumbnailSourceSize
  122.  
  123. Func _DWM_Thumbnail_Update_Properties($hThumbID, $rcDest_X, $rcDest_Y, $rcDest_Width, $rcDest_Height, $rcOpacity = 255, $rcReadOnly = True, $rcClientAreaOnly = 0)
  124.  
  125.  
  126.     $tDWM_THUMBNAIL_PROPERTIES = DllStructCreate("dword dwFlags;int rcDestination[4];int rcSource[4];byte opacity;int fVisible;int fSourceClientAreaOnly")
  127.  
  128.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "dwFlags", BitOR($DWM_TNP_RECTDESTINATION, $DWM_TNP_OPACITY, $DWM_TNP_VISIBLE, $DWM_TNP_SOURCECLIENTAREAONLY))
  129.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_X, 1)
  130.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_Y, 2)
  131.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_Width, 3)
  132.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_Height, 4)
  133.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "opacity", $rcOpacity)
  134.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "fVisible", $rcReadOnly)
  135.     DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "fSourceClientAreaOnly", $rcClientAreaOnly)
  136.  
  137.     $pDWM_THUMBNAIL_PROPERTIES = DllStructGetPtr($tDWM_THUMBNAIL_PROPERTIES)
  138.  
  139.     $aRet = DllCall("dwmapi.dll", "int", "DwmUpdateThumbnailProperties", "ptr", $hThumbID, "ptr", $pDWM_THUMBNAIL_PROPERTIES)
  140.     If Not IsArray($aRet) Then
  141.  
  142.         Return SetError(1, 0, 0) ; Update thumbnail failed
  143.     EndIf
  144.  
  145.     ;_ArrayDisplay($aRet, "DwmAPI.au3 - L80 - aRet array")
  146.  
  147. EndFunc   ;==>_DWM_Thumbnail_Update_Properties
  148.  
  149. Func _DWM_Thumbnail_Unregister($hThumbID)
  150.  
  151.     $aRet = DllCall("dwmapi.dll", "int", "DwmUnregisterThumbnail", "hwnd", $hThumbID)
  152.     If Not IsArray($aRet) Then
  153.  
  154.         Return SetError(1, 0, 0) ; Unregister thumbnail failed
  155.     EndIf
  156.  
  157.     Return $aRet[0]
  158. EndFunc   ;==>_DWM_Thumbnail_Unregister
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement