How do I find out what size the window manager would have chosen for my window?

Raymond Chen

We saw some time ago how the window manager decides where to place a newly-created window if you pass the CW_USE­DEFAULT values when creating the window. But what if you want to filter the values first? If you pass an explicit upper left corner but pass CW_USE­DEFAULT for the width and height, then the bottom right corner will be down near the bottom right corner of the screen.

Given that your CW_USE­DEFAULT code is buggy, is there a way I can ask how big you would have made the window, so I can go in and fix your mistake? If I try to resize it after the fact, there’s an ugly flicker. I’m kind of disgusted that something this simple still doesn’t work after all these years. This is why Apple is eating your lunch. This code was obviously never tested because it doesn’t even work.

There appears to be some elevation of opinion to fact here, because the customer thinks that when you say “I will let you decide where to put the bottom right corner of the window”, and when the window manager decides to put the bottom right corner the window near the bottom right corner of the screen, then that is obviously a bug. Yeesh, if you don’t want to let the window manager choose the bottom right corner of the window, then don’t pass the value that says “I will let you choose the bottom right corner of the window.” Anyway, back to the original question.

If you want to get a peek at the coordinates the window manager chose when you said, “You go ahead and choose,” you can just create the window without the WS_VISIBLE flag. And then look at the rectangle, and if you don’t like it, resize your window while it is still hidden. When you’re finally happy: Show it.

0 comments

Discussion is closed.

Feedback usabilla icon