How do I get the effect of CW_USEDEFAULT positioning on a window I've already created?
A customer wanted to know how to get the effect of
CW_USEDEFAULT positioning on a window that already exists. In particular, they wanted to be able to reposition a dialog box to get the
CW_USEDEFAULT cascade effect, but since you can’t actually pass
CW_USEDEFAULT in a dialog template, the repositioning has to be done after the fact. (Presumably in the
WM_INITDIALOG 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_USEDEFAULT 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.