Setting the initial position of a dialog-based application


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

Must Read