Visual Studio 2010的新特性里面Ribbon界面是一个很重要的东西,Ribbon界面非常易用和高效,也不去强调和证明它将成为未来应用程序界面的一种趋势。为了让我们的应用程序“Ready for Windows 7”,我们有必要根据实际的情况需要,为我们的应用程序添加Ribbon界面。
为了推广Ribbon界面,为了讨好程序员们,让程序员可以轻松地为各种应用程序创建Ribbon界面,微软真是不遗余力,不断地推出新的Ribbon界面接口。为了可以让所有基于C++的普通Windows应用程序都可以添加Ribbon界面,微软在Windows 7 SDK中,又推出了基于COM的接口——Scenic Ribbon API。
利用Scenic Ribbon API,我们可以更加灵活方便地为各种Windows应用程序添加Ribbon界面,改善应用程序的用户体验。在接下来的文章中,我们就介绍一下如何利用这种新的方式为普通Windows应用程序添加Ribbon界面。
我们都知道,Ribbon界面是随着Office 2007一同发布的。在过去的几年中,微软不断地吸取用户对Ribbon界面的反馈,不断地对其进行改进,到了Windows 7,微软正式加入了命名为Scenic Ribbon的第二代Ribbon界面,即取代第一代Ribbon的升级版本。随着Scenic Ribbon成为Windows 7的一部分以及微软所提供的Scenic Ribbon API,这意味着今后第三方程序开发者能在自己开发的应用程序中免费用上这种界面形式。Scenic Ribbon作为第二代Ribbon界面,所适用的是所有的Windows应用程序,和前代有所不同是理所当然的。例如,由于最初Ribbon界面是Office专用,因此使用Ribbon界面的Office 2007程序窗口左上角都有一个比较显眼的Office图标按钮。当应用到其他程序之后,这个图标显然不能继续存在,因此在Scenic Ribbon中,这个位置就被相应应用程序自身的图标所取代。另外,为了满足各种应用程序的需要,Scenic Ribbon还添加了部分Ribbon控件,使得Ribbon界面的控件更加丰富,能够应对各种应用程序对Ribbon界面控件的需要。值得一提的是,Office作为Ribbon界面的开山鼻祖,到了Office的下一个版本Office 2010,也全面使用了Scenic Ribbon以替代第一代Ribbon界面。
同时微软在VisualC++2010也提供了Ribbon资源设计器,使Ribbon开发更加简单快捷。
Scenic Ribbon API是一套基于COM的非托管API。通过这套API,我们可以为所有基于Windows的非托管应用程序创建Ribbon界面面板,添加Ribbon控件,处理Ribbon控件的各种动作,执行某种业务逻辑等等。而至于Ribbon界面的布局,各个控件的位置和属性等,则是通过基于XAML的xml文件来进行定义和描述的。编译器会将这个XML文件编译成相应的资源文件,头文件和二进制的BML文件。而Scenic Ribbon API最终会读取这些描述控件信息的文件并创建Ribbon界面。在业务逻辑层,Scenic Ribbon API提供了相应的Execute函数来处理所有控件的消息,在其中我们可以完成相应的业务逻辑。
在Windows 7中,微软还为我们提供了用于为非托管代码(Native)应用程序创建Ribbon界面的Scenic Ribbon API的解决方案。另外,针对基于WPF的托管代码应用程序,微软还将提供另外的基于WPF的Ribbon界面解决方案。
Firefox 3.7已经采用Windows7的Ribbon界面。
下面我们亲自来动手构建一个基于VisualC++2010开发windows7的tabelt pc应用的WindowsRibbon范例
1.帅气的VS2010启动画面,启动VS2010
2.创建inkdoc的MFC工程
3.MFC向导1
4.MFC向导2,选择中文界面,多文档程序,以及windows7风格
5.MFC向导3,跳过
6.MFC向导4,创建文档格式,文件名
7.MFC向导5。跳过
8.MFC向导6,选择Ribbon
9.MFC向导7,设置高级选项
10.MFC设置8,设置CFORMVIEW,
11.打印提示,不理睬,直接跳过
12.VisualC++2010自带的Ribbon编辑器
13.操作与工具箱控件一样操作,设置按钮属性
14.设置按钮
15.设置按钮属性,
16.为按钮添加事件
17.类似菜单的操作
18.在Formview,选择对话框,插入flash控件,然后为flash添加MFC activeX 类向导
19.插入flash控件类
帅的惊动了CSDN的windows7的tabelt pc应用的WindowsRibbon范例的效果图
tablet PC的轨迹核心代码如下
const TCHAR* gc_szAppName = TEXT("Basic Recognition");
// 建立轨迹指针,识别指针,轨迹画板指针
IInkCollector * g_pIInkCollector = NULL;
IInkDisp * g_pIInkDisp = NULL;
IInkRecognizerContext * g_pIInkRecoContext = NULL;
//定义初始化变量
const LPOLESTR gc_pwsInputScopes[] = {
L"(!IS_DEFAULT)",
L"(!IS_URL)",
L"(!IS_FILE_FULLFILEPATH)",
L"(!IS_FILE_FILENAME)",
L"(!IS_EMAIL_USERNAME)",
L"(!IS_EMAIL_SMTPEMAILADDRESS)",
L"(!IS_LOGINNAME)",
L"(!IS_PERSONALNAME_FULLNAME)",
L"(!IS_PERSONALNAME_PREFIX)",
L"(!IS_PERSONALNAME_GIVENNAME)",
L"(!IS_PERSONALNAME_MIDDLENAME)",
L"(!IS_PERSONALNAME_SURNAME)",
L"(!IS_PERSONALNAME_SUFFIX)",
L"(!IS_ADDRESS_FULLPOSTALADDRESS)",
L"(!IS_ADDRESS_POSTALCODE)",
L"(!IS_ADDRESS_STREET)",
L"(!IS_ADDRESS_STATEORPROVINCE)",
L"(!IS_ADDRESS_CITY)",
L"(!IS_ADDRESS_COUNTRYNAME)",
L"(!IS_ADDRESS_COUNTRYSHORTNAME)",
L"(!IS_CURRENCY_AMOUNTANDSYMBOL)",
L"(!IS_CURRENCY_AMOUNT)",
L"(!IS_DATE_FULLDATE)",
L"(!IS_DATE_MONTH)",
L"(!IS_DATE_DAY)",
L"(!IS_DATE_YEAR)",
L"(!IS_DATE_MONTHNAME)",
L"(!IS_DATE_DAYNAME)",
L"(!IS_DIGITS)",
L"(!IS_NUMBER)",
L"(!IS_ONECHAR)",
L"(!IS_TELEPHONE_FULLTELEPHONENUMBER)",
L"(!IS_TELEPHONE_COUNTRYCODE)",
L"(!IS_TELEPHONE_AREACODE)",
L"(!IS_TELEPHONE_LOCALNUMBER)",
L"(!IS_TIME_FULLTIME)",
L"(!IS_TIME_HOUR)",
L"(!IS_TIME_MINORSEC)",
L"((0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?-? ?)?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?-? ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9) ?(0|1|2|3|4|5|6|7|8|9)",
L"(!IS_PERSONALNAME_FULLNAME)|((!IS_PERSONALNAME_PREFIX)? +(!IS_PERSONALNAME_GIVENNAME)+ +(!IS_PERSONALNAME_MIDDLENAME)* +(!IS_PERSONALNAME_SURNAME)+)",
L"MN(0|1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(A|B)(!IS_DIGITS)(X|Y)((0|1)*)"
};
const LONG gc_lMaxInputScopeMenuItemLength = 40;
// 定义笔势常量
const InkApplicationGesture gc_igtSingleStrokeGestures[] = {
IAG_Scratchout, IAG_Triangle, IAG_Square, IAG_Star, IAG_Check,
IAG_Circle, IAG_DoubleCircle, IAG_Curlicue, IAG_DoubleCurlicue,
IAG_SemiCircleLeft, IAG_SemiCircleRight,
IAG_ChevronUp, IAG_ChevronDown, IAG_ChevronLeft,
IAG_ChevronRight, IAG_Up, IAG_Down, IAG_Left, IAG_Right, IAG_UpDown, IAG_DownUp,
IAG_LeftRight, IAG_RightLeft, IAG_UpLeftLong, IAG_UpRightLong, IAG_DownLeftLong,
IAG_DownRightLong, IAG_UpLeft, IAG_UpRight, IAG_DownLeft, IAG_DownRight, IAG_LeftUp,
IAG_LeftDown, IAG_RightUp, IAG_RightDown, IAG_Tap
};
const UINT gc_nRecommendedForMixedMode[] = {
0 /*Scratchout*/, 3/*Star*/, 6/*Double Circle*/,
7 /*Curlicue*/, 8 /*Double Curlicue*/, 25 /*Down-Left Long*/ };
const InkApplicationGesture gc_igtMultiStrokeGestures[] = {
IAG_ArrowUp, IAG_ArrowDown, IAG_ArrowLeft,
IAG_ArrowRight, IAG_Exclamation, IAG_DoubleTap
};
const _ATL_FUNC_INFO IInkRecognitionEventsImpl<CAdvRecoApp>::mc_AtlFuncInfo =
{CC_STDCALL, VT_EMPTY, 3, {VT_UNKNOWN, VT_VARIANT, VT_I4}};
const _ATL_FUNC_INFO IInkCollectorEventsImpl<CAdvRecoApp>::mc_AtlFuncInfo[2] = {
{CC_STDCALL, VT_EMPTY, 3, {VT_UNKNOWN, VT_UNKNOWN, VT_BOOL|VT_BYREF}},
{CC_STDCALL, VT_EMPTY, 4, {VT_UNKNOWN, VT_UNKNOWN, VT_VARIANT, VT_BOOL|VT_BYREF}}
};
const TCHAR gc_szAppName[] = TEXT("CSDN专家尹成的程序,http://blog.csdn.net/yincheng01");
/////////////////////////////////////////////////////////
//
//清除Com指针
/////////////////////////////////////////////////////////
void Cinkdoc::CleanUp() // Release all objects
{
if (g_pIInkRecoContext != NULL)
{
g_pIInkRecoContext->Release();
g_pIInkRecoContext = NULL;
}
if (g_pIInkDisp != NULL)
{
g_pIInkDisp->Release();
g_pIInkDisp = NULL;
}
if (g_pIInkCollector != NULL)
{
g_pIInkCollector->Release();
g_pIInkCollector = NULL;
}
}
void Cinkdoc::Reco() //识别
{
//获取识别结果,并显示最优化识别结果
HCURSOR hCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
//获取轨迹指针用于识别
IInkStrokes* pIInkStrokes = NULL;
HRESULT hr = g_pIInkDisp->get_Strokes(&pIInkStrokes);
if (SUCCEEDED(hr))
{
hr = g_pIInkRecoContext->putref_Strokes(pIInkStrokes);
if (SUCCEEDED(hr))
{ //利用识别指针获取识别结果
IInkRecognitionResult* pIInkRecoResult = NULL;
InkRecognitionStatus RecognitionStatus;
hr = g_pIInkRecoContext->Recognize(&RecognitionStatus, &pIInkRecoResult);
if (SUCCEEDED(hr) && (pIInkRecoResult!= NULL))
{
BSTR bstrBestResult = NULL;
hr = pIInkRecoResult->get_TopString(&bstrBestResult);
pIInkRecoResult->Release();
pIInkRecoResult = NULL;
if (SUCCEEDED(hr) && bstrBestResult)
{
MessageBoxW(hwnd, bstrBestResult,
L"识别结果", MB_OK);
SysFreeString(bstrBestResult);
}
}
g_pIInkRecoContext->putref_Strokes(NULL);
}
pIInkStrokes->Release();
}
::SetCursor(hCursor);
}
void Cinkdoc::start() // 开始创建
{
//并创建com指针接口
HRESULT hr;
hr = CoCreateInstance(CLSID_InkRecognizerContext,
NULL, CLSCTX_INPROC_SERVER,
IID_IInkRecognizerContext,
(void **) &g_pIInkRecoContext);
if (FAILED(hr))
{
return -1;
}
hr = CoCreateInstance(CLSID_InkCollector,
NULL, CLSCTX_INPROC_SERVER,
IID_IInkCollector,
(void **) &g_pIInkCollector);
if (FAILED(hr))
return -1;
hr = g_pIInkCollector->get_Ink(&g_pIInkDisp);
if (FAILED(hr))
return -1;
hr = g_pIInkCollector->put_hWnd((long)this->hwnd);
if (FAILED(hr))
return -1;
hr = g_pIInkCollector->put_Enabled(VARIANT_TRUE);
if (FAILED(hr))
return -1;
}
//笔势事件
HRESULT Cinkdoc::OnGesture(
IInkCursor* /*pIInkCursor*/,
IInkStrokes* pInkStrokes,
VARIANT vGestures,
VARIANT_BOOL* pbCancel
)
{
if (((VT_ARRAY | VT_DISPATCH) != vGestures.vt) || (NULL == vGestures.parray))
return E_INVALIDARG;
if (0 == vGestures.parray->rgsabound->cElements)
return E_INVALIDARG;
/ /数组中的手势应该是排序的承认
/ /置信水平。此示例拿起最高之一。
/ /注意:当在InkAndGesture收集模式,除了预期的手势
/ /应用程序也有可能是带着身份证IAG_NoGesture手势对象
/ /此应用程序时,如果取消与ISG_NoGesture对象
/ /最高水平的信心数组(第一项)。
InkApplicationGesture idGesture = IAG_NoGesture;
IDispatch** ppIDispatch;
HRESULT hr = ::SafeArrayAccessData(vGestures.parray, (void HUGEP**)&ppIDispatch);
if (SUCCEEDED(hr))
{
CComQIPtr<IInkGesture> spIInkGesture(ppIDispatch[0]);
if (spIInkGesture != NULL)
{
hr = spIInkGesture->get_Id(&idGesture);
}
::SafeArrayUnaccessData(vGestures.parray);
}
/ /加载资源字符串表的姿态名称
UINT idGestureName;
bool bAccepted; // will be true, if the gesture is known to this application
if (IAG_NoGesture != idGesture)
{
bAccepted = GetGestureName(idGesture, idGestureName);
}
else
{
bAccepted = false;
idGestureName = 0;
}
//如果当前的收集模式ICM_GestureOnly或者如果我们接受
//的姿态,手势的中风将被删除从墨迹对象,
//因此,窗口需要在招'区更新。
if (ID_MODE_GESTURES == m_nCmdMode || true == bAccepted)
{
// Get the rectangle to update.
RECT rc;
CComPtr<IInkRectangle> spIInkRect;
if (m_spIInkRenderer != NULL
&& pInkStrokes != NULL
&& SUCCEEDED(pInkStrokes->GetBoundingBox(IBBM_Default, &spIInkRect))
&& SUCCEEDED(spIInkRect->GetRectangle(&rc.top, &rc.left,
&rc.bottom, &rc.right)))
{
HDC hdc = m_wndInput.GetDC();
if (NULL != hdc)
{
if (FAILED(m_spIInkRenderer->InkSpaceToPixel((long)hdc, &rc.left, &rc.top))
|| FAILED(m_spIInkRenderer->InkSpaceToPixel((long)hdc, &rc.right,
&rc.bottom)))
{
m_wndInput.GetClientRect(&rc);
}
ReleaseDC(hdc);
}
else
{
m_wndInput.GetClientRect(&rc);
}
}
else
{
m_wndInput.GetClientRect(&rc);
}
m_wndInput.InvalidateRect(&rc);
}
else // if something's failed,
{
*pbCancel = VARIANT_TRUE;
idGestureName = IDS_GESTURE_UNKNOWN;
}
m_wndResults.SetGestureName(idGestureName);
m_wndResults.Invalidate();
return hr;
}
// Recognition event handlers 识别器事件
HRESULT Cinkdoc::OnRecognitionWithAlternates(
IInkRecognitionResult* pIInkRecoResult,
VARIANT /*vCustomParam*/,
InkRecognitionStatus /*RecognitionStatus*/
)
{
if (NULL == pIInkRecoResult)
return E_INVALIDARG;
m_wndResults.ResetResults();
// Get the best lCount results
HRESULT hr;
CComPtr<IInkRecognitionAlternates> spIInkRecoAlternates;
hr = pIInkRecoResult->AlternatesFromSelection(
0,
-1,
CRecoOutputWnd::mc_iNumResults,
&spIInkRecoAlternates
);
LONG lCount = 0;
if (SUCCEEDED(hr) && SUCCEEDED(spIInkRecoAlternates->get_Count(&lCount)))
{
IInkRecognitionAlternate* pIInkRecoAlternate = NULL;
for (LONG iItem = 0; (iItem < lCount) && (iItem < CRecoOutputWnd::mc_iNumResults); iItem++)
{
if (SUCCEEDED(spIInkRecoAlternates->Item(iItem, &pIInkRecoAlternate)))
{
BSTR bstr = NULL;
if (SUCCEEDED(pIInkRecoAlternate->get_String(&bstr)))
{
m_wndResults.m_bstrResults[iItem].Attach(bstr);
}
pIInkRecoAlternate->Release();
}
}
}
// Update the output window with the new results
m_wndResults.Invalidate();
return S_OK;
}
//识别结果获取
LRESULT Cinkdoc::OnRecognizer(
WORD /*wNotifyCode*/,
WORD wID,
HWND /*hWndCtl*/,
BOOL& /*bHandled*/
)
{
if (m_spIInkRecognizers == NULL || wID == m_nCmdRecognizer)
return 0;
HRESULT hr;
CComPtr<IInkRecognizer> spIInkRecognizer;
if (ID_RECOGNIZER_DEFAULT == wID)
{
hr = m_spIInkRecognizers->GetDefaultRecognizer(0, &spIInkRecognizer);//获取默认识别器设置之
}
else
{
hr = m_spIInkRecognizers->Item(wID - ID_RECOGNIZER_FIRST, &spIInkRecognizer);//否则获取第一个识别器设置之
}
if (SUCCEEDED(hr) && UseRecognizer(spIInkRecognizer))
{
UpdateMenuRadioItems(mc_iSubmenuRecognizers, wID, m_nCmdRecognizer);
m_bstrCurRecoName.Empty();
spIInkRecognizer->get_Name(&m_bstrCurRecoName);
UpdateStatusBar();
m_nCmdRecognizer = wID;
}
return 0;
}
//输入获取
LRESULT Cinkdoc::OnInputScopeCoerce(
WORD /*wNotifyCode*/,
WORD wID,
HWND /*hWndCtl*/,
BOOL& /*bHandled*/
)
{
if (m_spIInkRecoContext == NULL )
return 0;
if (m_spIInkStrokes != NULL)
{
m_spIInkRecoContext->putref_Strokes(NULL);
}
if (FAILED(m_spIInkRecoContext->put_RecognitionFlags (m_bCoerceInputScope?IRM_None:IRM_Coerce)))
{
MessageBox(TEXT("获取结果失败!"),
gc_szAppName, MB_ICONERROR | MB_OK);
// Re-attach the stroke collection to the context
if (m_spIInkStrokes != NULL)
{
m_spIInkRecoContext->putref_Strokes(m_spIInkStrokes);
}
return 0;
}
m_bCoerceInputScope = !m_bCoerceInputScope;
// 收集笔迹
if (m_spIInkStrokes != NULL)
{
m_spIInkRecoContext->putref_Strokes(m_spIInkStrokes);
}
// 更新识别结果
CComVariant vCustomData; // no custom data
m_spIInkRecoContext->BackgroundRecognizeWithAlternates(vCustomData);
return 0;
}
Ribbon多文档程序代码如下
#include "stdafx.h"
#include "CalendarBar.h"
#include "inkdoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const int nBorderSize = 10;
/////////////////////////////////////////////////////////////////////////////
// CCalendarBar
CCalendarBar::CCalendarBar()
{
m_nMyCalendarsY = 0;
}
CCalendarBar::~CCalendarBar()
{
}
BEGIN_MESSAGE_MAP(CCalendarBar, CWnd)
ON_WM_CREATE()
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_SETTINGCHANGE()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalendarBar 消息处理程序
int CCalendarBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rectDummy(0, 0, 0, 0);
m_wndCalendar.Create(WS_CHILD | WS_VISIBLE, rectDummy, this, 1);
CBitmap bmp;
bmp.LoadBitmap(IDB_PAGES_SMALL_HC);
m_Images.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 0);
m_Images.Add(&bmp, RGB(255, 0, 255));
return 0;
}
BOOL CCalendarBar::OnEraseBkgnd(CDC* /*pDC*/)
{
return TRUE;
}
void CCalendarBar::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
int nMyCalendarsHeight = 70;
if (m_wndCalendar.GetSafeHwnd() != NULL)
{
m_wndCalendar.SetWindowPos(NULL, nBorderSize, nBorderSize, cx - 2 * nBorderSize, cy - 2 * nBorderSize - nMyCalendarsHeight - 10, SWP_NOZORDER | SWP_NOACTIVATE);
}
m_nMyCalendarsY = cy - nMyCalendarsHeight;
}
BOOL CCalendarBar::Create(const RECT& rect, CWnd* pParentWnd, UINT nID)
{
return CWnd::Create(NULL, _T(""), WS_CHILD | WS_VISIBLE, rect, pParentWnd, nID);
}
void CCalendarBar::OnPaint()
{
CPaintDC dc(this); // 用于绘制的设备上下文
CRect rectClient;
GetClientRect(rectClient);
dc.FillRect(rectClient, &afxGlobalData.brWindow);
if (rectClient.bottom - m_nMyCalendarsY > 0)
{
CRect rectMyCalendarsCaption = rectClient;
rectMyCalendarsCaption.top = m_nMyCalendarsY;
rectMyCalendarsCaption.bottom = rectMyCalendarsCaption.top + afxGlobalData.GetTextHeight(TRUE) * 3 / 2;
COLORREF clrText = CMFCVisualManager::GetInstance()->OnDrawPaneCaption(&dc, NULL, FALSE, rectMyCalendarsCaption, CRect(0, 0, 0, 0));
CPen* pOldPen = dc.SelectObject(&afxGlobalData.penBarShadow);
dc.MoveTo(rectMyCalendarsCaption.left - 1, rectMyCalendarsCaption.top);
dc.LineTo(rectMyCalendarsCaption.right, rectMyCalendarsCaption.top);
dc.SelectStockObject(BLACK_PEN);
dc.MoveTo(rectMyCalendarsCaption.left - 1, rectMyCalendarsCaption.bottom);
dc.LineTo(rectMyCalendarsCaption.right, rectMyCalendarsCaption.bottom);
dc.SelectObject(pOldPen);
CRect rectText = rectMyCalendarsCaption;
rectText.DeflateRect(10, 0);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(clrText);
CFont* pOldFont = dc.SelectObject(&afxGlobalData.fontRegular);
BOOL bNameValid;
CString str;
bNameValid = str.LoadString(IDS_MYCALENDARS);
ASSERT(bNameValid);
dc.DrawText(str, rectText, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
CRect rectCalendar = rectClient;
rectCalendar.top = rectMyCalendarsCaption.bottom + 5;
rectCalendar.bottom = rectCalendar.top + afxGlobalData.GetTextHeight(TRUE) * 3 / 2 - 5;
dc.FillSolidRect(rectCalendar, RGB(255, 255, 213));
rectCalendar.DeflateRect(20, 0);
m_Images.Draw(&dc, 3, rectCalendar.TopLeft(), 0);
rectCalendar.left += 20;
bNameValid = str.LoadString(IDS_CALENDAR);
ASSERT(bNameValid);
dc.SetTextColor(afxGlobalData.clrHotLinkNormalText);
dc.DrawText(str, rectCalendar, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
dc.SelectObject(pOldFont);
}
}
// 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
// (“Fluent UI”)。该示例仅供参考,
// 用以补充《Microsoft 基础类参考》和
// MFC C++ 库软件随附的相关电子文档。
// 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
// 若要了解有关 Fluent UI 许可计划的详细信息,请访问
// http://msdn.microsoft.com/officeui。
//
// 版权所有(C) Microsoft Corporation
// 保留所有权利。
// inkdoc.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "afxwinappex.h"
#include "inkdoc.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "inkdocDoc.h"
#include "inkdocView.h"
#include "CShockwaveFlash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CinkdocApp
BEGIN_MESSAGE_MAP(CinkdocApp, CWinAppEx)
ON_COMMAND(ID_APP_ABOUT, &CinkdocApp::OnAppAbout)
// 基于文件的标准文档命令
ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
END_MESSAGE_MAP()
// CinkdocApp 构造
CinkdocApp::CinkdocApp()
{
m_bHiColorIcons = TRUE;
// 支持重新启动管理器
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
#ifdef _MANAGED
// 如果应用程序是利用公共语言运行时支持(/clr)构建的,则:
// 1) 必须有此附加设置,“重新启动管理器”支持才能正常工作。
// 2) 在您的项目中,您必须按照生成顺序向 System.Windows.Forms 添加引用。
System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
#endif
// TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式
//为 CompanyName.ProductName.SubProduct.VersionInformation
SetAppID(_T("inkdoc.AppID.NoVersion"));
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的一个 CinkdocApp 对象
CinkdocApp theApp;
// CinkdocApp 初始化
BOOL CinkdocApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinAppEx::InitInstance();
// 初始化 OLE 库
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
EnableTaskbarInteraction();
// 使用 RichEdit 控件需要 AfxInitRichEdit2()
// AfxInitRichEdit2();
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
InitContextMenuManager();
InitShellManager();
InitKeyboardManager();
InitTooltipManager();
CMFCToolTipInfo ttParams;
ttParams.m_bVislManagerTheme = TRUE;
theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
// 注册应用程序的文档模板。文档模板
// 将用作文档、框架窗口和视图之间的连接
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_inkdocTYPE,
RUNTIME_CLASS(CinkdocDoc),
RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
RUNTIME_CLASS(CinkdocView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
// 创建主 MDI 框架窗口
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
{
delete pMainFrame;
return FALSE;
}
m_pMainWnd = pMainFrame;
// 仅当具有后缀时才调用 DragAcceptFiles
// 在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生
// 启用拖/放
m_pMainWnd->DragAcceptFiles();
// 分析标准 shell 命令、DDE、打开文件操作的命令行
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// 启用“DDE 执行”
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// 调度在命令行中指定的命令。如果
// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// 主窗口已初始化,因此显示它并对其进行更新
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
return TRUE;
}
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// 用于运行对话框的应用程序命令
void CinkdocApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
// CinkdocApp 自定义加载/保存方法
void CinkdocApp::PreLoadState()
{
BOOL bNameValid;
CString strName;
bNameValid = strName.LoadString(IDS_EDIT_MENU);
ASSERT(bNameValid);
GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
}
void CinkdocApp::LoadCustomState()
{
}
void CinkdocApp::SaveCustomState()
{
}
// CinkdocApp 消息处理程序
// 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
// (“Fluent UI”)。该示例仅供参考,
// 用以补充《Microsoft 基础类参考》和
// MFC C++ 库软件随附的相关电子文档。
// 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
// 若要了解有关 Fluent UI 许可计划的详细信息,请访问
// http://msdn.microsoft.com/officeui。
//
// 版权所有(C) Microsoft Corporation
// 保留所有权利。
// inkdocDoc.cpp : CinkdocDoc 类的实现
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "inkdoc.h"
#endif
#include "inkdocDoc.h"
#include <propkey.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CinkdocDoc
IMPLEMENT_DYNCREATE(CinkdocDoc, CDocument)
BEGIN_MESSAGE_MAP(CinkdocDoc, CDocument)
END_MESSAGE_MAP()
// CinkdocDoc 构造/析构
CinkdocDoc::CinkdocDoc()
{
// TODO: 在此添加一次性构造代码
}
CinkdocDoc::~CinkdocDoc()
{
}
BOOL CinkdocDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: 在此添加重新初始化代码
// (SDI 文档将重用该文档)
return TRUE;
}
// CinkdocDoc 序列化
void CinkdocDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: 在此添加存储代码
}
else
{
// TODO: 在此添加加载代码
}
}
#ifdef SHARED_HANDLERS
// 缩略图的支持
void CinkdocDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
// 修改此代码以绘制文档数据
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
CString strText = _T("TODO: implement thumbnail drawing here");
LOGFONT lf;
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
pDefaultGUIFont->GetLogFont(&lf);
lf.lfHeight = 36;
CFont fontDraw;
fontDraw.CreateFontIndirect(&lf);
CFont* pOldFont = dc.SelectObject(&fontDraw);
dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
dc.SelectObject(pOldFont);
}
// 搜索处理程序的支持
void CinkdocDoc::InitializeSearchContent()
{
CString strSearchContent;
// 从文档数据设置搜索内容。
// 内容部分应由“;”分隔
// 例如: strSearchContent = _T("point;rectangle;circle;ole object;");
SetSearchContent(strSearchContent);
}
void CinkdocDoc::SetSearchContent(const CString& value)
{
if (value.IsEmpty())
{
RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
}
else
{
CMFCFilterChunkValueImpl *pChunk = NULL;
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
if (pChunk != NULL)
{
pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
SetChunkValue(pChunk);
}
}
}
#endif // SHARED_HANDLERS
// CinkdocDoc 诊断
#ifdef _DEBUG
void CinkdocDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CinkdocDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// CinkdocDoc 命令
// 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
// (“Fluent UI”)。该示例仅供参考,
// 用以补充《Microsoft 基础类参考》和
// MFC C++ 库软件随附的相关电子文档。
// 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
// 若要了解有关 Fluent UI 许可计划的详细信息,请访问
// http://msdn.microsoft.com/officeui。
//
// 版权所有(C) Microsoft Corporation
// 保留所有权利。
// inkdocView.cpp : CinkdocView 类的实现
//
#include "stdafx.h"
#include"CShockwaveFlash.h"
#include"shockwaveflash1.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "inkdoc.h"
#endif
#include "inkdocDoc.h"
#include "inkdocView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CinkdocView
IMPLEMENT_DYNCREATE(CinkdocView, CFormView)
BEGIN_MESSAGE_MAP(CinkdocView, CFormView)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_EN_CHANGE(IDC_RICHEDIT21, &CinkdocView::OnEnChangeRichedit21)
ON_COMMAND(ID_BUTTON3, &CinkdocView::OnButton3)
END_MESSAGE_MAP()
CinkdocView::CinkdocView()
: CFormView(CinkdocView::IDD)
{
// TODO: 在此处添加构造代码
AfxInitRichEdit2();
}
CinkdocView::~CinkdocView()
{
}
void CinkdocView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
}
BOOL CinkdocView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CFormView::PreCreateWindow(cs);
}
void CinkdocView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ResizeParentToFit();
}
void CinkdocView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CinkdocView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CinkdocView 诊断
#ifdef _DEBUG
void CinkdocView::AssertValid() const
{
CFormView::AssertValid();
}
void CinkdocView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CinkdocDoc* CinkdocView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CinkdocDoc)));
return (CinkdocDoc*)m_pDocument;
}
#endif //_DEBUG
// CinkdocView 消息处理程序
void CinkdocView::OnEnChangeRichedit21()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CFormView::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CinkdocView::OnButton3()
{
MessageBox(TEXT("CSDN著名技术专家尹成的杰作http://blog.csdn.net/yincheng01"), TEXT("WindowsRibbon范例"), MB_OK);
}
BOOL CinkdocView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
// 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
// (“Fluent UI”)。该示例仅供参考,
// 用以补充《Microsoft 基础类参考》和
// MFC C++ 库软件随附的相关电子文档。
// 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
// 若要了解有关 Fluent UI 许可计划的详细信息,请访问
// http://msdn.microsoft.com/officeui。
//
// 版权所有(C) Microsoft Corporation
// 保留所有权利。
// MainFrm.cpp : CMainFrame 类的实现
//
#include "stdafx.h"
#include "inkdoc.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWndEx)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx)
ON_WM_CREATE()
ON_COMMAND(ID_WINDOW_MANAGER, &CMainFrame::OnWindowManager)
ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnApplicationLook)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnUpdateApplicationLook)
ON_COMMAND(ID_VIEW_CAPTION_BAR, &CMainFrame::OnViewCaptionBar)
ON_UPDATE_COMMAND_UI(ID_VIEW_CAPTION_BAR, &CMainFrame::OnUpdateViewCaptionBar)
ON_COMMAND(ID_TOOLS_OPTIONS, &CMainFrame::OnOptions)
ON_COMMAND(ID_BUTTON2, &CMainFrame::OnButton2)
ON_COMMAND(ID_BUTTON31, &CMainFrame::OnButton31)
ON_COMMAND(ID_BUTTON4, &CMainFrame::OnButton4)
ON_COMMAND(ID_BUTTON5, &CMainFrame::OnButton5)
ON_COMMAND(ID_BUTTON6, &CMainFrame::OnButton6)
ON_COMMAND(ID_BUTTON7, &CMainFrame::OnButton7)
ON_COMMAND(ID_BUTTON8, &CMainFrame::OnButton8)
ON_COMMAND(ID_BUTTON9, &CMainFrame::OnButton9)
END_MESSAGE_MAP()
// CMainFrame 构造/析构
CMainFrame::CMainFrame()
{
// TODO: 在此添加成员初始化代码
theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_WINDOWS_7);
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
BOOL bNameValid;
// 基于持久值设置视觉管理器和样式
OnApplicationLook(theApp.m_nAppLook);
CMDITabInfo mdiTabParams;
mdiTabParams.m_style = CMFCTabCtrl::STYLE_3D_ONENOTE; // 其他可用样式...
mdiTabParams.m_bActiveTabCloseButton = TRUE; // 设置为 FALSE 会将关闭按钮放置在选项卡区域的右侧
mdiTabParams.m_bTabIcons = FALSE; // 设置为 TRUE 将在 MDI 选项卡上启用文档图标
mdiTabParams.m_bAutoColor = TRUE; // 设置为 FALSE 将禁用 MDI 选项卡的自动着色
mdiTabParams.m_bDocumentMenu = TRUE; // 在选项卡区域的右边缘启用文档菜单
EnableMDITabbedGroups(TRUE, mdiTabParams);
m_wndRibbonBar.Create(this);
m_wndRibbonBar.LoadFromResource(IDR_RIBBON);
if (!m_wndStatusBar.Create(this))
{
TRACE0("未能创建状态栏/n");
return -1; // 未能创建
}
CString strTitlePane1;
CString strTitlePane2;
bNameValid = strTitlePane1.LoadString(IDS_STATUS_PANE1);
ASSERT(bNameValid);
bNameValid = strTitlePane2.LoadString(IDS_STATUS_PANE2);
ASSERT(bNameValid);
m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE1, strTitlePane1, TRUE), strTitlePane1);
m_wndStatusBar.AddExtendedElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE2, strTitlePane2, TRUE), strTitlePane2);
// 启用 Visual Studio 2005 样式停靠窗口行为
CDockingManager::SetDockingMode(DT_SMART);
// 启用 Visual Studio 2005 样式停靠窗口自动隐藏行为
EnableAutoHidePanes(CBRS_ALIGN_ANY);
// 导航窗格将创建在左侧,因此将暂时禁用左侧的停靠:
EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM | CBRS_ALIGN_RIGHT);
// 创建并设置“Outlook”导航栏:
if (!CreateOutlookBar(m_wndNavigationBar, ID_VIEW_NAVIGATION, m_wndTree, m_wndCalendar, 250))
{
TRACE0("未能创建导航窗格/n");
return -1; // 未能创建
}
// 创建标题栏:
if (!CreateCaptionBar())
{
TRACE0("未能创建标题栏/n");
return -1; // 未能创建
}
// 已创建 Outlook 栏,应允许在左侧停靠。
EnableDocking(CBRS_ALIGN_LEFT);
EnableAutoHidePanes(CBRS_ALIGN_RIGHT);
// 启用增强的窗口管理对话框
EnableWindowsDialog(ID_WINDOW_MANAGER, ID_WINDOW_MANAGER, TRUE);
// 将文档名和应用程序名称在窗口标题栏上的顺序进行交换。这
// 将改进任务栏的可用性,因为显示的文档名带有缩略图。
ModifyStyle(0, FWS_PREFIXTITLE);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWndEx::PreCreateWindow(cs) )
return FALSE;
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE | WS_SYSMENU;
return TRUE;
}
BOOL CMainFrame::CreateOutlookBar(CMFCOutlookBar& bar, UINT uiID, CMFCShellTreeCtrl& tree, CCalendarBar& calendar, int nInitialWidth)
{
bar.SetMode2003();
BOOL bNameValid;
CString strTemp;
bNameValid = strTemp.LoadString(IDS_SHORTCUTS);
ASSERT(bNameValid);
if (!bar.Create(strTemp, this, CRect(0, 0, nInitialWidth, 32000), uiID, WS_CHILD | WS_VISIBLE | CBRS_LEFT))
{
return FALSE; // 未能创建
}
CMFCOutlookBarTabCtrl* pOutlookBar = (CMFCOutlookBarTabCtrl*)bar.GetUnderlyingWindow();
if (pOutlookBar == NULL)
{
ASSERT(FALSE);
return FALSE;
}
pOutlookBar->EnableInPlaceEdit(TRUE);
static UINT uiPageID = 1;
// 可浮动,可自动隐藏,可调整大小,但不能关闭
DWORD dwStyle = AFX_CBRS_FLOAT | AFX_CBRS_AUTOHIDE | AFX_CBRS_RESIZE;
CRect rectDummy(0, 0, 0, 0);
const DWORD dwTreeStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
tree.Create(dwTreeStyle, rectDummy, &bar, 1200);
bNameValid = strTemp.LoadString(IDS_FOLDERS);
ASSERT(bNameValid);
pOutlookBar->AddControl(&tree, strTemp, 2, TRUE, dwStyle);
calendar.Create(rectDummy, &bar, 1201);
bNameValid = strTemp.LoadString(IDS_CALENDAR);
ASSERT(bNameValid);
pOutlookBar->AddControl(&calendar, strTemp, 3, TRUE, dwStyle);
bar.SetPaneStyle(bar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
pOutlookBar->SetImageList(theApp.m_bHiColorIcons ? IDB_PAGES_HC : IDB_PAGES, 24);
pOutlookBar->SetToolbarImageList(theApp.m_bHiColorIcons ? IDB_PAGES_SMALL_HC : IDB_PAGES_SMALL, 16);
pOutlookBar->RecalcLayout();
BOOL bAnimation = theApp.GetInt(_T("OutlookAnimation"), TRUE);
CMFCOutlookBarTabCtrl::EnableAnimation(bAnimation);
bar.SetButtonsFont(&afxGlobalData.fontBold);
return TRUE;
}
BOOL CMainFrame::CreateCaptionBar()
{
if (!m_wndCaptionBar.Create(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, this, ID_VIEW_CAPTION_BAR, -1, TRUE))
{
TRACE0("未能创建标题栏/n");
return FALSE;
}
BOOL bNameValid;
CString strTemp, strTemp2;
bNameValid = strTemp.LoadString(IDS_CAPTION_BUTTON);
ASSERT(bNameValid);
m_wndCaptionBar.SetButton(strTemp, ID_TOOLS_OPTIONS, CMFCCaptionBar::ALIGN_LEFT, FALSE);
bNameValid = strTemp.LoadString(IDS_CAPTION_BUTTON_TIP);
ASSERT(bNameValid);
m_wndCaptionBar.SetButtonToolTip(strTemp);
bNameValid = strTemp.LoadString(IDS_CAPTION_TEXT);
ASSERT(bNameValid);
m_wndCaptionBar.SetText(strTemp, CMFCCaptionBar::ALIGN_LEFT);
m_wndCaptionBar.SetBitmap(IDB_INFO, RGB(255, 255, 255), FALSE, CMFCCaptionBar::ALIGN_LEFT);
bNameValid = strTemp.LoadString(IDS_CAPTION_IMAGE_TIP);
ASSERT(bNameValid);
bNameValid = strTemp2.LoadString(IDS_CAPTION_IMAGE_TEXT);
ASSERT(bNameValid);
m_wndCaptionBar.SetImageToolTip(strTemp, strTemp2);
return TRUE;
}
// CMainFrame 诊断
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWndEx::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWndEx::Dump(dc);
}
#endif //_DEBUG
// CMainFrame 消息处理程序
void CMainFrame::OnWindowManager()
{
ShowWindowsDialog();
}
void CMainFrame::OnApplicationLook(UINT id)
{
CWaitCursor wait;
theApp.m_nAppLook = id;
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_WIN_2000:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager));
m_wndRibbonBar.SetWindows7Look(FALSE);
break;
case ID_VIEW_APPLOOK_OFF_XP:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
m_wndRibbonBar.SetWindows7Look(FALSE);
break;
case ID_VIEW_APPLOOK_WIN_XP:
CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
m_wndRibbonBar.SetWindows7Look(FALSE);
break;
case ID_VIEW_APPLOOK_OFF_2003:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
CDockingManager::SetDockingMode(DT_SMART);
m_wndRibbonBar.SetWindows7Look(FALSE);
break;
case ID_VIEW_APPLOOK_VS_2005:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
CDockingManager::SetDockingMode(DT_SMART);
m_wndRibbonBar.SetWindows7Look(FALSE);
break;
case ID_VIEW_APPLOOK_VS_2008:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008));
CDockingManager::SetDockingMode(DT_SMART);
m_wndRibbonBar.SetWindows7Look(FALSE);
break;
case ID_VIEW_APPLOOK_WINDOWS_7:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
CDockingManager::SetDockingMode(DT_SMART);
m_wndRibbonBar.SetWindows7Look(TRUE);
break;
default:
switch (theApp.m_nAppLook)
{
case ID_VIEW_APPLOOK_OFF_2007_BLUE:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
break;
case ID_VIEW_APPLOOK_OFF_2007_BLACK:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
break;
case ID_VIEW_APPLOOK_OFF_2007_SILVER:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
break;
case ID_VIEW_APPLOOK_OFF_2007_AQUA:
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
break;
}
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
CDockingManager::SetDockingMode(DT_SMART);
m_wndRibbonBar.SetWindows7Look(FALSE);
}
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
}
void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
}
void CMainFrame::OnViewCaptionBar()
{
m_wndCaptionBar.ShowWindow(m_wndCaptionBar.IsVisible() ? SW_HIDE : SW_SHOW);
RecalcLayout(FALSE);
}
void CMainFrame::OnUpdateViewCaptionBar(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_wndCaptionBar.IsVisible());
}
void CMainFrame::OnOptions()
{
CMFCRibbonCustomizeDialog *pOptionsDlg = new CMFCRibbonCustomizeDialog(this, &m_wndRibbonBar);
ASSERT(pOptionsDlg != NULL);
pOptionsDlg->DoModal();
delete pOptionsDlg;
}
如果需要工程源码,请本人CSDN博客留言留下email!
本文作者专著《Visual C++2010开发权威指南》即将推出,敬请关注,Visual C++2010最近技术,Windows7开发最新技术!