// 加载菜单资源
newMenu.LoadMenu(IDR_MENU_DLG); //IDR_MENU_DLG为新建的菜单资源
// 为对话框设置菜单
this->SetMenu(&newMenu);
//添加工具栏
/*创建第二个工具栏*/
if (!m_myToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_myToolBar.LoadToolBar(IDR_MYTOOLBAR16))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
/*让此工具栏可以使用256色的图标*/
m_myToolBar.LoadTrueColorToolBar( 16,
IDB_MYNOR16,
IDB_MYNOR16,
IDB_MYDIS16);
/*设置工具栏按钮文本*/
for (int n=0;n<m_myToolBar.GetCount();n++)
{
UINT nID=m_myToolBar.GetItemID(n);
CString strText=_T("");
if (!strText.LoadString(nID))
{
continue;
}
int nIndex=strText.Find(_T('\n'));
if (nIndex<0)
{
continue;
}
strText=strText.Right(strText.GetLength()-nIndex-1);
m_myToolBar.SetButtonText(n,strText);
}
/*设置工具栏按钮尺寸*/
CRect rect;
m_myToolBar.GetItemRect(0,&rect);
m_myToolBar.SetSizes(rect.Size(),CSize(16,16));
// 创建工具条并调入资源
// if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MYTOOLBAR1))
// {
// TRACE0("Failed to Create Dialog Toolbar\n");
// EndDialog(IDCANCEL);
// }
/*或者像下面这样,看你要哪种风格。
if(!m_wndToolBar. CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to Create Dialog Toolbar\n");
EndDialog(IDCANCEL);
} */
CRect rcClientOld; // 旧客户区RECT
CRect rcClientNew; // 加入TOOLBAR后的CLIENT RECT
GetClientRect(rcClientOld);
//重新计算RECT大小
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew); //所有的子窗口将被移动,以免被TOOLBAR覆盖
//计算移动的距离
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);
//