力为的技术博客

联系 聚合 管理
  154 Posts :: 1 Stories :: 561 Comments :: 0 Trackbacks

对于MDI的MFC程序,在向导中可以设置子窗口启动时最大化,生成的代码如下:

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    
// TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs
    if!CMDIChildWnd::PreCreateWindow(cs) )
        
return FALSE;

    cs.style 
= WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
        
| FWS_ADDTOTITLE | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;

    
return TRUE;
}


但是,在运行至 CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)和CYourView::OnInitialUpdate()的时候并不能得到子窗口最大时的rect大小。可以通过GetClientRect检验。
此时可以用如下代码解决:

    WINDOWPLACEMENT winplacement;
    memset(
&winplacement, 0sizeof(winplacement));
    winplacement.length 
= sizeof(WINDOWPLACEMENT);
    winplacement.showCmd 
= SW_SHOWMAXIMIZED;
    SetWindowPlacement(
&winplacement);

 

MSDN:
Sets the show state and the normal (restored), minimized, and maximized positions for a window.

 
BOOL SetWindowPlacement(
   
const WINDOWPLACEMENT*lpwndpl 
); 
 


Parameters
lpwndpl
Points to a WINDOWPLACEMENT structure that specifies the 
new show state and positions.

Return Value
posted on 2007-06-20 22:47 力为 阅读(5459) 评论(0)  编辑 收藏 引用 所属分类: 3. VC&MFC&Qt

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理