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

  • 相关阅读:
    DELPHI给整个项目加编译开关
    TThread.Queue和TThread.Synchronize的区别
    中文分词 《第七篇》
    搜索结果的处理和显示《第六篇》
    高级搜索 《第五篇》
    索引管理 《第四篇》
    执行搜索 《第三篇》
    构建索引 《第二篇》
    Lucene.net 基本示例 《第一篇》
    通过配置的方式Autofac 《第三篇》
  • 原文地址:https://www.cnblogs.com/xingrun/p/3410187.html
Copyright © 2011-2022 走看看