注册表编程,程序记忆功能

来源:互联网 发布:帝国cms养生采集规则 编辑:程序博客网 时间:2024/05/22 06:09

BCG注册表清除:
第一次在CXXXApp::ExitInstance() 加入CleanState(),
运行一次
接着注释掉,再在OnInitInstance加入m_bSaveState=FALSE

估计在BCG控件要写注册表的时候,它自己的写入注册表函数会判断m_bSaveState

1.VC2008集成了BCGControlBar的相关功能,用wizard生成的话如果选与BCGControlBar有关的性能,如预定皮肤,则应用程序是从CWinAppEx派生,再加CBCGPWorkspace似乎不行。


2.BCG 为了方便程序员,在注册表中保存了窗口的大小、位置等信息,包括工具栏的相应信息。这样减少了程序员保存和恢复用户上次使用过的界面的重复劳动。但也会造成改变菜单之类出现无反应的现象,让人摸不着头脑。可以采用的一个方法是,删除 BCG 为你保存的注册表键:
HKEY_CURRENT_USER/Software/[your corporation]/[your application]/Workspace
里面 your corporation 是指在 app 类里面 SetRegistryKey 指定的路径;your application 就是你的应用程序名。
把这个删掉之后,还是用你最上面的代码,运行。OK!

更方便的是InitInstance里设m_bSaveState=FALSE;

如果已经有注册内容了再加一句CleanState();

程序成型后再加上。


3.应用皮肤的过程
(1)找一个BCG的例子,将菜单与皮肤相关的项复制粘贴到你的菜单下,ID值是连续的。

(2)CMainFrame的头文件中
#define CFrameWnd CBCGPFrameWnd//类定义前。这样可以省很多替换工作哦
UINT m_nAppLook;//指示应用哪个皮肤
CBCGPMenuBar m_wndMenuBar;
//手动加入消息响应:
afx_msg void OnAppLook(UINT id);
afx_msg void OnUpdateAppLook(CCmdUI* pCmdUI);

(3)CMainFrame的Cpp文件
//消息映射增加
ON_COMMAND_RANGE(ID_VIEW_APPLOOK_2000, ID_VIEW_APPLOOK_VS2008, OnAppLook) //这是范围的响应,所以ID要连续
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_2000, ID_VIEW_APPLOOK_VS2008, OnUpdateAppLook)
//初始化函数
m_nAppLook = theApp.GetInt (_T("ApplicationLook"), ID_VIEW_APPLOOK_2003);//初始的样子
//OnCreate
OnAppLook (m_nAppLook);

if (!m_wndMenuBar.Create (this))
{
TRACE0("Failed to create menubar/n");
return -1; // fail to create
}

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

m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
EnableAutoHideBars(CBRS_ALIGN_ANY);
DockControlBar(&m_wndMenuBar); //可浮动

//直接把以下两个函数拷贝上去就OK了。
void CMainFrame::OnAppLook(UINT id)
{
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);

m_nAppLook = id;

switch (m_nAppLook)
{
case ID_VIEW_APPLOOK_2000:
// enable Office 2000 look:
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager));
break;

case ID_VIEW_APPLOOK_XP:
// enable Office XP look:
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManagerXP));
break;

case ID_VIEW_APPLOOK_WIN_XP:
// enable Windows XP look (in other OS Office XP look will be used):
CBCGPWinXPVisualManager::m_b3DTabsXPTheme = TRUE;
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPWinXPVisualManager));
break;

case ID_VIEW_APPLOOK_2003:
// enable Office 2003 look:
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2003));
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);
break;

case ID_VIEW_APPLOOK_VS2005:
// enable VS 2005 look:
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManagerVS2005));
CBCGPVisualManager::GetInstance ();
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);
break;

case ID_VIEW_APPLOOK_VS2008:
// enable VS 2008 look:
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManagerVS2008));
CBCGPVisualManager::GetInstance ();
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);
break;

case ID_VIEW_APPLOOK_2007_1:
// enable Office 2007 look:
CBCGPVisualManager2007::SetStyle (CBCGPVisualManager2007::VS2007_LunaBlue);
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2007));
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);
break;

case ID_VIEW_APPLOOK_2007_2:
// enable Office 2007 look:
CBCGPVisualManager2007::SetStyle (CBCGPVisualManager2007::VS2007_ObsidianBlack);
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2007));
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);
break;

case ID_VIEW_APPLOOK_2007_3:
// enable Office 2007 look:
CBCGPVisualManager2007::SetStyle (CBCGPVisualManager2007::VS2007_Aqua);
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2007));
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);
break;

case ID_VIEW_APPLOOK_2007_4:
// enable Office 2007 look:
CBCGPVisualManager2007::SetStyle (CBCGPVisualManager2007::VS2007_Silver);
CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2007));
CBCGPDockManager::SetDockMode (BCGP_DT_SMART);
break;

default:
ASSERT (FALSE);
}

CBCGPDockManager* pDockManager = GetDockManager ();
if (pDockManager != NULL)
{
ASSERT_VALID (pDockManager);
pDockManager->AdjustBarFrames ();
}

RecalcLayout ();
RedrawWindow (NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);

theApp.WriteInt (_T("ApplicationLook"), m_nAppLook);
}


void CMainFrame::OnUpdateAppLook(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio (m_nAppLook == pCmdUI->m_nID);
}

4.上下文菜单

(1)当然是新建一个需要的上下文菜单

(2)应用程序类的头文件下

virtual void PreLoadState ();

Cpp文件

void C***App::PreLoadState ()
{

GetContextMenuManager()->AddMenu (_T("My menu"), IDR_CONTEXT_MENU);//IDR_CONTEXT_MENU是菜单的ID

// TODO: add another context menus here
}

(3)响应上下文菜单的视图类中增加对上下文菜单消息的响应

void C***View::OnContextMenu(CWnd* , CPoint point)
{
theApp.ShowPopupMenu (IDR_CONTEXT_MENU, point, this);
// TODO: 在此处添加消息处理程序代码
}

2.

BCG例子BCGPExplorer:

1.BCG的菜单、工具栏、动画图标和地址栏

这是BCG的主要特色,也比较繁琐。

(1)如果要支持自定义工具。

首先在String表定义入口ID:ID_TOOLS_ENTRY,与某菜单项关联。然后定义连续的ID,如ID_USER_TOOL1、ID_USER_TOOL2......。

在App下增加 EnableUserTools (ID_TOOLS_ENTRY, ID_USER_TOOL1, ID_USER_TOOL10);

(2)主要是修改CMainFrame

头文件声明

CBCGPMenuBar m_wndMenuBar;
CBCGPStatusBar m_wndStatusBar;
CBCGPToolBar m_wndToolBar;
CBCGPReBar m_wndReBar; //菜单、工具栏、地址栏的容器
CBCGPAnimCtrl m_wndAnimate;//动画控件
CComboBoxEx m_wndAddress;//地址栏

增加响应自定义工具的消息函数OnViewCustomize

手动添加消息响应

afx_msg LRESULT OnToolbarReset(WPARAM,LPARAM);
afx_msg LRESULT OnToolbarContextMenu(WPARAM,LPARAM);

虚函数virtual BOOL OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup);

Cpp文件

ON_REGISTERED_MESSAGE(BCGM_RESETTOOLBAR, OnToolbarReset)
ON_REGISTERED_MESSAGE(BCGM_TOOLBARMENU, OnToolbarContextMenu)

OnCreate()函数

CBCGPToolBar::EnableQuickCustomization ();

CBCGPToolBar::SetSizes (CSize (28, 28), CSize (22, 22));//工具栏大小
CBCGPToolBar::SetMenuSizes (CSize (22, 22), CSize (16, 16));//工具栏中下拉菜单项大小

//指定常用的工具,其它会自动收缩。每个下拉(pulldown)菜单条至少要有一项

CList<UINT, UINT> lstBasicCommands;

