MFC之控件扩展

      MFC给程序员们提供了一个很强大的开发模板用于Windows编程,简单的界面创建方法更是方便了程序员。但是MFC提供的界面控件虽然挺多挺强大,但却不能满足某些功能的特殊需求。还好,C++的类继承机制和MFC精致的设计给我们带来了无限的发挥空间。

 

      1. CListCtrl 的扩展:

          CListCtrl控件不支持单元格的背景和字体颜色改变,单元格的编辑和下拉等功能。要完成这些需要程序员做一定的功能扩展,主要用到控件组合和GDI自绘。控件组合就是把一般的CEdit,CCombox等控件动态的加到CListCtrl单元格中。而自绘主要由用户扩充绘制函数,例如要在CListCtrl单元格中加入色块,色块后加入文字Caption,可以重载它的这个函数:

          CListCtrl::OnCustomDraw(..., ...)    {....代码同3例...}

 

      2. CGridCtrl控件是一个外国人所写的功能强大的报表控件。直接从CWnd类派生,自己管理单元格。

 

      3. 最近我所见到的对MFC控件扩展最深入的要算Xtreme Toolkit Pro了。Xtreme Toolkit Pro 为Windows开发人员提供了一个尖端技术的组件集来为你的应用程序提供一个专业的,现代化的外观。Xtreme Suite Pro组合了8种我们最受欢迎的组件, Xtreme CommandBar,Xtreme Docking Pane,Xtreme Property Grid,Xtreme Report Control,Xtreme Calendar,Xtreme Task Panel,Xtreme ShortcutBar和 Xtreme Controls。能运行在多种语言环境中。

           其中XTPButton按钮类的使用和一般的按钮扩展控件相同,直接把按钮变量声明为这种类型就行了。

           它的Xtreme Report Control控件中用到的单元格虽然能改变颜色,但是不能加色块后面再写文字。所以我们还得对它的单元格类进行扩展。例如我们可以这样改造:

           CXTPReportItem::OnDrawCaption(..., ....) {

           CRect& rect = pDrawArgs->rcItem;

           rect.DeflateRect(2,1,2,0); //对矩形缩放,以使色块显示在格子里面

           CXTPBrush brush(pDrawArgs->pDC, color);

           pDrawArgs->pDC->Rectangle(rect);

           CRect rt(rect);//使矩形再向右移动一些,写文字

           pDrawArgs->pDC->DrawText(...,...,...);  }

                      

 

 

     

一个功能强大的MFC界面处理扩展库:CJ60Lib 这是从网上搜集的一个扩展库,把它分享给大家! 简介: CJ60Lib是基于MFC基础之上的一个扩展库,主要是改进MFC的下述类: CCJButton - ( CJButton.cpp and CJButton.h )对CButton的改进。 CCJComboBox - ( CJComboBox.cpp and CJComboBox.h )对CComboBox的改进。 CCJControlBar - ( CJControlBar.cpp and CJControlBar.h )对CControlBar的改进。 CCJFrameWnd - ( CJFrameWnd.cpp and CJFrameWnd.h ) CCJMDIFrameWnd - ( CJMDIFrameWnd.cpp and CJMDIFrameWnd.h ) CCJDockBar - ( CJDockBar.cpp and CJDockBar.h ) 这些类重载了缺省的主框架布局,以增加3D效果到工具条。为了使用这些类,仅将 CFrameWnd 改为 CCJFrameWnd,其中,CMainFrame 包含在 Mainfrm.h文件中,(对于MDI,采用CCJMDIFrameWnd)。 CCJOutlookBar - ( CJOutlookBar.cpp and CJOutlookBar.h )新增类,用于实现Outlook中的工具条。 CCJPagerCtrl - ( CJPagerCtrl.cpp and CJPagerCtrl.h )新增类,用于设置标签视或者对话框。 CCJTabCtrlBar - ( CJTabCtrlBar.cpp and CJTabCtrlBar.h )新增类。 CCJToolBar - ( CJToolBar.cpp and CJToolBar.h )对CToolBar类的改进。 CCoolMenuManager -( CoolMenu.cpp, Emboss.cpp and CoolMenu.h ) CSubclassWnd -( Subclass.cpp and Subclass.h ) 新增类,用于改进已有的菜单。 CFlatToolBar - ( FlatBar.cpp and FlatBar.h ) Obsolete with VC 6.0 CModuleVersion - ( ModulVer.cpp and ModulVer.h ) 这是CCJToolBar的基类。 CCoolBar, CRebarInfo - ( CoolBar.cpp and CoolBar.h ) Obsolete with VC 6.0 新增类,用于实现Internet Explorer 4风格的工具条。 CHyperLink - ( HyperLink.cpp and HyperLink.h ) 超链接控件。 使用方法: 在Project Settings中选择General标签,Microsoft Foundation Class设置为 Use MFC in a shared DLL。 在Project Settings中选择Link标签,设置Category为Input,增加../Lib到Additional Library Path。 在Link标签中,改变Category为General,Output Name (所有配置)设置为../Lib。 选择C/C++标签,改变Category为Preprocessor,增加../Include到Additional Include Directories. 最后一步是添加下面两行代码到StdAfx.h头文件中: #define MFCX_PROJ #include 为了能静态链接到CJ60Lib,需要做下面修改: 在project settings对话框中,选择General标签,确保Microsoft Foundation Class设置为Use MFC in a static library。 添加下面代码到StdAfx.h 头文件,其将使库静态链接到应用程序: #define MFCXLIB_STATIC #define MFCX_PROJ #include
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值