Function Reference


_WinAPI_DwmSetIconicLivePreviewBitmap

Sets a static, iconic bitmap to display a live preview (also known as a Peek preview) of a window or tab

#include <WinAPIGdi.au3>
_WinAPI_DwmSetIconicLivePreviewBitmap ( $hWnd, $hBitmap [, $bFrame = False [, $tClient = 0]] )

Parameters

$hWnd Handle to the window or tab.
$hBitmap Handle to the device-independent bitmap (DIB) to represent the specified window.
$bFrame [optional] Specifies whether display a frame around the provided bitmap, valid values:
    True - Display frame.
    False - Do not display frame (Default).
$tClient [optional] $tagPOINT structure that contains The offset of a tab window's client region from the host window's frame.
This offset enables the tab window's contents to be drawn correctly in a live preview when it is drawn without its frame.

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero, @extended flag may contain the HRESULT error code.

Remarks

A window typically calls the _WinAPI_DwmSetIconicLivePreviewBitmap() function in response to a WM_DWMSENDICONICLIVEPREVIEWBITMAP message.
The returned bitmap must not be larger than the client area of the window or frame and must have 32-bit color depth.

The DWM uses a copy of the bitmap, but the caller retains ownership of the original bitmap and is responsible for freeing the resources that it uses when it is no longer needed.
The DWM does not keep its copy of the bitmap when the DWM stops displaying the live preview representation.

This function requires Windows 7 or later.

See Also

Search DwmSetIconicLivePreviewBitmap in MSDN Library.

Example

#include <APIGdiConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIConv.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPIRes.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

If (Number(_WinAPI_GetVersion()) < 6.1) Or (Not _WinAPI_DwmIsCompositionEnabled()) Then
        MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Require Windows 7 or later with enabled Aero theme.')
        Exit
EndIf

; Load bitmap to create a thumbnail
Global $g_hAutoIt = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\AutoIt.bmp', $IMAGE_BITMAP, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION))

; Create GUI
Global $g_hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400)

; Set DWM window attributes to provide the iconic bitmap, and to always render the thumbnail and live preview using the iconic bitmap
_WinAPI_DwmSetWindowAttribute($g_hForm, $DWMWA_FORCE_ICONIC_REPRESENTATION, 1)
_WinAPI_DwmSetWindowAttribute($g_hForm, $DWMWA_HAS_ICONIC_BITMAP, 1)

; Register WM_DWMSENDICONICLIVEPREVIEWBITMAP window message to display live preview
GUIRegisterMsg($WM_DWMSENDICONICLIVEPREVIEWBITMAP, 'WM_DWMSENDICONICLIVEPREVIEWBITMAP')

; Register WM_DWMSENDICONICTHUMBNAIL window message to display thumbnail
GUIRegisterMsg($WM_DWMSENDICONICTHUMBNAIL, 'WM_DWMSENDICONICTHUMBNAIL')

GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _CreateThumbnail($hSource, $iWidth, $iHeight)
        Local $hBitmap = _WinAPI_CreateDIB($iWidth, $iHeight)
        Local $hDestDC = _WinAPI_CreateCompatibleDC(0)
        Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
        Local $tSIZE = _WinAPI_GetBitmapDimension($hSource)
        Local $hSrcDC = _WinAPI_CreateCompatibleDC(0)
        Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hSource)
        _WinAPI_SetStretchBltMode($hDestDC, $HALFTONE)
        _WinAPI_StretchBlt($hDestDC, 0, 0, $iWidth, $iHeight, $hSrcDC, 0, 0, DllStructGetData($tSIZE, 'X'), DllStructGetData($tSIZE, 'Y'), $SRCCOPY)
        _WinAPI_SelectObject($hDestDC, $hDestSv)
        _WinAPI_DeleteDC($hDestDC)
        _WinAPI_SelectObject($hSrcDC, $hSrcSv)
        _WinAPI_DeleteDC($hSrcDC)
        Return $hBitmap
EndFunc   ;==>_CreateThumbnail

Func WM_DWMSENDICONICLIVEPREVIEWBITMAP($hWnd, $iMsg, $wParam, $lParam)
        #forceref $iMsg, $wParam, $lParam

        Switch $hWnd
                Case $g_hForm
                        Local $hBitmap = _CreateThumbnail($g_hAutoIt, 400, 400)
                        _WinAPI_DwmSetIconicLivePreviewBitmap($g_hForm, $hBitmap, 1)
                        _WinAPI_DeleteObject($hBitmap)
                        Return 0
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DWMSENDICONICLIVEPREVIEWBITMAP

Func WM_DWMSENDICONICTHUMBNAIL($hWnd, $iMsg, $wParam, $lParam)
        #forceref $iMsg, $wParam

        Switch $hWnd
                Case $g_hForm
                        Local $W, $H, $hBitmap

                        $W = _WinAPI_HiWord($lParam)
                        $H = _WinAPI_LoWord($lParam)
                        If $W > $H Then
                                $W = $H
                        Else
                                $H = $W
                        EndIf
                        $hBitmap = _CreateThumbnail($g_hAutoIt, $W, $H)
                        _WinAPI_DwmSetIconicThumbnail($g_hForm, $hBitmap, 1)
                        _WinAPI_DeleteObject($hBitmap)
                        Return 0
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DWMSENDICONICTHUMBNAIL