对话框可以放工具条吗?

xiepoora 2003-04-09 08:33:18
对话框可以放工具条吗?

我建了一个无模态对话框,想在它的底下放一个工具条。行吗?
...全文
82 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ripyu 2003-04-10
  • 打赏
  • 举报
回复
可以
chinaqianhu 2003-04-10
  • 打赏
  • 举报
回复
你查查MSDN的例子,
有一个例子教你如何在对话框里加菜单,工具栏和状态栏!
pcman1990 2003-04-10
  • 打赏
  • 举报
回复
VCKBASE中的一篇文章:

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);

xiepoora 2003-04-10
  • 打赏
  • 举报
回复
我按这种方法建了,怎么显示不出来我建的工具条呢?
GoogleGeek 2003-04-10
  • 打赏
  • 举报
回复
怎么会显示不出来??
你有没有WS_VISIBLE风格??
GoogleGeek 2003-04-09
  • 打赏
  • 举报
回复

in class head file
private:
CToolBar m_wndToolBar1;
...

// in cpp file
BOOL CDialogMenuToolBarDlg::OnInitDialog()
{
....
// Set small icon

if (!m_wndToolBar1.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar1.LoadToolBar(IDR_TOOLBAR_DIALOG))
{
TRACE0("Failed to create toolbar\n");
EndDialog(IDCANCEL);// fail to create
}

//repostion the toolbar
this->RecalToolBarPos(this);
...

return TRUE; // return TRUE unless you set the focus to a control
}

void CDialogMenuToolBarDlg::RecalToolBarPos(CDialog *pParentWnd)
{
ASSERT(pParentWnd!=NULL);
ASSERT(pParentWnd->IsKindOf(RUNTIME_CLASS(CDialog)));

CRect rectClientStart;
CRect rectClientNow;
//make the rectClientStart bigger than rectClientNow
pParentWnd->GetClientRect(rectClientStart);
pParentWnd->RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rectClientNow);

//shift the position of all the control
CPoint ptOffset(rectClientNow.left-rectClientStart.left,rectClientNow.top-rectClientStart.top);
CRect rectChild;
CWnd *pWndChild=pParentWnd->GetWindow(GW_CHILD);
while(pWndChild)
{
pWndChild->GetWindowRect(rectChild);
pParentWnd->ScreenToClient(rectChild);
rectChild.OffsetRect(ptOffset);
pWndChild->MoveWindow(rectChild,false);
pWndChild=pWndChild->GetNextWindow();
}

//enlarge the size of the dialog
CRect rectWindow;
pParentWnd->GetWindowRect(rectWindow);
rectWindow.right+=rectClientStart.Width()-rectClientNow.Width();
rectWindow.bottom+=rectClientStart.Height()-rectClientNow.Height();
pParentWnd->MoveWindow(rectWindow,false);

//set the proper postion of the toolbar!
pParentWnd->RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
pParentWnd->CenterWindow();

}
GoogleGeek 2003-04-09
  • 打赏
  • 举报
回复
of course!!
you can ...
xiepoora 2003-04-09
  • 打赏
  • 举报
回复
能否详细些?
edwardsoft 2003-04-09
  • 打赏
  • 举报
回复
可以的,你只要自己动态创建就可以了,按钮id可以自己加,消息函数自己写。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