dialog中使用toolbar 闻怡洋 译 homepage: http://vchelp.zb169.net mfc中没有提供供对话框使用的工具条类,而我们时常需要开发以对话框为框架的程序。下面我使用简单的代码说明这种方法。 step1: 在资源编辑器中插入工具条资源,并为每个按钮创建id。将它命名为idc_toolbar1 step2: 在对话框变量中添加一个工具条变量。 ctoolbar m_wndtoolbar; step3: 在cdialog::oninitdialog中添加如下代码: // 创建工具条并调入资源 if(!m_wndtoolbar.create(this) || !m_wndtoolbar.loadtoolbar(idr_toolbar1)) { trace0("failed to create dialog toolbar/n"); enddialog(idcancel); } 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); |
dialog中使用toolbar
最新推荐文章于 2021-05-10 15:19:20 发布