WM_GETMINMAXINFO
is generated when maximize operation is about to begin and WM_SIZE
when maximize operation is finished.
WM_SIZE
is also generated when restore operation is finished.
But how to detect window restore operation is about to begin?
I need detect exact moment when window is about to restore , but not the moment when already restored. I am developing multithread DirectX
application. I render in dedicated secondary thread. When window is about to begin maximize or restore I need to change render back buffer size (DirectX Device
Reset
). I can resize back buffer only from main thread so I use Critical Sections
to sync with render thread. The problem is that I cant interrupt Present
operation in render thread and when maximize or restore operation is about to begin I wait until current Present
operation is finished and only then begin to resize (maximize / restore). If you change back buffer size too late (when maximize / restore operation is finished (WM_SIZE
message) you can notice old frame is drawn with wrong size (image is stretched).
Well, it is nice to see that someone is still ponder over such issues. This small things, like one-second image stretching when resizing, distinguish a professional looking application from bedroom coded one.
In my old code I found tricks that probably will be interesting to you. A first thing is that you can check
WM_SYSCOMMAND
:But the problem is that it don't catch maximize / restore events when user double-clicks titlebar.
So I found a little trick, when parse
WM_WINDOWPOSCHANGING
.First let's do a little fun research. We read docs here and here where we found that:
Because it is nearly impossible to debug events in common debugger (how would you test if debugger often changes z-order of window?), so for testing purposes we will make a little console app with
int main()
, where we initialize a window as usual (HINSTANCE we can get fromGetModuleHandle(0);
). So we have a console and a window at same time. In window procedure we catchWM_WINDOWPOSCHANGING
and print info, it will tell us, to console:See utility functions here.
When we played enough we can now make it useful:
I'm really not sure that is it a simplest or even is it right way to do this. But it works for now =) Also, I think your app dont'care what exactly happened: maximizing, restoration or resizing. It just cares if size has changed, so you need to resize your buffers / recreate swap chain etc...
Hope it helps! Happy coding!