如何在属性页的顶部同时加入菜单和工具栏(菜单在上面)?谢谢!附代码.

ylb_and_xy 2002-07-11 11:11:31
BOOL CMySheet::OnInitDialog()
{
//load menu
CMenu Menu;
if(Menu.LoadMenu( IDR_MENU )==0)
{
MessageBox("LOAD MENU ERROR!",NULL,MB_OK);
}
SetMenu(&Menu);

//load toolbar
CToolBar ToolBar;
ToolBar.Create(this);
if(ToolBar.LoadToolBar(IDR_TOOLBAR)==0)
{
MessageBox("LOAD ToolBar ERROR!",NULL,MB_OK);
}
ToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY |CBRS_ALIGN_BOTTOM |CBRS_ALIGN_ANY );
ToolBar.ShowWindow(SW_SHOW);
...........
}
...全文
55 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ylb_and_xy 2002-07-16
  • 打赏
  • 举报
回复
我的也是,我已经改变方案了。
马上结帖。
public 2002-07-12
  • 打赏
  • 举报
回复
我的
CMySheet继承自CPropertyPage
ylb_and_xy 2002-07-11
  • 打赏
  • 举报
回复
上面的代码只能添加菜单,不能添加工具栏。并且LoadToolBar函数执行是正确的。
ylb_and_xy 2002-07-11
  • 打赏
  • 举报
回复
试了,没用。谢谢。
public 2002-07-11
  • 打赏
  • 举报
回复
添加工具栏成员变量m_wndToolbar
BOOL CMySheet::OnInitDialog()
{
.......................
//CREATE TOOLBAR
if(!m_wndToolbar.Create(this) || !m_wndToolbar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to Create Dialog Toolbar\n");
EndDialog(IDCANCEL);
}
CRect rcClientOld; // Old Client Rect
CRect rcClientNew; // New Client Rect with Tollbar Added
GetClientRect(rcClientOld); // Retrive the Old Client WindowSize
// 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.
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.
// 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); //Handle to the Dialog Controls
while(pwndChild) // Cycle through all child controls
{
pwndChild->GetWindowRect(rcChild); // Get the child control RECT
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset); // Changes the Child Rect by the values of the claculated offset
pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
pwndChild = pwndChild->GetNextWindow();
}

CRect rcWindow;
GetWindowRect(rcWindow); // Get the RECT of the Dialog
rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // Increase width to new Client Width
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); // Increase height to new Client Height
MoveWindow(rcWindow,FALSE); // Redraw Window

// Now we REALLY Redraw the Toolbar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);


return TRUE;












}
ylb_and_xy 2002-07-11
  • 打赏
  • 举报
回复
up up up

16,548

社区成员

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

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

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