How do I get the effect of CW_USEDEFAULT positioning on a window I've already created?

Raymond Chen

A customer wanted to know how to get the effect of CW_USE­DEFAULT positioning on a window that already exists. In particular, they wanted to be able to reposition a dialog box to get the CW_USE­DEFAULT cascade effect, but since you can’t actually pass CW_USE­DEFAULT in a dialog template, the repositioning has to be done after the fact. (Presumably in the WM_INIT­DIALOG handler, which runs before the dialog is visible, so that there is no visible flicker.)

The solution here is simple: Create a temporary invisible window with CW_USE­DEFAULT as its position and the same height and width as your dialog box. See where the window manager puts that temporary window and move your dialog box to match that position. Then destroy the temporary window.