请教 那高手会在对话框上放置工具栏。
我用vc生成一个对话框的应用, 请问如何在这个对话框中生成一个工具栏????谢谢!!!
我用vc生成一个对话框的应用, 请问如何在这个对话框中生成一个工具栏????谢谢!!!
解决方案 »
- opencv 高斯二维掩膜怎么转化成一维模版??
- 继续刻录光盘之USB
- 如何把窗口的标题栏去掉?
- VC++6.0 怎么老是死在Link....
- 急!请教兄弟们个问题,关于档案和户口的问题
- 来者有分,多线程中访问SQL中同一条记录,出现数据库异常问题?
- 怎样获得我的WAN IP(internet ip)?
- 请教:如何在整个桌面上编程隐藏鼠标显示?
- 诚交vc同行,qq=197575,好兄弟,往下传。
- RegisterServiceProcess 的问题,请高手帮忙!!!
- 期末考试终于考完了,高兴啊!!!为什么我只能给100分啊???
- FileOpenDlg 同时选中多个文件打开, 选定的文件数目有什么限制?
{
CDialog::OnInitDialog(); //初始化工具条
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_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// Create the toolbar. To understand the meaning of the styles used, you
CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart); // To reposition and resize the control bar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0, reposQuery, rcClientNow);
CPoint ptOffset(rcClientNow.left - rcClientStart.left,rcClientNow.top-rcClientStart.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);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE); // And position the control bars
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
//
/* for(int i = 0; i < m_wndToolBar.GetCount(); i++)
{
UINT id = m_wndToolBar.GetItemID(i);
CString s;
if(!s.LoadString(id))
continue;
int j=s.Find(_T('\n'));
if(j < 0) continue;
s=s.Right(s.GetLength()-j-1);
m_wndToolBar.SetButtonText(i,s);
} // Add drop-down arrow to File|New button
// m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
i=m_wndToolBar.CommandToIndex(ID_NODE_START);
UINT id,style;
int image;
m_wndToolBar.GetButtonInfo(i,id,style,image);
m_wndToolBar.SetButtonInfo(i,ID_NODE_START,TBSTYLE_BUTTON | TBSTYLE_DROPDOWN,image);
// Adjust sizes to include text CRect rect;
CRect rect;
m_wndToolBar.GetItemRect(0,&rect);
m_wndToolBar.SetSizes(rect.Size(),CSize(32,31));
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
先在对话框中放置一个STATIC空间,然后在这个静态控件的位置创建工具栏就可以了
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here 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); return TRUE; // return TRUE unless you set the focus to a control
}