lstBasicCommands.AddTail (ID_VIEW_TOOLBARS);
lstBasicCommands.AddTail (ID_APP_EXIT);
lstBasicCommands.AddTail (ID_APP_ABOUT);
lstBasicCommands.AddTail (ID_VIEW_TOOLBAR);
lstBasicCommands.AddTail (ID_VIEW_CUSTOMIZE);
lstBasicCommands.AddTail (ID_COMMAND_HISTORY);
lstBasicCommands.AddTail (ID_VIEW_LARGEICON);
lstBasicCommands.AddTail (ID_VIEW_SMALLICON);
lstBasicCommands.AddTail (ID_VIEW_LIST);
lstBasicCommands.AddTail (ID_VIEW_DETAILS);
lstBasicCommands.AddTail (ID_EDIT_CUT);
lstBasicCommands.AddTail (ID_EDIT_COPY);
lstBasicCommands.AddTail (ID_EDIT_PASTE);

CBCGPToolBar::SetBasicCommands (lstBasicCommands);

if (!m_wndMenuBar.Create (this))//菜单的创建
{
TRACE0("Failed to create menubar/n");
return -1; // fail to create
}

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

// Remove menubar gripper and borders:
m_wndMenuBar.SetBarStyle (m_wndMenuBar.GetBarStyle() &
~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));

//动画控件的创建,AFX_IDW_TOOLBAR为标准ID,IDB_ANIMATION是连续位图

if (!m_wndAnimate.Create (_T(""), WS_CHILD | WS_VISIBLE, CRect(0, 0, 20, 20), this, AFX_IDW_TOOLBAR + 2) ||
!m_wndAnimate.SetBitmap (IDB_ANIMATION, 20))
{
TRACE0("Failed to create aimation/n");
return -1; // fail to create
}

m_wndAnimate.Play (500);

//检测颜色深度是256还是真彩色

CClientDC dc (this);
BOOL bIsHighColor = dc.GetDeviceCaps (BITSPIXEL) > 8;

UINT uiToolbarHotID = bIsHighColor ? IDB_TOOLBAR256 : 0; //IDB_TOOLBAR256真彩色图像(用作工具栏)
UINT uiToolbarColdID = bIsHighColor ? IDB_TOOLBARCOLD256 : 0;
UINT uiMenuID = bIsHighColor ? IDB_MENU256 : IDB_MENU16;

if (!m_wndToolBar.CreateEx(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME, uiToolbarColdID, uiMenuID, FALSE, 0, 0, uiToolbarHotID))//IDR_MAINFRAME是256色的预定义工具栏
{
TRACE0("Failed to create toolbar/n");
return -1; // fail to create
}

// Remove toolbar gripper and borders:
m_wndToolBar.SetBarStyle (m_wndToolBar.GetBarStyle() &
~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));

//创建地址栏

if (!m_wndAddress.Create (CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 120), this, AFX_IDW_TOOLBAR + 1))
{
TRACE0("Failed to create combobox/n");
return -1; // fail to create
}

//将各项加入rebar面板
DWORD dwStyle = RBBS_GRIPPERALWAYS | RBBS_FIXEDBMP | RBBS_BREAK;

if (!m_wndReBar.Create(this) ||
!m_wndReBar.AddBar (&m_wndMenuBar) ||
!m_wndReBar.AddBar (&m_wndToolBar, NULL, NULL, dwStyle) ||
!m_wndReBar.AddBar(&m_wndAnimate, NULL, NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP) ||
!m_wndReBar.AddBar(&m_wndAddress, _T("Address"), NULL, dwStyle))
{
TRACE0("Failed to create rebar/n");
return -1; // fail to create
}

m_wndMenuBar.AdjustLayout ();
m_wndToolBar.AdjustLayout ();

//--------------------------------------------------------------
// Set up min/max sizes and ideal sizes for pieces of the rebar:
//--------------------------------------------------------------
REBARBANDINFO rbbi;

CRect rectToolBar;
m_wndToolBar.GetItemRect(0, &rectToolBar);

rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE;
rbbi.cxMinChild = rectToolBar.Width();
rbbi.cyMinChild = rectToolBar.Height();
rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * m_wndToolBar.GetCount ();
m_wndReBar.GetReBarCtrl().SetBandInfo (1, &rbbi);
rbbi.cxMinChild = 0;

CRect rectAddress;
m_wndAddress.GetEditCtrl()->GetWindowRect(&rectAddress);

rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE;
rbbi.cyMinChild = rectAddress.Height() + 10;
rbbi.cxIdeal = 200;
m_wndReBar.GetReBarCtrl().SetBandInfo (3, &rbbi);//基于上面的AddBar所定的顺序

// 菜单和工具栏允许增加自定义按钮
m_wndMenuBar.EnableCustomizeButton (TRUE, (UINT)-1, _T(""));
m_wndToolBar.EnableCustomizeButton (TRUE, (UINT)-1, _T(""));

EnableDocking (CBRS_ALIGN_ANY);

m_wndReBar.EnableDocking (CBRS_TOP);//可以浮动和停靠
DockControlBar (&m_wndReBar);

CString strMainToolbarTitle;
strMainToolbarTitle.LoadString (IDS_MAIN_TOOLBAR);
m_wndToolBar.SetWindowText (strMainToolbarTitle);

// TODO: Remove this if you don't want tool tips
m_wndMenuBar.SetBarStyle(m_wndMenuBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY);
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY);

void CMainFrame::OnViewCustomize()
{
//------------------------------------
// Create a customize toolbars dialog:
//------------------------------------
CBCGPToolbarCustomize* pDlgCust = new CBCGPToolbarCustomize (this,
TRUE
);

pDlgCust->Create ();
}

LRESULT CMainFrame::OnToolbarContextMenu(WPARAM,LPARAM lp)
{
CPoint point (BCG_GET_X_LPARAM(lp), BCG_GET_Y_LPARAM(lp));

CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu;
pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ());

return 0;
}

//替换256色标准工具栏IDR_MAINFRAME为真彩色

afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM)
{
UINT uiToolBarId = (UINT) wp;
if (uiToolBarId != IDR_MAINFRAME)
{
return 0;
}

// Replace "Back" and "Forward" buttons by the menu buttons
// with the history lists:

CMenu menuHistory;
menuHistory.LoadMenu (IDR_HISTORY_POPUP);

CBCGPToolbarMenuButton btnBack (ID_GO_BACK, menuHistory,
CImageHash::GetImageOfCommand (ID_GO_BACK), _T("Back"));//带菜单的按钮
btnBack.m_bText = TRUE;
m_wndToolBar.ReplaceButton (ID_GO_BACK, btnBack);

m_wndToolBar.ReplaceButton (ID_GO_FORWARD,
CBCGPToolbarMenuButton (ID_GO_FORWARD, menuHistory,
CImageHash::GetImageOfCommand (ID_GO_FORWARD), _T("Forward")));

// "Folders" button has a text label:
m_wndToolBar.SetToolBarBtnText (m_wndToolBar.CommandToIndex (ID_VIEW_FOLDERS),
_T("Folders"));

// Replace "Views" button by the menu button:
CMenu menuViews;
menuViews.LoadMenu (IDR_VIEWS_POPUP);

m_wndToolBar.ReplaceButton (ID_VIEW_VIEWS,
CBCGPToolbarMenuButton ((UINT)-1, menuViews,
CImageHash::GetImageOfCommand (ID_VIEW_VIEWS), _T("Views")));

return 0;
}

BOOL CMainFrame::OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup)
{
//---------------------------------------------------------
// 将占位的ID_VIEW_TOOLBARS菜单项替换为IDR_POPUP_TOOLBAR:
//---------------------------------------------------------
CFrameWnd::OnShowPopupMenu (pMenuPopup);

if (pMenuPopup != NULL &&
pMenuPopup->GetMenuBar ()->CommandToIndex (ID_VIEW_TOOLBARS) >= 0)
{
if (CBCGPToolBar::IsCustomizeMode ())
{
//----------------------------------------------------
// Don't show toolbars list in the cuztomization mode!
//----------------------------------------------------
return FALSE;
}

pMenuPopup->RemoveAllItems ();

CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE);
}

return TRUE;
}

3.

补充CBCGPToolBar的使用

CMainFrame::OnCreate下

(1) CBCGPToolBar::EnableQuickCustomization ();//按Alt键时可以拖动工具栏上的图标重新排列

(2) m_wndToolBar.EnableCustomizeButton (TRUE, ID_VIEW_CUSTOMIZE, _T("Customize..."));

//允许自定义工具栏,名字“Customize”,并与菜单项ID_VIEW_CUSTOMIZE关联。

