Setting the initial position of a dialog-based application

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.


void CAppDlg::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if (lpwndpos->cx = -1)
if (lpwndpos->cy = -1) // is init time
{
lpwndpos->x = 0; // change here if you want to move left or right the window.
lpwndpos->y = 0; // change here if you want to move top or bottom the window.
}
CDialog::OnWindowPosChanging(lpwndpos);
}

Explanation

After CreateDialogIndirect, the MFC call CenterWindow. The last line of this function call SetWindowPos with position of window, and with -1, -1, as width and height of window. So the WM_WINDOWPOSCHANGING is obviously.

Date Last Updated: April 19, 1999

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read