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

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);
...........
}
...全文
33 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
  • 打赏
  • 举报
回复
相关推荐
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "Menu.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_COMMAND(IDM_TEST, OnTest) ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut) ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew) ON_COMMAND(IDM_SHOW, OnShow) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here m_bAutoMenuEnable = FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; 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 } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); /* GetMenu()->GetSubMenu(0)->CheckMenuItem(0, MF_BYPOSITION | MF_CHECKED); GetMenu()->GetSubMenu(0)->CheckMenuItem(ID_FILE_NEW, MF_BYCOMMAND | MF_CHECKED); GetMenu()->GetSubMenu(0)->SetDefaultItem(1,TRUE); GetMenu()->GetSubMenu(0)->SetDefaultItem(ID_FILE_OPEN,FALSE); GetMenu()->GetSubMenu(0)->SetDefaultItem(5,TRUE); CString str; str.Format("x=%d, y=%d",GetSystemMetrics(SM_CXMENUCHECK),GetSystemMetrics(SM_CYMENUCHECK)); MessageBox(str); m_bitmap.LoadBitmap(IDB_BITMAP1); GetMenu()->GetSubMenu(0)->SetMenuItemBitmaps(0,MF_BYPOSITION, &m_bitmap, &m_bitmap); */ GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED); SetMenu(NULL); CMenu menu; menu.LoadMenu(IDR_MAINFRAME); SetMenu(&menu); menu.Detach(); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::OnTest() { // TODO: Add your command handler code here MessageBox("MainFrame Clicked"); } void CMainFrame::OnUpdateEditCut(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here if(2 == pCmdUI->m_nIndex) pCmdUI->Enable(); } void CMainFrame::OnUpdateFileNew(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here // if(ID_FILE_NEW == pCmdUI->m_nID); /* if(0 == pCmdUI->m_nIndex) pCmdUI->Enable(FALSE); */ } void CMainFrame::OnShow() { // TODO: Add your command handler code here MessageBox("Main show"); }
发帖
VC/MFC

1.6w+

社区成员

VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
帖子事件
创建了帖子
2002-07-11 11:11
社区公告

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