当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: rt ......
    摘要: knight94(愚翁) ---------------------------- 改进的方法,修改main,例如: [stathread] static void main() { form1 myform1=new form1(); myform1.showdialog(); form2 myform2=new form2();//还可以加入标志,来决定是否创建form2 my......


关于在dialog上加toolbar

我想再对话框上加一个工具栏,  
  按msdn上说的作了一个toolbar   resource,id=IDR_TOOLBAR1  
  在initdialog()中create,load   toolbar:  
  if   (!m_ToolBar.CreateEx(this,   TBSTYLE_FLAT,   WS_CHILD   |   WS_VISIBLE   |   CBRS_TOP  
  |   CBRS_GRIPPER   |   CBRS_TOOLTIPS   |   CBRS_FLYBY   |   CBRS_SIZE_DYNAMIC)   ||  
  !m_ToolBar.LoadToolBar(IDR_TOOLBAR1))  
  {  
  TRACE0("Failed   to   create   toolbar\n");  
  return   -1;             //   fail   to   create  
  }  
   
  请问哪里不对了?为什么看不到工具栏?

NO.1   作者: free_card

http://www.vckbase.com/document/viewdoc.asp?id=265

NO.2   作者: feiniaoliang

后面加两句:  
  m_ToolBar.ShowWindow(SW_SHOW);  
  RepositionBars(AFX_IDW_CONTROLBAR_FIRST,   AFX_IDW_CONTROLBAR_LAST,   0);

NO.3   作者: shineryu

 
  MFC中没有提供供对话框使用的工具条类。  
  简单介绍  
  step1:  
  在资源编辑器中插入工具条资源,并为每个按钮创建ID。将它命名为IDC_TOOLBAR1  
  step2:  
  在对话框变量中添加一个工具条变量。  
  CToolBar   m_wndToolBar;  
  step3:  
  在CDialog::OnInitDialog中添加如下代码:  
  //创建工具条并调入资源  
  if(!m_wndToolBar.Create(this)||!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))  
  {  
  TRACE0("FailedtoCreateDialogToolbar\n");  
  EndDialog(IDCANCEL);  
  }  
  CRect rcClientOld;//旧客户区RECT  
  CRect rcClientNew;//加入TOOLBAR后的CLIENTRECT  
  GetClientRect(rcClientOld);//Calledtorepositionandresizecontrolbars //intheclientareaofawindow  
  //ThereposQueryFLAGdoesnotreallytrawthe //Toolbar.Itonlydoesthecalculations.  
  //AndputsthenewClientRectvaluesin //rcClientNewsowecandotherestoftheMath.  
  //重新计算RECT大小  
  RepositionBars(AFX_IDW_CONTROLBAR_FIRST,  
  AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);  
  //AlloftheChildWindows(Controls)nowneedtobemovedsotheTollbar //doesnotcoverthemup.  
  //所有的子窗口将被移动,以免被TOOLBAR覆盖  
  //OffesttomoveallchildcontrolsafteraddingTollbar  
  //计算移动的距离  
  CPointptOffset(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);//RedrawWindow  
  RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);  
 


    摘要: 例如:程序a设置了互斥信号量来阻止运行多个自身,我如何通过b程序(自己写的)来改变a程序中的互斥信号量呢?也就是说,可以设计一个b程序,运行此程序后改变了互斥量然后在调用a程序.已知信号量abcdefg.如何写这个b程序呢?最好给出代码(主要是改变互斥信号量的代码),谢谢! ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE