您的位置:首页 > 其它

MFC MDI和SDI非客户区框架界面美化之----界面全面美化

2014-02-12 10:49 801 查看
VS2008以上的开发平台,微软提供了“视觉管理器和样式”这么一个概念,目前包含了XP、WIN7、OFFICE等不同的风格,如下所示:

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

case ID_VIEW_APPLOOK_OFF_XP:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP));
break;

case ID_VIEW_APPLOOK_WIN_XP:
CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE;
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
break;

case ID_VIEW_APPLOOK_OFF_2003:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003));
CDockingManager::SetDockingMode(DT_SMART);
break;

case ID_VIEW_APPLOOK_VS_2005:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
CDockingManager::SetDockingMode(DT_SMART);
break;

case ID_VIEW_APPLOOK_VS_2008:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008));
CDockingManager::SetDockingMode(DT_SMART);
break;

case ID_VIEW_APPLOOK_WINDOWS_7:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7));
CDockingManager::SetDockingMode(DT_SMART);
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);
}

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

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


就以CMFCVisualManagerOffice2007 风格为例,这个类提供了很强大的界面框架美化结构,包含到每一个按钮,每一个容器,甚至是每一个图标。但是很不幸,里面的样式内容微软进行了封装,不允许用户进行改变。但是与其我们一张一张贴图,重绘,废了半天劲,可能还达不到预期的效果,为什么不能模仿微软自带的样式进行继承一个新的界面库呢?

CMFCVisualManagerOffice2007 类的界面背景主要由OnFillBarBackground函数进行填充绘制,其他工具栏、菜单栏、状态栏等等的重绘都对应着一个类似的函数。颜色管理主要由OnUpdateSystemColors函数进行管理。进行编写界面库前,必须深入的了解CMFCVisualManagerOffice2007 类的工作原理,继承过程,消息机制等要点。其他其他VS自带样式类似,不管是CMFCVisualManagerOffice2007或者CMFCVisualManagerOffice2003或者XP都是继承一个基类来完成。如果了解了这些,编写一个对应的界面库就不成问题了吧!

1、DEMO具体操作:

1、新建类,基类为CMFCVisualManagerOffice2007。</p>

2、声明要继承的虚函数,如virtual void OnUpdateSystemColors();</p>
3、重写对应函数,如:实现标题栏TITLE居左或者居中,(PS:再也不用重绘标题栏了吧!)</p>
void TestStyle::OnUpdateSystemColors()
{
CMFCVisualManagerOffice2007::OnUpdateSystemColors();

CMFCVisualManagerOffice2007::m_bNcTextCenter = FALSE;//标题栏Title 居左。TRUE:居中
}
4、视觉管理器里更改样式</p>
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(TestStyle));
CDockingManager::SetDockingMode(DT_SMART);</pre>
5、类似的功能都可以进行重新进行继承封装。
6、CDrawingManager实现渐变色的绘制也是非常好的哦!</p>

美化效果:



例子下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: