Sign in to follow this  
Followers 0
KaFu

SAT - Simple AERO Thumbnailer

1 post in this topic

#1 ·  Posted (edited)

Hiho,

derived from the thread "Simple vista thumbnail example" by monoceres and with great input by wraithdu I started this program.

Next steps will be to save config, auto-create thumbnails on windows existence, allow multiple previews and add more settings (thumbnail sizing and positioning).

To quit the preview, hover with the mouse cursor over the thumbnail and press ESC.

SAT - Simple AERO Thumbnailer.zip

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=SAT.ico
#AutoIt3Wrapper_Outfile=SAT.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_Comment=© SAT - Simple AERO Thumbnailer 2010 by Karsten Funk. All rights reserved. http://www.funk.eu
#AutoIt3Wrapper_Res_Description=SAT - Simple AERO Thumbnailer
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Creative Commons License "by-nc-sa 3.0", this program is freeware under Creative Commons License "by-nc-sa 3.0" (http://creativecommons.org/licenses/by-nc-sa/3.0/us/)
#AutoIt3Wrapper_res_requestedExecutionLevel=highestAvailable
://////=__=
://////=__=
://////=__=
#AutoIt3Wrapper_Au3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; AutoIt Version: 3.3.4.0

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>
#include <Misc.au3>

Global $s_versionnumber = "v1.0.0.0 (2010-Jan-31)"
Global $s_mainguititel = "SAT - Simple AERO Thumbnailer - " & $s_versionnumber

Opt("WinWaitDelay", 50)

Global $hwnd_Thumbnail, $hThumbID, $iPID

Global $i_hwnd_Thumbnail_Width, $i_hwnd_Thumbnail_Width_Save
Global $i_hwnd_Thumbnail_Height, $i_hwnd_Thumbnail_Height_Save

Global $iClientAreaOnly = 1 ; set to 1 to paint only client area
Global $aWinGetPos

Global Const $DWM_TNP_RECTDESTINATION = 0x00000001
Global Const $DWM_TNP_RECTSOURCE = 0x00000002
Global Const $DWM_TNP_OPACITY = 0x00000004
Global Const $DWM_TNP_VISIBLE = 0x00000008
Global Const $DWM_TNP_SOURCECLIENTAREAONLY = 0x00000010

Global Const $S_OK = 0
Global Const $S_FALSE = 1

Global $tTimer_Doubleclick = 0, $iPID = 0
Global $iZoomFactor_Large = 1 ; to set "large" thumbnail size to width = source width
Global $iZoomFactor_Large_PX = 600
Global $iZoomFactor_Small = 200 ; to set "small" thumbnail size to width = 100
Global $Big = True
Global $bExitPreview = False
Global $hMO_Hook, $hKB_Hook, $hStub_KeyProc, $hStub_MouseProc

If Not @OSVersion = "WIN_7" And Not @OSVersion = "WIN_VISTA" Then
    MsgBox(16, "Error", "Vista or Win7 needed to run example.")
    Exit
EndIf

$guiWinList = GUICreate($s_mainguititel)

$a_WinGetPosEx_Source = _WinGetPosEx($guiWinList)
If @extended <> 1 Then
    MsgBox(16, "Error", "AERO not enabled on your system, SAT will not work.")
    Exit
EndIf

$hListView = _GUICtrlListView_Create($guiWinList, "", 10, 10, 380, 320)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_InsertColumn($hListView, 0, "Window Title", 220)
_GUICtrlListView_InsertColumn($hListView, 1, "Process", 80)
_GUICtrlListView_InsertColumn($hListView, 2, "Handle", 80)

$hImage = _GUIImageList_Create(16, 16, 5, 1 + 2, 0, 1)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)

$var = WinList()
$ProcessList = ProcessList()
$AutoItPID = @AutoItPID
$line = 0
Global $aImagePos[1][2]
For $i = 1 To $var[0][0]
    $winHandle = $var[$i][1]
    $winTitle = $var[$i][0]
    $WinGetProcessName = ""
    $WinGetProcess = WinGetProcess($winHandle)
    $winHandleDesktop = WinGetHandle("Program Manager", "")
    If ($winTitle <> "" And IsVisible($winHandle) And $WinGetProcess <> $AutoItPID) Or $winHandle = $winHandleDesktop Then
        If $winHandle = $winHandleDesktop Then $winTitle = "Desktop"
        If $ProcessList[0][0] > 0 Then
            For $y = 1 To $ProcessList[0][0]
                If $ProcessList[$y][1] = $WinGetProcess Then
                    $WinGetProcessName = $ProcessList[$y][0]
                    ExitLoop
                EndIf
            Next
        Else
            $WinGetProcessName = "PID: " & $WinGetProcess
        EndIf

        $hIcon = getIconHandleByHwnd($winHandle)
        _GUIImageList_ReplaceIcon($hImage, -1, $hIcon)
        _GUICtrlListView_AddItem($hListView, $winTitle, 0)
        _GUICtrlListView_AddSubItem($hListView, $line, $WinGetProcessName, 1)
        _GUICtrlListView_AddSubItem($hListView, $line, $winHandle, 2)
        ReDim $aImagePos[$line + 1][2]
        $aImagePos[$line][0] = $winHandle
        $aImagePos[$line][1] = $line
        $line += 1
    EndIf
Next

$vDescending = False
_GUICtrlListView_SimpleSort($hListView, $vDescending, 0)

For $y = 0 To _GUICtrlListView_GetItemCount($hListView)
    For $i = 0 To UBound($aImagePos) - 1
        If $aImagePos[$i][0] = _GUICtrlListView_GetItemText($hListView, $y, 2) Then
            _GUICtrlListView_SetItemImage($hListView, $y, $i)
            ExitLoop
        EndIf
    Next
Next

$cButtonselect = GUICtrlCreateButton("Select", 150, 345, 100, 40)
$cButtonCancel = GUICtrlCreateButton("Cancel", 280, 345, 100, 40)

GUIStartGroup()
$cRadioWindow = GUICtrlCreateRadio("Whole window", 30, 345, 100, 20)
$cRadioClient = GUICtrlCreateRadio("Client area only", 30, 365, 100, 20)
GUICtrlSetState($cRadioWindow, $GUI_CHECKED)

GUISetState()

While Sleep(10)
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cButtonCancel Then
        Exit
    EndIf
    If $msg = $cButtonselect Then
        If _GUICtrlListView_GetSelectedCount($hListView) > 0 Then
            $aSelected = _GUICtrlListView_GetSelectedIndices($hListView, True)
            $hwnd_Source = HWnd(_GUICtrlListView_GetItemText($hListView, $aSelected[1], 2))
            If WinExists($hwnd_Source) Then
                If GUICtrlRead($cRadioWindow) = $GUI_CHECKED Then
                    $iClientAreaOnly = 0
                Else
                    $iClientAreaOnly = 1
                EndIf
                GUISetState(@SW_HIDE, $guiWinList)
                If Not BitAND(WinGetState($hwnd_Source, ""), 2) Then WinSetState($hwnd_Source, "", @SW_SHOW)
                _Show_Thumbnail()
                GUISetState(@SW_SHOW, $guiWinList)
                WinSetOnTop($guiWinList, "", 1)
                WinSetOnTop($guiWinList, "", 0)
            Else
                MsgBox(16, "Error", "Window not found...")
            EndIf
        Else
            MsgBox(64, "Select a Window", "You have to select a window to proced.")
        EndIf
    EndIf
WEnd

Func IsVisible($handle)
    If $handle = _WinAPI_GetDesktopWindow() Then Return 1
    If BitAND(WinGetState($handle), 2) And Not BitAND(_WinAPI_GetWindowLong($handle, $GWL_EXSTYLE), $WS_EX_TOOLWINDOW) And Not _WinAPI_GetParent($handle) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>IsVisible

Func getIconHandleByFile($pszPath)
    ; http://www.autoitscript.com/forum/index.php?showtopic=40762&st=0&p=303247&hl=icon%20handle%20window&fromsearch=1&#entry303247
    ; lod3n

    $SHGFI_ICON = 0x100 ;Get icon
    $SHGFI_SMALLICON = 0x1 ;Get Small Icon

    $dwFileAttributes = 0
    $psfi = DllStructCreate("uint;int;dword;char[260];char[80]") ; thanks Holger!
    $cbSizeFileInfo = DllStructGetSize($psfi)
    $uFlags = BitOR($SHGFI_ICON, $SHGFI_SMALLICON)

    $hImgSmall = DllCall('shell32.dll', 'int', 'SHGetFileInfo', _
            'str', $pszPath, _
            'uint', $dwFileAttributes, _
            'ptr', DllStructGetPtr($psfi), _
            'uint', $cbSizeFileInfo, _
            'uint', $uFlags)

    Return DllStructGetData($psfi, 1)
EndFunc   ;==>getIconHandleByFile

Func getIconHandleByHwnd($hwnd)
    ; http://www.autoitscript.com/forum/index.php?showtopic=40762&st=0&p=303247&hl=icon%20handle%20window&fromsearch=1&#entry303247
    ; lod3n

    $hwnd = HWnd($hwnd)
    ;$WM_GETICON = 0x7F
    $GCL_HICONSM = -34
    $GCL_HICON = -14
    ;$IDI_APPLICATION = 32512
    $hIcon = 0
    $hIcon = _SendMessage($hwnd, $WM_GETICON, False, 0)
    If ($hIcon == 0) Then $hIcon = _SendMessage($hwnd, $WM_GETICON, True, 0)
    If ($hIcon == 0) Then
        $hIcon = DllCall("user32.dll", "int", "GetClassLong", "hwnd", $hwnd, "int", $GCL_HICONSM)
        $hIcon = $hIcon[0]
    EndIf
    If ($hIcon == 0) Then
        $hIcon = DllCall("user32.dll", "int", "GetClassLong", "hwnd", $hwnd, "int", $GCL_HICON)
        $hIcon = $hIcon[0]
    EndIf
    If ($hIcon == 0) Then
        $pid = WinGetProcess(HWnd($hwnd))
        $path = getExePathByPid($pid)
        $hIcon = getIconHandleByFile($path)
    EndIf
    Return $hIcon
EndFunc   ;==>getIconHandleByHwnd

Func getExePathByPid($pid)
    $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            Return $objItem.ExecutablePath
        Next
    EndIf
EndFunc   ;==>getExePathByPid

Func _Show_Thumbnail()

    Opt("GUIOnEventMode", 1)

    $hStub_MouseProc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
    $hMO_Hook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), _WinAPI_GetModuleHandle(0))

    $hStub_KeyProc = DllCallbackRegister("_Key_Proc", "long", "int;wparam;lparam")
    $hKB_Hook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), _WinAPI_GetModuleHandle(0))

    If $iPID = 0 Then $iPID = WinGetProcess($hwnd_Source)


    $a_WinGetPosEx_Source = _WinGetPosEx($hwnd_Source)
    If @extended <> 1 Then
        MsgBox(16, "Error", "AERO not enabled on your system. Example will not work.")
        ;ProcessClose($iPID)
        Exit
    EndIf

    While Not BitAND(WinGetState($hwnd_Source, ""), 2)
        Sleep(10)
    WEnd

    $hwnd_Thumbnail = GUICreate("Vista Thumbnail", 100, 100, 100, 100, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_CONTROLPARENT))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    $hThumbID = _DWM_Thumbnail_Register($hwnd_Thumbnail, $hwnd_Source)
    If @error Then
        MsgBox(16, "Error", "Registration of Thumbnail failed.")
        _exit()
    EndIf

    If _DwmQueryThumbnailSourceSize($hThumbID) = False Then
        MsgBox(16, "Error", "Thumbnail Source Size could not be determined.")
        _exit()
    EndIf
    $iZoomFactor_Large = $iZoomFactor_Large_PX / $i_hwnd_Thumbnail_Width ; to set "large" thumbnail size to width = 300

    $aWinGetPos = WinGetPos($hwnd_Thumbnail)
    _DWM_Thumbnail_Update_Properties($hThumbID, 0, 0, $i_hwnd_Thumbnail_Width * ($iZoomFactor_Small / $i_hwnd_Thumbnail_Height), $iZoomFactor_Small, 255, True, $iClientAreaOnly)
    WinMove($hwnd_Thumbnail, "", $aWinGetPos[0], $aWinGetPos[1], $i_hwnd_Thumbnail_Width * ($iZoomFactor_Small / $i_hwnd_Thumbnail_Height), $iZoomFactor_Small)

    $i_hwnd_Thumbnail_Height_Save = $i_hwnd_Thumbnail_Height
    $i_hwnd_Thumbnail_Width_Save = $i_hwnd_Thumbnail_Width

    $Big = True

    AdlibRegister("_check_GUI")

    Sleep(500) ; works for me, otherwise the inital thumb is resized / flickering a bit

    GUISetState()

    $bExitPreview = False
    Local Const $VK_ESC = 0x1B

    While Sleep(250)
        If Not ProcessExists($iPID) Or Not WinExists($hwnd_Source) Or $bExitPreview = True Then ExitLoop
    WEnd

    _exit()

EndFunc   ;==>_Show_Thumbnail



Func _exit()

    AdlibUnRegister("_check_GUI")
    If IsHWnd($hwnd_Thumbnail) Then WinSetState($hwnd_Thumbnail, "", @SW_HIDE)
    _DWM_Thumbnail_Unregister($hThumbID)

    _WinAPI_UnhookWindowsHookEx($hMO_Hook)
    DllCallbackFree($hStub_MouseProc)

    _WinAPI_UnhookWindowsHookEx($hKB_Hook)
    DllCallbackFree($hStub_KeyProc)

    GUIDelete($hwnd_Thumbnail)

    Opt("GUIOnEventMode", 0)

EndFunc   ;==>_exit

Func _check_GUI()

    If Not IsHWnd($hwnd_Thumbnail) Or Not IsHWnd($hwnd_Source) Then Return

    _check_GUI_Pos()

    If _WindowFromPoint() <> $hwnd_Thumbnail Then
        If $Big Then
            ;ConsoleWrite("_WinAPI_SetWindowLong: " & _WinAPI_SetWindowLong($hwnd_Thumbnail,$GWL_STYLE,$WS_POPUP) & @crlf)
            ;ConsoleWrite("_WinAPI_SetWindowLong: " & _WinAPI_SetWindowLong($hwnd_Thumbnail,$GWL_EXSTYLE,BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_CONTROLPARENT)) & @crlf)

            $iStep = $i_hwnd_Thumbnail_Height / 10
            For $i = $i_hwnd_Thumbnail_Height To $iZoomFactor_Small Step -$iStep
                _DWM_Thumbnail_Update_Properties($hThumbID, 0, 0, $i_hwnd_Thumbnail_Width * ($i / $i_hwnd_Thumbnail_Height), $i, 255, True, $iClientAreaOnly)
                WinMove($hwnd_Thumbnail, "", $aWinGetPos[0], $aWinGetPos[1], $i_hwnd_Thumbnail_Width * ($i / $i_hwnd_Thumbnail_Height), $i)
            Next
            _DWM_Thumbnail_Update_Properties($hThumbID, 0, 0, $i_hwnd_Thumbnail_Width * ($iZoomFactor_Small / $i_hwnd_Thumbnail_Height), $iZoomFactor_Small, 255, True, $iClientAreaOnly)
            WinMove($hwnd_Thumbnail, "", $aWinGetPos[0], $aWinGetPos[1], $i_hwnd_Thumbnail_Width * ($iZoomFactor_Small / $i_hwnd_Thumbnail_Height), $iZoomFactor_Small)
            $i_hwnd_Thumbnail_Height_Save = $i_hwnd_Thumbnail_Height
            $i_hwnd_Thumbnail_Width_Save = $i_hwnd_Thumbnail_Width
            $Big = False
        ElseIf $i_hwnd_Thumbnail_Height <> $i_hwnd_Thumbnail_Height_Save Or $i_hwnd_Thumbnail_Width <> $i_hwnd_Thumbnail_Width_Save Then ;source size changed
            _DWM_Thumbnail_Update_Properties($hThumbID, 0, 0, $i_hwnd_Thumbnail_Width * ($iZoomFactor_Small / $i_hwnd_Thumbnail_Height), $iZoomFactor_Small, 255, True, $iClientAreaOnly)
            WinMove($hwnd_Thumbnail, "", $aWinGetPos[0], $aWinGetPos[1], $i_hwnd_Thumbnail_Width * ($iZoomFactor_Small / $i_hwnd_Thumbnail_Height), $iZoomFactor_Small)
            $i_hwnd_Thumbnail_Height_Save = $i_hwnd_Thumbnail_Height
            $i_hwnd_Thumbnail_Width_Save = $i_hwnd_Thumbnail_Width
        EndIf
    Else
        If Not $Big Then
            ;ConsoleWrite("NB _WinAPI_SetWindowLong: " & _WinAPI_SetWindowLong($hwnd_Thumbnail,$GWL_STYLE,$GUI_SS_DEFAULT_GUI) & @crlf)
            ;ConsoleWrite("NB _WinAPI_SetWindowLong: " & _WinAPI_SetWindowLong($hwnd_Thumbnail,$GWL_EXSTYLE,BitOR($WS_EX_TOPMOST, $WS_EX_CONTROLPARENT)) & @crlf)

            $iStep = $i_hwnd_Thumbnail_Height / 10
            For $i = $iZoomFactor_Small To $i_hwnd_Thumbnail_Height Step $iStep
                _DWM_Thumbnail_Update_Properties($hThumbID, 0, 0, $i_hwnd_Thumbnail_Width * ($i / $i_hwnd_Thumbnail_Height), $i, 255, True, $iClientAreaOnly)
                WinMove($hwnd_Thumbnail, "", $aWinGetPos[0], $aWinGetPos[1], $i_hwnd_Thumbnail_Width * ($i / $i_hwnd_Thumbnail_Height), $i)
            Next
            _DWM_Thumbnail_Update_Properties($hThumbID, 0, 0, $i_hwnd_Thumbnail_Width, $i_hwnd_Thumbnail_Height, 255, True, $iClientAreaOnly)
            WinMove($hwnd_Thumbnail, "", $aWinGetPos[0], $aWinGetPos[1], $i_hwnd_Thumbnail_Width, $i_hwnd_Thumbnail_Height)
            $i_hwnd_Thumbnail_Height_Save = $i_hwnd_Thumbnail_Height
            $i_hwnd_Thumbnail_Width_Save = $i_hwnd_Thumbnail_Width
            $Big = True
        ElseIf $i_hwnd_Thumbnail_Height <> $i_hwnd_Thumbnail_Height_Save Or $i_hwnd_Thumbnail_Width <> $i_hwnd_Thumbnail_Width_Save Then ;source size changed
            _DWM_Thumbnail_Update_Properties($hThumbID, 0, 0, $i_hwnd_Thumbnail_Width, $i_hwnd_Thumbnail_Height, 255, True, $iClientAreaOnly)
            WinMove($hwnd_Thumbnail, "", $aWinGetPos[0], $aWinGetPos[1], $i_hwnd_Thumbnail_Width, $i_hwnd_Thumbnail_Height)
            $i_hwnd_Thumbnail_Height_Save = $i_hwnd_Thumbnail_Height
            $i_hwnd_Thumbnail_Width_Save = $i_hwnd_Thumbnail_Width
        EndIf
    EndIf
EndFunc   ;==>_check_GUI

Func _check_GUI_Pos()

    $aWinGetPos = WinGetPos($hwnd_Thumbnail)
    $i_hwnd_Source_State = WinGetState($hwnd_Source, "")

    If BitAND($i_hwnd_Source_State, 2) And Not BitAND($i_hwnd_Source_State, 16) Then ; Update only if source is visible and not minimized
        _DwmQueryThumbnailSourceSize($hThumbID)
        $i_hwnd_Thumbnail_Width = $i_hwnd_Thumbnail_Width * $iZoomFactor_Large
        $i_hwnd_Thumbnail_Height = $i_hwnd_Thumbnail_Height * $iZoomFactor_Large
    ElseIf BitAND($i_hwnd_Source_State, 16) Then
        WinSetState($hwnd_Source, "", @SW_SHOWNOACTIVATE)
    EndIf

EndFunc   ;==>_check_GUI_Pos

Func _WindowFromPoint()
    ; from _GUICtrl_SetOnHover
    ; http://www.autoitscript.com/forum/index.ph...showtopic=55120
    ; by G.Sandler a.k.a MrCreatoR (CreatoR's Lab, http://creator-lab.ucoz.ru)

    ; x64 FIX! http://www.autoitscript.com/trac/autoit/ticket/1362
    ; http://www.autoitscript.com/forum/index.php?showtopic=77831&view=findpost&p=768190

    Local $Old_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $pt = DllStructCreate("long;long")
    Local $pt64 = DllStructCreate("int64", DllStructGetPtr($pt))
    DllStructSetData($pt, 1, MouseGetPos(0))
    DllStructSetData($pt, 2, MouseGetPos(1))
    Local $aRet = DllCall("User32.dll", "hwnd", "WindowFromPoint", _
            "int64", DllStructGetData($pt64, 1))
    ;$aRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $aRet[0])
    Opt("MouseCoordMode", $Old_Opt_MCM)
    Return $aRet[0]
EndFunc   ;==>_WindowFromPoint

Func _WindowDrag()
    DllCall("user32.dll", "int", "SendMessage", "hWnd", $hwnd_Thumbnail, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
EndFunc   ;==>_WindowDrag

Func _DWM_Thumbnail_Register($hwnd, $hWndOw)
    $aRet = DllCall("dwmapi.dll", "int", "DwmRegisterThumbnail", "hwnd", $hwnd, "hwnd", $hWndOw, "ptr*", 0)
    If Not IsArray($aRet) Then Return SetError(1, 0, 0); Register thumbnail failed
    Return $aRet[3]
EndFunc   ;==>_DWM_Thumbnail_Register

Func _DWM_Thumbnail_Unregister($hThumbID)
    $aRet = DllCall("dwmapi.dll", "int", "DwmUnregisterThumbnail", "hwnd", $hThumbID)
    If Not IsArray($aRet) Then Return SetError(1, 0, 0); Unregister thumbnail failed
    Return $aRet[0]
EndFunc   ;==>_DWM_Thumbnail_Unregister

Func _DWM_Thumbnail_Update_Properties($hThumbID, $rcDest_X, $rcDest_Y, $rcDest_Width, $rcDest_Height, $rcOpacity = 255, $rcReadOnly = True, $rcClientAreaOnly = 0)
    $tDWM_THUMBNAIL_PROPERTIES = DllStructCreate("dword dwFlags;int rcDestination[4];int rcSource[4];byte opacity;int fVisible;int fSourceClientAreaOnly")

    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "dwFlags", BitOR($DWM_TNP_RECTDESTINATION, $DWM_TNP_OPACITY, $DWM_TNP_VISIBLE, $DWM_TNP_SOURCECLIENTAREAONLY))
    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_X, 1)
    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_Y, 2)
    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_Width, 3)
    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "rcDestination", $rcDest_Height, 4)
    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "opacity", $rcOpacity)
    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "fVisible", $rcReadOnly)
    DllStructSetData($tDWM_THUMBNAIL_PROPERTIES, "fSourceClientAreaOnly", $rcClientAreaOnly)

    $pDWM_THUMBNAIL_PROPERTIES = DllStructGetPtr($tDWM_THUMBNAIL_PROPERTIES)

    $aRet = DllCall("dwmapi.dll", "int", "DwmUpdateThumbnailProperties", "ptr", $hThumbID, "ptr", $pDWM_THUMBNAIL_PROPERTIES)
    If Not IsArray($aRet) Then Return SetError(1, 0, 0); Update thumbnail failed
EndFunc   ;==>_DWM_Thumbnail_Update_Properties


Func _Mouse_Proc($nCode, $wParam, $lParam)
    ;$mouseData = DllStructGetData(DllStructCreate("int X;int Y" & ";dword mouseData", $lParam), 3)
    ;If $wParam = 0x020A Then $mouseEvent = BitShift($mouseData, 16)
    ; ConsoleWrite($nCode & @tab & $wParam & @tab & $lParam & @CRLF)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hMO_Hook, $nCode, $wParam, $lParam)
    EndIf

    If $wParam = 0x00000201 Then
        If TimerDiff($tTimer_Doubleclick) < 500 Then
            WinSetState($hwnd_Source, "", @SW_SHOW)
            WinSetOnTop($hwnd_Source, "", 1)
            WinSetOnTop($hwnd_Source, "", 0)
        EndIf
        If _WindowFromPoint() = $hwnd_Thumbnail Then $tTimer_Doubleclick = TimerInit()
    EndIf
    Return _WinAPI_CallNextHookEx($hMO_Hook, $nCode, $wParam, $lParam)
EndFunc   ;==>_Mouse_Proc

Func _Key_Proc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hKB_Hook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN And DllStructGetData($tKEYHOOKS, "vkCode") = 27 And _WindowFromPoint() = $hwnd_Thumbnail Then $bExitPreview = True ; ConsoleWrite("ESC pressed" & @crlf)
    Return _WinAPI_CallNextHookEx($hKB_Hook, $nCode, $wParam, $lParam)
EndFunc   ;==>_Key_Proc

; #FUNCTION# =======================================================
; Name...........:  _WinGetPosEx
; Description ...:  Retrieves Window size and position similar to WinGetPos() but regards possible Aero effects on Vista and Win7
; Syntax.........:  _WinGetPosEx($hWnd)
; Parameters ....:  $hWnd - Handle to Window to measure
; Return values .:  Success:    Returns a 4-element array containing the following information:
;                               $array[0] = X position
;                               $array[1] = Y position
;                               $array[2] = Width
;                               $array[3] = Height
;                       Sets @extended  = 0 for Aero effect is OFF for $hWnd
;                                       = 1 for Aero effect is ON for $hWnd
;
;                   Failure:    Returns 0 and sets @error to 1 if windows is not found.
; Author ........: KaFu
; Link ..........; http://msdn.microsoft.com/en-us/library/aa969515%28VS.85%29.aspx
; Example .......; Yes
; ==================================================================
Func _WinGetPosEx($hwnd)
    If Not IsHWnd($hwnd) Then Return SetError(1, 0, 0)
    Local $aPos[4], $tRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
    Local Const $DWMWA_EXTENDED_FRAME_BOUNDS = 9
    DllCall("dwmapi.dll", "hwnd", "DwmGetWindowAttribute", "hwnd", WinGetHandle($hwnd), "dword", $DWMWA_EXTENDED_FRAME_BOUNDS, "ptr", DllStructGetPtr($tRect), "dword", DllStructGetSize($tRect))
    If @error Then Return SetError(0, 0, WinGetPos($hwnd))
    Local $iRectLeft = DllStructGetData($tRect, "Left")
    Local $iRectTop = DllStructGetData($tRect, "Top")
    Local $iRectRight = DllStructGetData($tRect, "Right")
    Local $iRectBottom = DllStructGetData($tRect, "Bottom")
    If Abs($iRectLeft) + Abs($iRectTop) + Abs($iRectRight) + Abs($iRectBottom) > 0 Then
        $aPos[0] = $iRectLeft
        $aPos[1] = $iRectTop
        $aPos[2] = $iRectRight - $iRectLeft
        $aPos[3] = $iRectBottom - $iRectTop
        Return SetError(0, 1, $aPos)
    EndIf
    Return SetError(0, 0, WinGetPos($hwnd))
EndFunc   ;==>_WinGetPosEx


Func _DwmQueryThumbnailSourceSize($hThumbID)
    #cs
        http://msdn.microsoft.com/en-us/library/aa969520%28VS.85%29.aspx
        HRESULT DwmQueryThumbnailSourceSize(
        HTHUMBNAIL hThumbnail,
        PSIZE pSize
        );
        typedef struct tagSIZE {
        LONG cx;
        LONG cy;
        }SIZE, *PSIZE;
    #ce

    $tSize = DllStructCreate("int X;int Y")
    $aRet = DllCall("dwmapi.dll", "hwnd", "DwmQueryThumbnailSourceSize", "hwnd", $hThumbID, "ptr", DllStructGetPtr($tSize))
    If $aRet[0] = $S_OK Then
        $i_hwnd_Thumbnail_Width = DllStructGetData($tSize, 1)
        $i_hwnd_Thumbnail_Height = DllStructGetData($tSize, 2)
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_DwmQueryThumbnailSourceSize
Edited by KaFu

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0