簡體   English   中英

如何在啟動時居中MFC MDI應用程序?

[英]How can I center an MFC MDI application at startup?

我正在使用舊的MFC(VC 6)應用程序,該應用程序在啟動時需要進行修改以在屏幕上垂直和水平居中。 我已經嘗試在主框架OnCreate調用中使用對CenterWindow的調用,但這似乎無濟於事。 任何幫助將不勝感激。

在InitInstance()上是m_pMainWnd-> CenterWindow()?

左=(ScreenWidth-WindowWidth)/ 2頂部=(ScreenHeight-WIndowHeight)/ 2

我有一個MDI應用程序,它在啟動時在Application類的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;
}

希望對您有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM