zoukankan      html  css  js  c++  java
  • WIN32项目中MFC程序窗口居中

    //class CMainWindow : public CFrameWnd

    void CMainWindow::OnSize(UINT nType, int cx, int cy)
    {
        CFrameWnd::OnSize(nType, cx, cy);

        // TODO: 在此处添加消息处理程序代码
        // SIZE_RESTORED   Window has been resized, but neither SIZE_MINIMIZED nor SIZE_MAXIMIZED applies.
        if( nType == SIZE_RESTORED )
        {
            /* 获取屏幕大小 */
            int iScreenW = GetSystemMetrics( SM_CXSCREEN );
            int iScreenH = GetSystemMetrics( SM_CYSCREEN );

            /* 获取窗口大小 */
            RECT rcWindowRect;
            GetWindowRect( &rcWindowRect );

            int iWindowW = rcWindowRect.right - rcWindowRect.left;
            int iWindowH = rcWindowRect.bottom - rcWindowRect.top;

            /* 获取任务栏高度 */
            RECT rect;
            HWND hwndTaskbar;
            int iTaskbarH;
            hwndTaskbar = ::FindWindow(L"Shell_TrayWnd", 0);
            ::GetWindowRect(hwndTaskbar, &rect);
            iTaskbarH = rect.bottom - rect.top;

            int iLeft = (iScreenW - iWindowW ) / 2;
            int iTop = (iScreenH - iWindowH - iTaskbarH ) / 2;

            MoveWindow( iLeft, iTop, iWindowW, iWindowH, FALSE ); 
        }
    }

  • 相关阅读:
    D. Babaei and Birthday Cake--- Codeforces Round #343 (Div. 2)
    Vijos P1389婚礼上的小杉
    AIM Tech Round (Div. 2) C. Graph and String
    HDU 5627Clarke and MST
    bzoj 3332 旧试题
    codeforces 842C Ilya And The Tree
    codesforces 671D Roads in Yusland
    Travelling
    codeforces 606C Sorting Railway Cars
    codeforces 651C Watchmen
  • 原文地址:https://www.cnblogs.com/xingrun/p/3410187.html
Copyright © 2011-2022 走看看