tags:

views:

77

answers:

3

I am working with a legacy MFC (VC 6) application that needs to be modified to be centered vertically and horizontally on the screen at startup. I have tried using the call to CenterWindow in the main frame OnCreate call, but that doesn't appear to do anything. Any help would be greatly appreciated.

A: 

left = (ScreenWidth-WindowWidth) /2 top = (ScreenHeight-WIndowHeight) / 2

No Refunds No Returns
A: 

I have an MDI application which does the positioning at startup in InitInstance of the Application class. (I remember having read that OnCreate of the main frame is indeed the wrong place, but I don't know anymore where I've read that ... long time ago) I try to strip out the relevant parts here:

BOOL CMyApp::InitInstance()
{
    // stuff...

    CMyMainFrame* pMyMainFrame=CreateMainFrame();
    if (!pMyMainFrame)
        return FALSE;
    m_pMainWnd = pMyMainFrame;

    // stuff...

    if (!ProcessShellCommand(cmdInfo))
        return FALSE;

    int nCmdShow=SW_NORMAL;
    UINT flags=WPF_SETMINPOSITION;
    WINDOWPLACEMENT aWndPlacement;
    CRect rect;

    // determine the desired rect of the application window

    aWndPlacement.length=sizeof(WINDOWPLACEMENT);
    aWndPlacement.showCmd=nCmdShow;
    aWndPlacement.flags=flags;
    aWndPlacement.ptMinPosition=CPoint(0,0);
    aWndPlacement.ptMaxPosition=CPoint(-::GetSystemMetrics(SM_CXBORDER),
                                       -::GetSystemMetrics(SM_CYBORDER));
    aWndPlacement.rcNormalPosition=rect;
    m_pMainWnd->SetWindowPlacement(&aWndPlacement);
    m_nCmdShow=nCmdShow;

    pMyMainFrame->ShowWindow(m_nCmdShow);
    pMyMainFrame->UpdateWindow();

    return TRUE;
}

I hope that works for you.

Slauma
A: 

m_pMainWnd->CenterWindow() on InitInstance()?

Roel
Yup - that did it! Thanks so much.
pFilicetti