简体   繁体   中英

DWM Thumbnail, change size of preview window

I have window, which mirrors some another window with DWM thumbnails. Now I want when user resizes the preview window, than the preview area is resized to. How can I do this? How can I send update about new size of preview (change size 300x300 to size of preview window)?

switch (message) {
case WM_CREATE:
    {
        HRESULT hr = S_OK;
        HTHUMBNAIL thumbnail = NULL;
        hr = DwmRegisterThumbnail(hWnd, ieWindowHwnd, &thumbnail);
        if (SUCCEEDED(hr)) {
            // The destination rectangle size
            RECT dest = {0,0,300,300};

            // Set the thumbnail properties for use
            DWM_THUMBNAIL_PROPERTIES dskThumbProps;
            dskThumbProps.dwFlags = DWM_TNP_RECTDESTINATION | DWM_TNP_VISIBLE | DWM_TNP_SOURCECLIENTAREAONLY;

            // Use the window frame and client area
            dskThumbProps.fSourceClientAreaOnly = FALSE;
            dskThumbProps.fVisible = TRUE;
            dskThumbProps.rcDestination = dest;

            // Display the thumbnail
            hr = DwmUpdateThumbnailProperties(thumbnail, &dskThumbProps);
        }
    }
    break;
case WM_SIZE:
    {
        // What to do here.
    }
    break;

Remove thumbnail declaration from WM_CREATE , declare it as static value in Window procedure. Then update the thumbnail in WM_SIZE .

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wp, LPARAM lp)
{
    static HTHUMBNAIL thumbnail = NULL;

    switch (message)
    {
    ...    
    case WM_SIZE:
    {
        if (thumbnail)
        {
            RECT rc;
            GetClientRect(hWnd, &rc);
            DWM_THUMBNAIL_PROPERTIES dskThumbProps;
            ...
            dskThumbProps.rcDestination = rc;
            DwmUpdateThumbnailProperties(thumbnail, &dskThumbProps);
        }
        break;
    }
}

Call DwmUnregisterThumbnail when finished.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM