How to use DwmSetIconicThumbnail with thumbnails smaller than the maximum width?

  Kiến thức lập trình

If the DwmSetIconicThumbnail method is called with a bitmap having the exact width and height values given by the WM_DWMSENDICONICTHUMBNAIL message, the taskbar thumbnail is shown with the appropriate size. If the bitmap passed to DwmSetIconicThumbnail method has a smaller width than the maximum allowed width, the taskbar thumbnail is shown stretched to the maximum width provided by the WM_DWMSENDICONICTHUMBNAIL message. If the taskbar button is hovered a second time, the thumbnail is shown with the correct width.

I expect the size of the taskbar thumbnail to be correct already during the first mouse over.

Is this a windows bug? If yes, can it be circumvented?

I have tried to call DwmSetIconicThumbnail a second time using the same bitmap. But it does not fix the problem.

Reproduction:

Download and install the TabThumbnail Visual Studio sample project:

https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/winui/shell/appshellintegration/TabThumbnails

Add the following code at the beginning of the _CreateDIB(int,int) method in TabWnd.cpp to decrease the target width of the thumbnail:

nWidth /= 2;

Compile and run the sample app.

First time mouse over
Second time mouse over

New contributor

matthias is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT