BCG开始设置

Posted on 2009-05-29 09:53 ferrero 阅读(1263) 评论(0)  编辑 收藏 引用
原文网址http://www.bcgsoft.com/doc/getting_started.htm
1.确定在你程序的InitInstance()函数中调用了AfxOleInit()函数
2.在ExistInstance()调用BCGCBProCleanUp()
3.在stdafx.h中添加下面的语句:
#include "BCGCBProInc.h"
4.使你的程序类派生自CBCGWorkspace:
class CMyApp
                      
public CWinApp,
public CBCGPWorkspace
5.首先你需要确定在注册表的什么位置保存你自定义的数据,需要什么样的自定义特征(鼠标,键盘,上下文菜单)。为了完成这个工作,需要在CMyApp::InitInstance中设置注册表项,并且初始化自定义管理器
SetRegistryBase (_T("Settings"));

// Initialize customization managers:
InitMouseManager();
InitContextMenuManager();
InitKeyboardManager();
6.如果你决定使用鼠标或者上下文菜单自定义功能,你需要“附加”一个视类到鼠标自定义管理器,并且初始化上下文菜单。然后重载CBCGPWorkspace::PreLoadState方法
class CMyApp ....
{
...

virtual void
PreLoadState();
...
};


void CMyApp::PreLoadState()
{
   
// Associate mouse event with specific view(s):
    GetMouseManager()->AddView (iIdTestView, _T("
Test view"), IDR_VIEW);

   
// Initialize context menus:
    GetContextMenuManager()->AddMenu (_T("
Test menu"), idMenu); 
}
7.在mainfrm.h和mainfrm.cpp中将 CMDIFrameWnd 换成 CBCGPMDIFrameWnd (在单文档程序中将CFrameWnd 变成 CBCGPFrameWnd
8.将CMDIChildWnd 变成  CBCGPMDIChildWnd
9.将CToolbar 变成 CBCGPToolBar并且添加一个植入式菜单栏到你的 CMainFrame 类:
CBCGPMenuBar    m_wndMenuBar;     // New menu bar
CBCGPToolBar      m_wndToolBar;     
// Application toolbar
10.在CMainFrame::OnCreate() 中添加下面的语句,激活新的菜单栏
// Create menu bar (replaces the standard menu):
if (!m_wndMenuBar.Create (
this))
{
      TRACE0("Failed to create menubar\n");
     
return -1;      // fail to create
}

m_wndMenuBar.SetBarStyle (m_wndMenuBar.GetBarStyle() |
                                          CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

11.使得菜单栏能浮动,需要添加下面的语句:
m_wndMenuBar.EnableDocking (CBRS_ALIGN_ANY);
DockControlBar (&m_wndMenuBar);
12.重要:你能在程序中使用任何数量的CBCGToolBar工具栏。所有的工具栏图像都将自动的整合到一张位图图像中。虽然如此,但是只有一个CBCGMenuBar 对象能被使用。
为了使工具栏和菜单能自定义,一定要进行下面的改变:
    添加工具栏和菜单自定义命令(比如View | Customize...
    实现OnViewCustomize 方法。代码有点像下面所示:
  •  
void CMainFrame::OnViewCustomize()
{
 // Create a customize toolbars dialog:
 CBCGPToolbarCustomize* pDlgCust = new CBCGPToolbarCustomize (
this,
TRUE
/* Automatic menus scaning */);

 // Add predefined toolbars:
 pDlgCust->AddToolBar ("Main", IDR_MAINFRAME);
 ....

 // Add user-defined commands:
 pDlgCust->AddButton ("User", CBCGPToolbarButton (ID_USER_TOOL1, 1, "User Tool 1", TRUE));
 pDlgCust->AddButton ("User", CBCGPToolbarButton (ID_USER_TOOL2, 2, "User Tool 2", TRUE));
 pDlgCust->AddButton ("User", CBCGPToolbarButton (ID_USER_TOOL3, 3, "User Tool 3", TRUE));
 ....

 pDlgCust->SetUserCategory ("User");

 // Enable Create/Delete of the user-defined toolbars:
 pDlgCust->EnableUserDefinedToolbars ();

 pDlgCust->Create ();
}

  


实现office 2000菜单

    定义你自己的基本命令设置(通常在CMainFrame::OnCreate()中):

CList<UINT, UINT> lstBasicCoomads;

lstBasicCoomads.AddTail (ID_FILE_NEW);
lstBasicCoomads.AddTail (ID_FILE_OPEN);
lstBasicCoomads.AddTail (ID_FILE_SAVE);

......
lstBasicCoomads.AddTail (ID_APP_ABOUT);

CBCGPToolBar::SetBasicCommands (lstBasicCoomads);

    这些命令会显示在下拉菜单中


在运行时改变菜单字体

CBCGPMenuBar::SetMenuFont (LPLOGFONT lpLogFont, BOOL bHorz = TRUE);


激活“页面”(自定义)按钮只需要调用:

m_wndToolBar.EnableCustomizeButton (TRUE, id_of_customize_command,
_T("Customize..."));


激活在按钮图像下的文字:

m_wndToolBar.EnableTextLabels (BOOL bEnable = TRUE);

激活用户定义的工具
    增加一个新的菜单项:ID_TOOLS_ENTRY。这项会自动的被实际的工具表代替
    增加下面的项到STRING资源中:
  1. ID_TOOL1    "Activates user-defined tool\nUser Tool"
  2. ID_TOOL2    "Activates user-defined tool\nUser Tool"
    ....
  3. ID_TOOLx    "Activates user-defined tool\nUser Tool"


    为了每个可“分离式”弹出菜单项,将"Break"属性变成"Bar"(MF_MENUBARBREAK)
    在程序的InitInstance() 调用
    EnableTearOffMenus (_T("RegBase"), ID_TEAR_OFF1, ID_TEAR_OFFx);

    激活静态可"分离"("可分开")菜单


    在STRIING资源表中保留一个项目,这个项的ID应该与动态的可分离ID不同(如上所示)
    ID_TEAR_OFF_BAR    "<dummy>"
    在框架类OnShowPopupMenu中,为了特别的菜单按钮激活“可分离”
    pMenuButton->SetTearOff (D_TEAR_OFF_BAR);






































 


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


posts - 5, comments - 0, trackbacks - 0, articles - 0

Copyright © ferrero