2010-03-03 60 views
0

我正在使用旧版MFC(VC 6)应用程序,该应用程序需要在启动时被修改为在屏幕上垂直和水平居中。我曾尝试在主框架OnCreate调用中使用对CenterWindow的调用,但似乎没有任何操作。任何帮助将不胜感激。如何在启动时将MFC MDI应用程序居中?

回答

1

m_pMainWnd-> CenterWindow()on InitInstance()?

+0

是的 - 它做到了!非常感谢。 – pFilicetti 2010-03-03 19:19:18

0

左=(屏​​幕宽度-WINDOWWIDTH)/ 2 顶部=(ScreenHeight-WINDOWHEIGHT)/ 2

0

我有一个MDI应用程序,它确实在启动时在应用程序类的InitInstance中的定位。 (我记得曾经读过主框架的OnCreate确实是错误的地方,但我不知道我在哪里读过......很久以前)我尝试去掉这里的相关部分:

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; 
} 

我希望这对你有用。

相关问题