• 1.1. 如何使用XproerUI库


     项目类型:MFC

     
    XproerUI结构:
    3rd                    第三方库目录
      cximage
        dll                编译的DLL目录
      pugixml-1.4         
        lib                编译的LIB目录
      zlib-1.2.8
        dll                编译的DLL目录
    XproerUI               UI引擎库目录
      dll                  编译的DLL目录
      Resource
      Xproer.Com
      Xproer.Drawing
      Xproer.Forms
      Xproer.Manager
      Xproer.UI
      Xproer.UI.Controls
      Xproer.UI.WinControls
     
    1.1.1.    下载相关资源
    boost-1.55.0-lib(VC100)360云盘(提取码 ef58),百度网盘,
     
    1.1.2.    设置头文件路径和链接库路径
    说明:建议将项目文件夹和XproerUI放在同级目录下
    示例结构:
    3rd           第三方库目录
    AppUI         XproerUI库目录
    AppUtils      Xproer工具库目录
    demo          自已的工程目录
     
    使用上面的目录结构可以直接使用下面的头文件和链接库配置代码(在Debug和Release模式下通用):
    头文件:
    .
    ..3rdpugixml-1.4src
    ..3rdcximageCxImage
    ..3rdzlib-1.2.8
    ..AppUtils
    合并:
    .;..3rdpugixml-1.4src;..3rdcximageCxImage;..3rdzlib-1.2.8;..AppUtils;
     
    链接库(MD):
    ..3rdpugixml-1.4lib$(ConfigurationName)
    ..3rdcximagedllUnicode $(ConfigurationName)
    ..3rdzlib-1.2.8dll$(ConfigurationName)
    ..AppUtils
    %(AdditionalLibraryDirectories)
    合并:
    ..3rdpugixml-1.4lib$(ConfigurationName);..3rdcximagedllUnicode $(ConfigurationName);..3rdzlib-1.2.8dll$(ConfigurationName);..AppUtilsdll$(ConfigurationName);%(AdditionalLibraryDirectories)
     
    附加包含目录截图:
    clip_image002
     
    链接器配置截图:
    clip_image004
     
    1.1.3.    在项目的stdafx.h中增加头文件
    XproerUI提供了UIHead.h文件,在项目中只需要包含此文件即可。
    // stdafx.h : 标准系统包含文件的包含文件,
    // 或是经常使用但不常更改的
    // 特定于项目的包含文件
     
    #pragmaonce
     
    #ifndefVC_EXTRALEAN
    #defineVC_EXTRALEAN            // 从 Windows 头中排除极少使用的资料
    #endif
     
    #include"targetver.h"
     
    #define_ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // 某些 CString 构造函数将是显式的
     
    // 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏
    #define_AFX_ALL_WARNINGS
     
    #include<afxwin.h>         // MFC 核心组件和标准组件
    #include<afxext.h>         // MFC 扩展
     
     
    #include<afxdisp.h>        // MFC 自动化类
     
     
     
    #ifndef _AFX_NO_OLE_SUPPORT
    #include<afxdtctl.h>           // MFC 对 Internet Explorer 4 公共控件的支持
    #endif
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include<afxcmn.h>             // MFC 对 Windows 公共控件的支持
    #endif// _AFX_NO_AFXCMN_SUPPORT
     
    #include<afxcontrolbars.h>     // 功能区和控件条的 MFC 支持
     
    #include"UIHead.h"
     
    #ifdef_UNICODE
    #ifdefined _M_IX86
    #pragmacomment(linker,"/manifestdependency:"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'"")
    #elifdefined _M_X64
    #pragmacomment(linker,"/manifestdependency:"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'"")
    #else
    #pragmacomment(linker,"/manifestdependency:"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'"")
    #endif
    #endif
    说明:在UIHead.h中自动包含了boost,AppUtils,XproerUI.lib,zlib,cximage,pugixml等文件和lib
    UIHead.h文件代码如下:
    #pragmawarning(disable:4150) //
    #pragmawarning(disable:4251) //
    #pragmawarning(disable:4275) //
     
    #include"afxtoolbar.h"
    #include"afxmenubar.h"
    #include"afxtoolbarmenubutton.h"
    #include<gdiplus.h>
    #include"Richole.h"
    #include"Richedit.h"
    #include"shellapi.h"
    #include"Usp10.h"
    #include<ctime>
    usingnamespaceGdiplus;
     
    #include"atlutil.h"
     
    #include<vector>
    #include<list>
    #include<map>
    #include<algorithm>
    #include<fstream>
    #include<iostream>
    #include<string>
    #include<array>
    #include<memory>
    usingnamespacestd;
     
    #include<boost/foreach.hpp>
    #include<boost/typeof/typeof.hpp>
    #include<boost/shared_array.hpp>
    #include<boost/smart_ptr.hpp>
    #include<boost/any.hpp>
    #include<boost/variant.hpp>
    #include<boost/bimap.hpp>
    #include<boost/filesystem.hpp>
    #include<boost/format.hpp>
    #include<boost/assert.hpp>
    #include<boost/assign.hpp>
    #include<boost/random.hpp>
    #include<boost/algorithm/string.hpp>
    #include<boost/pool/detail/singleton.hpp>
    #include<boost/date_time/gregorian/gregorian.hpp>
    #include<boost/date_time/posix_time/posix_time.hpp>
    #defineBOOST_ALL_NO_LIB
    #defineBOOST_DATE_TIME_SOURCE
    #defineforeachBOOST_FOREACH
    #definereverse_foreachBOOST_REVERSE_FOREACH
    usingnamespaceboost;
    usingnamespaceboost::assign;
    usingnamespaceboost::gregorian;
    usingnamespaceboost::posix_time;
    usingnamespaceboost::filesystem;
    namespacefs = boost::filesystem;
    usingboost::details::pool::singleton_default;
     
    #include"ximage.h"
    #include"sigslot.h"
    #include"pugiconfig.hpp"
    #include"pugixml.hpp"
    #include"contrib/minizip/zip.h"
    #include"contrib/minizip/unzip.h"
    usingnamespacepugi;
     
    #include"sigslot.h"
    #include"AppUI.h"
    #include"AppUICfg.h"
    #include"AppUtilsCfg.h"
    #include"Resource/IResource.h"
    #include"Xproer.Drawing/GdiTool.h"
    #include"ximage.h"
    #include"Xproer.Drawing/CxImageTool.h"
    #include"Xproer.Drawing/CombinImage.h"
    #include"Xproer.Drawing/CombinImageX.h"
    #include"Xproer.Drawing/TileImage.h"
    #include"Xproer.Drawing/TileImageX.h"
    #include"xproer.Drawing/MemoryDC.h"
    #include"xproer.Manager/ResMgr.h"
    #include"Xproer.Manager/ColorMgr.h"
    #include"xproer.Manager/FontMgr.h"
    #include"xproer.Manager/ImageMgr.h"
    #include"xproer.Manager/PopMenuMgr.h"
    #include"Xproer.Manager/StyleManager.h"
    #include"xproer.Manager/ImageCfg.h"
    #include"xproer.Manager/ToolBarMgr.h"
    #include"Xproer.Forms/DialogBase.h"
    #include"Xproer.UI/ArgsManager.h"
    #include"Xproer.UI/Styles.h"
    #include"Xproer.UI/IDSigner.h"
    #include"Xproer.UI/CtrlIDMaker.h"
    #include"Xproer.UI/DUIControl.h"
    #include"Xproer.UI.Controls/Button.h"
    #include"Utility/Encoder.h"
    #include"Utility/Convert.h"
    #include"IO/Directory.h"
    #include"System/Screen.h"
    usingnamespaceXproer::Manager;
    usingnamespaceXproer::System;
    usingnamespaceXproer::Drawing;
    usingnamespaceXproer::UI;
    usingnamespaceXproer::UI::Controls;
    usingnamespaceXproer::Forms;
    usingnamespaceAppUtils::Utility;
    usingnamespaceAppUtils::IO;
     
    #pragmacomment(lib, "Usp10.lib")
    #pragmacomment(lib, "cximage.lib")
    #pragmacomment(lib, "gdiplus.lib")
    #pragmacomment(lib, "pugixml.lib")
    #pragmacomment(lib, "zlib.lib")
    #pragmacomment(lib, "AppUtils.lib")
    #pragmacomment(lib, "XproerUI.lib")
    #ifdef_DEBUG 
    #pragmacomment(lib, "libboost_date_time-vc100-mt-1_55.lib")
    #pragmacomment(lib, "libboost_system-vc100-mt-gd-1_55.lib")
    #pragmacomment(lib, "libboost_filesystem-vc100-mt-gd-1_55.lib")
    #else
    #pragmacomment(lib, "libboost_date_time-vc100-mt-1_55.lib")
    #pragmacomment(lib, "libboost_system-vc100-mt-1_55.lib")
    #pragmacomment(lib, "libboost_filesystem-vc100-mt-1_55.lib")
    #endif
     
    2.将项目运行库改为MD
    clip_image006
     
    修改Release模式的运行库:
    clip_image008
     
    1.1.4.    在InitInstance中初始化UI库
    BOOLCmfcDemoApp::InitInstance()
    {
         // 如果一个运行在 Windows XP 上的应用程序清单指定要
         // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
         //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。
         INITCOMMONCONTROLSEXInitCtrls;
         InitCtrls.dwSize = sizeof(InitCtrls);
         // 将它设置为包括所有要在应用程序中使用的
         // 公共控件类。
         InitCtrls.dwICC = ICC_WIN95_CLASSES;
         InitCommonControlsEx(&InitCtrls);
     
         CWinApp::InitInstance();
     
     
         AfxEnableControlContainer();
     
         // 创建 shell 管理器,以防对话框包含
         // 任何 shell 树视图控件或 shell 列表视图控件。
         CShellManager *pShellManager = newCShellManager;
     
         // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
         CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
     
         // 标准初始化
         // 如果未使用这些功能并希望减小
         // 最终可执行文件的大小,则应移除下列
         // 不需要的特定初始化例程
         // 更改用于存储设置的注册表项
         // TODO:  应适当修改该字符串,
         // 例如修改为公司或组织名
         SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
         GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
         //初始化UI库
         LoadAppTheme(L"skin.zip");//skin.zip需要和主程序放在一起
     
         CmfcDemoDlgdlg;
         m_pMainWnd = &dlg;
         INT_PTRnResponse = dlg.DoModal();
         if (nResponse == IDOK)
         {
         }
         elseif (nResponse == IDCANCEL)
         {
         }
         elseif (nResponse == -1)
         {
             TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。 ");
             TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。 ");
         }
     
         // 删除上面创建的 shell 管理器。
         if (pShellManager != NULL)
         {
             deletepShellManager;
         }
     
         returnFALSE;
    }
     
    在应用程序退出时卸载皮肤和GDI+
    intCmfcDemoApp::ExitInstance()
    {
         UnLoadTheme();
         //卸载GDI+
         GdiplusShutdown(gdiplusToken);
     
         returnCWinApp::ExitInstance();
    }
     
    1.1.5.    修改主窗口代码
    1.继承FormMsgHandler
    #pragmaonce
     
    // CmfcDemoDlg 对话框
    classCmfcDemoDlg
         : publicCDialogEx
         , publicFormMsgHandler
    {
    // 构造
    public:
         CmfcDemoDlg(CWnd* pParent = NULL);   // 标准构造函数
     
         virtualLRESULTWindowProc(UINTmessage, WPARAMwParam, LPARAMlParam);
     
         //dui
         virtualvoidInitControls();
     
         //event
         voidbtnCancle_click(ControlBase* sender);
     
    private:
         Button* m_btnCancel;//退出按钮
     
    // 对话框数据
         enum { IDD = IDD_MFCDEMO_DIALOG };
     
         protected:
         virtualvoidDoDataExchange(CDataExchange* pDX);   // DDX/DDV 支持
     
     
    // 实现
    protected:
         HICONm_hIcon;
     
         // 生成的消息映射函数
         virtualBOOLOnInitDialog();
         afx_msgvoidOnSysCommand(UINTnID, LPARAMlParam);
         afx_msgHCURSOROnQueryDragIcon();
         DECLARE_MESSAGE_MAP()
    };
     
    2.重载WindowProc方法,将消息转发到UI引擎
    LRESULTCmfcDemoDlg::WindowProc(UINTmessage, WPARAMwParam, LPARAMlParam)
    {
         BOOLhd = FALSE;
         if (this->isWmMsg(message))
         {
             returnthis->wmMsgMap(message, wParam, lParam,hd);
         }
         returnCDialogEx::WindowProc(message, wParam, lParam);
    }
     
    3.在OnInitDialog中初始化UI资源
    BOOLCmfcDemoDlg::OnInitDialog()
    {
         CDialogEx::OnInitDialog();
     
         // 将“关于...”菜单项添加到系统菜单中。
     
         // IDM_ABOUTBOX 必须在系统命令范围内。
         ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
         ASSERT(IDM_ABOUTBOX < 0xF000);
     
         CMenu* pSysMenu = GetSystemMenu(FALSE);
         if (pSysMenu != NULL)
         {
             BOOLbNameValid;
             CStringstrAboutMenu;
             bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
             ASSERT(bNameValid);
             if (!strAboutMenu.IsEmpty())
             {
                  pSysMenu->AppendMenu(MF_SEPARATOR);
                  pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
             }
         }
     
         // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
         //  执行此操作
         SetIcon(m_hIcon, TRUE);          // 设置大图标
         SetIcon(m_hIcon, FALSE);         // 设置小图标
     
         // 加载UI资源
         this->init(this, L"demo.xml");
     
         returnTRUE// 除非将焦点设置到控件,否则返回 TRUE
    }
     
    4.在InitControls中获取控件并与成员变量关联
    voidCmfcDemoDlg::InitControls()
    {
         this->m_btnCancel = (Button*)this->find(L"button2");
         this->m_btnCancel->Click.connect(this, &CmfcDemoDlg::btnCancle_click);
    }
     
    5.编写控件事件
    voidCmfcDemoDlg::btnCancle_click(ControlBase* sender)
    {
         TRACE("btnCancle_click ");
         this->EndDialog(1);
    }
  • 相关阅读:
    经典代码JSKeyword查看(M。。。$)的哦!
    django处理websocket
    产品所有者也应该是Scrum教练吗?
    google的javascript编码规范
    python 处理websocket
    [转] 虚拟座谈会:TDD有多美?
    python 数字相关
    google的python编码规范
    python 函数相关
    python推荐的模块结构
  • 原文地址:https://www.cnblogs.com/songsu/p/4216830.html