在对话框中增加菜单栏,工具栏,状态栏

1.加菜单:  
  在对话框的property对话框中style中选中system   menu  
  再在property对话框中generic中加入菜单

 

 

 

2.加工具栏

 

1。要增加一个资源IDR_TOOLBAR1

2.记得加一个成员变量     protected:  CToolBar   m_wndToolBar

3.

BOOL CMain::OnInitDialog()
{
 CDialog::OnInitDialog();
// TODO: Add extra initialization here 

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
 {
  TRACE0("Failed to create toolbar/n");
  return -1;      // fail to create
 }
 
 
 CRect rcClientOld;   //   久客户区RECT  
 CRect rcClientNew;   //   加入TOOLBAR后的CLIENT   RECT  
 GetClientRect(rcClientOld);   //    
 //   Called   to   reposition   and   resize   control   bars   in   the   client   area   of   a   window  
 //   The   reposQuery   FLAG   does   not   really   traw   the   Toolbar.     It   only   does   the   calculations.  
 //   And   puts   the   new   ClientRect   values   in   rcClientNew   so   we   can   do   the   rest   of   the   Math.  
 //重新计算RECT大小  
 RepositionBars(AFX_IDW_CONTROLBAR_FIRST,  
  AFX_IDW_CONTROLBAR_LAST,  
  0,  
  reposQuery,  
  rcClientNew);  
   
 //   All   of   the   Child   Windows   (Controls)   now   need   to   be   moved   so   the   Tollbar   does   not   cover   them   up.  
 //所有的子窗口将被移动,以免被TOOLBAR覆盖  
 //   Offest   to   move   all   child   controls   after   adding   Tollbar  
 //计算移动的距离  
 CPoint   ptOffset(rcClientNew.left-rcClientOld.left,  
  rcClientNew.top-rcClientOld.top);  
   
 CRect rcChild;  
 CWnd* pwndChild   =   GetWindow(GW_CHILD);     //得到子窗口  
 while(pwndChild)   //   处理所有子窗口  
 {//移动所有子窗口  
  pwndChild->GetWindowRect(rcChild);  
  ScreenToClient(rcChild);    
  rcChild.OffsetRect(ptOffset);    
  pwndChild->MoveWindow(rcChild,FALSE);    
  pwndChild   =   pwndChild->GetNextWindow();  
 }  
   
 CRect rcWindow;  
 GetWindowRect(rcWindow);   //   得到对话框RECT  
 rcWindow.right   +=   rcClientOld.Width()   -   rcClientNew.Width();   //   修改对话框尺寸  
 rcWindow.bottom   +=   rcClientOld.Height()   -   rcClientNew.Height();    
 MoveWindow(rcWindow,FALSE);   //   Redraw   Window  
   
 RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);  

 

 

加状态栏 

1.为所加的对话框类加入成员变量         protected:       HWND    m_hStatusWindow  

 

//调用API函数创建状态栏  
  BOOL CMain::OnInitDialog()
{
 CDialog::OnInitDialog();
// TODO: Add extra initialization here 
    m_hStatusWindow   =   CreateStatusWindow(WS_CHILD   |   WS_VISIBLE   |   WS_BORDER,   //风格  
  NULL,   //显示在状态栏上的信息  
  GetSafeHwnd(),   //父窗口句柄  
  100);   //的资源ID  
   
    UINT   indicators[]   =   {540,   830,   920,   -1};   //设定间隔  
    ::SendMessage(m_hStatusWindow,   SB_SETPARTS,   sizeof(indicators)   /   sizeof(UINT),   (LPARAM)indicators);  
 ::SendMessage(m_hStatusWindow,   SB_SETTEXT,   0,   (LPARAM)TEXT("Author:TH"));  
 ::SendMessage(m_hStatusWindow,   SB_SETTEXT,   1,   (LPARAM)TEXT("X"));    
    ::SendMessage(m_hStatusWindow,   SB_SETTEXT,   2,   (LPARAM)TEXT("Y")); 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值