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

  • 相关阅读:
    KMP
    1. Android Studio阅读源码
    疑难杂症
    队列
    方法和数组
    基本语法
    MySQL数据库创建
    MySQL安装
    Python--爬虫之(斗图啦网站)图片爬取
    Linux网络编程之基础概念
  • 原文地址:https://www.cnblogs.com/xingrun/p/3410187.html
Copyright © 2011-2022 走看看