RSS
热门关键字:
当前位置 : 主页>嵌入式开发>VxWorks>列表

Dialog中使用Toolbar

来源:我要研发网 作者: 时间:1970-01-01 点击:



FC中没有提供供对话框使用工具条类,而我们时常需要开发以对话框为框架程序。下面我使用简单代码说明这种方法。

  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 字串1
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, 字串1
rcClientNew.top-rcClientOld.top);

CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD); //得到子窗口
while(pwndChild) // 处理所有子窗口
{//移动所有子窗口
pwndChild-$#@62;GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild-$#@62;MoveWindow(rcChild,FALSE);
pwndChild = pwndChild-$#@62;GetNextWindow();
}

CRect rcWindow;
GetWindowRect(rcWindow); // 得到对话框RECT
rcWindow.right = rcClientOld.Width() - lientNew.Width(); // 修改对话框尺寸
rcWindow.bottom = rcClientOld.Height() - rcClientNew.Height();
MoveWindow(rcWindow,FALSE); // Redraw Window

RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
相关文章