文档/视图下主窗口屏幕居中

在CWinApp类的InitInstance()中添加如下代码

 RECT rc;
 ::GetWindowRect( m_pMainWnd->m_hWnd, &rc );
 ::SetWindowPos( m_pMainWnd->m_hWnd, HWND_TOP,
  ( GetSystemMetrics( SM_CXSCREEN ) - ( rc.right - rc.left ) ) / 2,
  ( GetSystemMetrics( SM_CYSCREEN ) - ( rc.bottom - rc.top ) ) / 2,
  rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW );

posted @ 2009-11-08 03:27  冷寒生  阅读(220)  评论(0编辑  收藏  举报
IT知识库