void CMainFrame::OnViewCustomize()
{//在BCG标准的自定义工具栏中加入新的属性页
CList <CRuntimeClass*, CRuntimeClass*> lstCustomPages;
lstCustomPages.AddTail (RUNTIME_CLASS (CMyCustomizationPage));

//CMyCustomizationPage是一个自定义的属性页
//------------------------------------
// Create a customize toolbars dialog:
//------------------------------------
CBCGPToolbarCustomize* pDlgCust = new CBCGPToolbarCustomize (this,
TRUE ,
BCGCUSTOMIZE_MENU_SHADOWS | BCGCUSTOMIZE_TEXT_LABELS |
BCGCUSTOMIZE_LOOK_2000 | BCGCUSTOMIZE_MENU_ANIMATIONS, // default parameters
&lstCustomPages); // pointer to the list of runtime classes of the custom property pages

pDlgCust->Create ();
}

(3)将占位菜单项ID_VIEW_TOOLBARS替换为菜单IDR_POPUP_TOOLBAR

virtual BOOL OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup);

BOOL CMainFrame::OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup)
{
//---------------------------------------------------------
// Replace ID_VIEW_TOOLBARS menu item to the toolbars list:
//---------------------------------------------------------
CFrameWnd::OnShowPopupMenu (pMenuPopup);

if (pMenuPopup != NULL &&
pMenuPopup->GetMenuBar ()->CommandToIndex (ID_VIEW_TOOLBARS) >= 0)
{
if (CBCGPToolBar::IsCustomizeMode ())
{
//----------------------------------------------------
// Don't show toolbars list in the cuztomization mode!
//----------------------------------------------------
return FALSE;
}

pMenuPopup->RemoveAllItems ();

CMenu menu;
VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE);
}

return TRUE;
}


IDR_POPUP_TOOLBAR菜单

4.

在对话框中使用菜单、工具栏等

DlgBars解析

(1)在对话框资源中进行占位,设置相应ID,产生相应变量

CStatic m_wndMenuBarLocation;//菜单
CStatic m_wndStatusBarLocation;//状态栏
CStatic m_wndToolbarLocation;//工具栏
CStatic m_wndOutlookBarLocation;//Outlook侧边栏
CStatic m_wndCaptionLocation;//标题栏

(2)有关菜单的类

class CMyMenuBar : public CBCGPMenuBar

class CCmdFrame : public CBCGPFrameWnd

构造函数CCmdFrame(CBCGPDialog* pDlg);

BOOL CCmdFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
ASSERT_VALID (m_pDlg);
return m_pDlg->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);//转由对话框处理
}

class CMyFrameImpl : public CBCGPFrameImpl

//CBCGPFrameImpl实现工具栏的管理,包括从注册表读写状态,docking,键盘和鼠标消息等
{
CMyFrameImpl() : CBCGPFrameImpl (NULL) {}

friend class CCmdFrame;
};

void CCmdFrame::SetMenuBar (CBCGPMenuBar* pMenuBar)
{
((CMyFrameImpl&)m_Impl).m_pMenuBar = pMenuBar;//实际是把CMyMenuBar绑定到CMyFrameImpl
}

(3)对话框类

头文件

#define CDialog CBCGPDialog

定义:

CBCGPOutlookBar m_wndOutlookBar;
CBCGPOutlookBarPane m_wndPane1;
CBCGPOutlookBarPane m_wndPane2;

CMyMenuBar m_wndMenuBar;
CBCGPCaptionBar m_wndCaptionBar;
CBCGPToolBar m_wndToolBar;
CBCGPStatusBar m_wndStatusBar;

CBitmap m_bmpCaption;

CCmdFrame* m_pMenuFrame;

Cpp文件

OnInitDialog()

// Create Outlook Bar:
DWORD dwStyle = WS_CAPTION | WS_CHILD | WS_VISIBLE | CBRS_ALIGN_LEFT;
DWORD dwBCGStyle = 0;
m_wndOutlookBar.Create (_T("Shortcuts"), this, CRect (0, 0, 100, 100),
AFX_IDW_TOOLBAR, dwStyle, dwBCGStyle);

m_wndOutlookBar.EnableGripper (TRUE);

m_wndOutlookBar.SetBarStyle (CBRS_ALIGN_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

m_wndOutlookBar.EnableSetCaptionTextToTabName (FALSE);

m_wndPane1.Create (&m_wndOutlookBar, dwDefaultToolbarStyle, 1);
m_wndPane1.SetWindowText (_T("Page 1"));
m_wndOutlookBar.AddTab (&m_wndPane1);

m_wndPane1.EnableTextLabels (TRUE);
m_wndPane1.SetOwner (this);

m_wndPane2.Create (&m_wndOutlookBar, dwDefaultToolbarStyle, 1);
m_wndPane2.SetWindowText (_T("Page 2"));
m_wndOutlookBar.AddTab (&m_wndPane2);

m_wndPane2.EnableTextLabels (TRUE);
m_wndPane2.SetOwner (this);

// Add some shortcuts:
m_wndPane1.AddButton (IDB_SHORTCUT1, "Shortcut 1", ID_SHORTCUT_1);
m_wndPane1.AddButton (IDB_SHORTCUT2, "Shortcut 2", ID_SHORTCUT_2);


m_wndPane2.AddButton (IDB_SHORTCUT3, "Shortcut 3", ID_SHORTCUT_3);
m_wndPane2.AddButton (IDB_SHORTCUT4, "Shortcut 4", ID_SHORTCUT_4);

CRect rectClient;
GetClientRect (rectClient);

// 在m_wndOutlookBarLocation所占位创建m_wndOutlookBar:
CRect rectOutlookBar;
m_wndOutlookBarLocation.GetWindowRect (&rectOutlookBar);
ScreenToClient (&rectOutlookBar);

m_wndOutlookBar.SetWindowPos (&wndTop, rectOutlookBar.left, rectOutlookBar.top,
rectOutlookBar.Width (),
rectClient.Height () - 2 * rectOutlookBar.top,
SWP_NOACTIVATE);

// Create menu bar:
m_wndMenuBar.Create (this);

CMenu menu;
menu.LoadMenu (IDR_MAINFRAME);
m_wndMenuBar.CreateFromMenu (menu.GetSafeHmenu (), TRUE, TRUE);

m_wndMenuBar.SetBarStyle (
m_wndMenuBar.GetBarStyle () &
~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));

// Set menu bar position and size:
CRect rectMenuBar;
m_wndMenuBarLocation.GetWindowRect (&rectMenuBar);
ScreenToClient (&rectMenuBar);

m_wndMenuBar.SetWindowPos (&wndTop, rectMenuBar.left, rectMenuBar.top,
rectMenuBar.Width (),
rectMenuBar.Height (),
SWP_NOACTIVATE);

m_pMenuFrame = new CCmdFrame (this);
m_pMenuFrame->Create (NULL, _T(""));
m_pMenuFrame->ShowWindow (SW_HIDE);
m_pMenuFrame->SetMenuBar (&m_wndMenuBar);

m_wndMenuBar.SetOwner (m_pMenuFrame);//设定m_wndMenuBar的Owner为m_pMenuFrame
BCGCBProSetTopLevelFrame (m_pMenuFrame);

// Create caption bar:
m_wndCaptionBar.Create (WS_CHILD | WS_VISIBLE, this, (UINT)-1);
m_wndCaptionBar.SetText (_T("Caption"), CBCGPCaptionBar::ALIGN_LEFT);
m_wndCaptionBar.SetFlatBorder ();

// Load caption image:
m_bmpCaption.LoadBitmap (IDB_CAPTION);
m_wndCaptionBar.SetBitmap ((HBITMAP) m_bmpCaption.GetSafeHandle (), RGB (255, 0, 255));

m_wndCaptionBar.SetBarStyle (
m_wndCaptionBar.GetBarStyle () &
~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));

// Set caption bar position and size:
CRect rectCaptionBar;
m_wndCaptionLocation.GetWindowRect (&rectCaptionBar);
ScreenToClient (&rectCaptionBar);

m_wndCaptionBar.SetWindowPos (&wndTop, rectCaptionBar.left, rectCaptionBar.top,
rectCaptionBar.Width (),
rectCaptionBar.Height (),
SWP_NOACTIVATE);
// Create toolbar:
m_wndToolBar.Create (this);
m_wndToolBar.LoadToolBar (IDR_MAINFRAME, 0, 0, TRUE );

m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY);

m_wndToolBar.SetBarStyle (
m_wndToolBar.GetBarStyle () &
~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));

CSize sizeToolBar = m_wndToolBar.CalcFixedLayout (FALSE, TRUE);

// Set ToolBar position and size:
CRect rectToolBar;
m_wndToolbarLocation.GetWindowRect (&rectToolBar);
ScreenToClient (&rectToolBar);

m_wndToolBar.SetWindowPos (&wndTop, rectToolBar.left, rectToolBar.top,
sizeToolBar.cx, sizeToolBar.cy, SWP_NOACTIVATE);

m_wndToolBar.SetOwner (this);

// 指示m_wndToolBar的消息全部由对话框处理
m_wndToolBar.SetRouteCommandsViaFrame (FALSE);

// Create status bar:
m_wndStatusBar.Create(this);
m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT));

// Set status bar position and size:
CRect rectStatusBar;
m_wndStatusBarLocation.GetWindowRect (&rectStatusBar);
ScreenToClient (&rectStatusBar);

m_wndStatusBar.SetWindowPos (&wndTop, rectStatusBar.left, rectStatusBar.top,
rectStatusBar.Width (), rectStatusBar.Height (), SWP_NOACTIVATE);

m_wndStatusBar.SetWindowText ("Test");

//消息处理

void CDlgBarsDlg::OnEditPaste()
{
MessageBox ("OnEditPaste");
}

//状态更新

void CDlgBarsDlg::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck ();
}

LRESULT CDlgBarsDlg::OnKickIdle(WPARAM, LPARAM)
{
m_wndToolBar.OnUpdateCmdUI ((CFrameWnd*) this, TRUE);
return 0;
}

5.

工具提示控件

DlgToolTips


1.创建类class CCustomToolTipCtrl : public CBCGPToolTipCtrl

virtual CSize GetIconSize ()
{
return CSize (32, 32);
}


void CCustomToolTipCtrl::OnShow(NMHDR* pNMHDR, LRESULT* pResult)
{
m_nCurrID = CWnd::FromHandle ((HWND)pNMHDR->idFrom)->GetDlgCtrlID ();

switch (m_nCurrID)
{
case IDOK:
m_strDesrciption = _T("OK Button description...");//基本描述
break;

case IDCANCEL:
m_strDesrciption = _T("Cancel Button description...");
break;

default:
m_strDesrciption.Empty ();
}

CBCGPToolTipCtrl::OnShow (pNMHDR, pResult);
}

BOOL CCustomToolTipCtrl::OnDrawIcon (CDC* pDC, CRect rectImage)
{
UINT uiBmpResID = 0;

switch (m_nCurrID)
{
case IDOK:
uiBmpResID = IDB_OK;
break;

case IDCANCEL:
uiBmpResID = IDB_CANCEL;
break;
}

if (uiBmpResID == 0)
{
return FALSE;
}

CBCGPToolBarImages image;
image.Load (uiBmpResID);
image.SetSingleImage ();
image.DrawEx (pDC, rectImage, 0);

return TRUE;
}

2.对话框

OnInitDialog()

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);
}
}



// Create the ToolTip control.
m_ToolTip.Create(this);
m_ToolTip.Activate(TRUE);

CBCGPToolTipParams params;
params.m_bVislManagerTheme = TRUE;

m_ToolTip.SetParams (&params);

// TODO: Use one of the following forms to add controls:
m_ToolTip.AddTool (GetDlgItem(IDOK), _T("This is OK button!"));//另外的描述
m_ToolTip.AddTool (GetDlgItem(IDCANCEL), _T("This is Cancel button!"));

BOOL CDlgToolTipsDlg::PreTranslateMessage(MSG* pMsg)
{
switch (pMsg->message)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_MOUSEMOVE:
m_ToolTip.RelayEvent(pMsg);
break;
}

return CBCGPDialog::PreTranslateMessage(pMsg);
}

0 0
原创粉丝点击