对话框中工具栏,状态栏随对话框变化而变化

添加窗体的Onsize事件:
void CStatusbartestDlg::OnSize(UINT nType, int cx, int cy)
{
 CDialog::OnSize(nType, cx, cy);
 
 // TODO: Add your message handler code here
 CRect   rectMain;  
    CPaintDC   dc(this);  
    this->GetClientRect(rectMain);
 CRect rectBar;

 CToolBar *pToolBar = (CToolBar *)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_TOOLBAR);
 if(pToolBar != NULL)
 {
  
  pToolBar->GetClientRect(&rectBar);  
  pToolBar->MoveWindow(0,0,rectMain.Width(),rectBar.Height()+9);
  CWnd *pStaticToolBar = GetDlgItem(IDC_STATIC_ToolBar);//IDC_STATIC_ToolBar为picture控件,模拟工具栏的分隔条
  if(pStaticToolBar != NULL)
  {
   
   pToolBar->GetClientRect(&rectBar); 
   pStaticToolBar->MoveWindow(0,rectBar.Height()+10,rectMain.Width(),2);
   pStaticToolBar->ShowWindow(SW_SHOW);
  }
 }

 CStatusBarCtrl *pStatusBar = (CStatusBarCtrl *)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);//取得窗口指针
    if(pStatusBar != NULL)
 {
 
  pStatusBar->GetClientRect(&rectBar);
  pStatusBar->MoveWindow(0,cy-rectBar.Height(),rectMain.Width(),rectBar.Height());
  pStatusBar->GetClientRect(&rectBar);
  int nParts[4]= {rectMain.Width()/rectBar.Width()*100, rectMain.Width()/rectBar.Width()*200, rectMain.Width()/rectBar.Width()*400,-1};      //分割尺寸
  pStatusBar->SetParts(4, nParts);  //分割状态栏
  CWnd *pStaticBar = GetDlgItem(IDC_STATIC_BAR);//picture控件ID
  if(pStaticBar != NULL)
  {
   pStaticBar->MoveWindow(0,rectMain.Height() - rectBar.Height()-1,rectMain.Width(),2);
   pStaticBar->ShowWindow(SW_SHOW);
  }
  
  //绘制背景色  
     dc.FillSolidRect(rectMain,RGB(255,255,255));     //设置为白色 
 }
 
}

posted on 2009-05-22 15:32 小猪 阅读(529) 评论(0)  编辑 收藏 引用 所属分类: VC++


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


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