Mixed use Duilib authoring interface in MFC

Source: Internet
Author: User
Tags mixed

Because the company project recently into the Big Hole in MFC, with MFC to do the UI for a period of time, it is not very convenient, the development efficiency is a bit slow.

See the C + + interface to do the class library, feel duilib more in line with the need to do the interface, and many large companies are also using duilib, that with a large stream, and in this expression of Duilib author and the vast majority of open-source author's respect.

Duilib supports Win32 programs and MFC programs.

?

The steps are as follows:

?

    1. Setting up the DUILIB environment

You can go to the Https://github.com/duilib/duilib download framework and compile the Duilib framework under Unicodedebug and debug to build the library file

Here are the VS2008 environment operations. VC + + options, projects and solutions

The introduction of Duilib

Include file

Library files

source file

Setting environment variables for the system

If you do not set environment variables, you can also copy the Duilib_ud.dll and Duilib_d.dll directly to the application's build directory. Otherwise, an error is reported that the associated DLL is missing.

?

    1. Adding references and DLLs

Add Duilib header files and libraries to the StdAfx.h file

#include <ObjBase.h>

#include <UIlib.h>

?

using namespace Duilib;

?

#ifdef _DEBUG

#pragma Comment (Lib, "Duilib_ud.lib")

#else

#pragma comment (lib, "Duilib_u.lib")

#endif

?

Note: If you run the generated program on another machine, be sure to copy the Duilib_ud.dll and Duilib_d.dll to the application's root directory.

?

    1. Create a corresponding class

?

Create a C + + class to inherit the Duilib cwindowwnd and Inotifyui

As shown below:

?

In the header file of the class you define, add

Public:

LPCTSTR getwindowclassname () const;

void???? Notify (tnotifyui& msg);

LRESULT handlemessage (UINT umsg, WPARAM WPARAM, LPARAM LPARAM);

?

And

Private:

???? Cpaintmanagerui m_pm;

?

Getwindowclassname

?

Getwindowclassname is the class name of the Set class

?

The source file can be defined as follows:

LPCTSTR cduilib_dialog::getwindowclassname () const

{

???? return (lpctstr) "Ctestdlg"; / * Feel free to take a name * *

}

?

Notify

?

Notify is a response function for a control in duilib, such as when a control button is clicked.

The source file can be defined as follows:

void Cduilib_dialog::notify (tnotifyui& msg)

{

???? if (Msg.stype = = _t ("click"))

???? {

???????? if (Msg.psender->getname () = = _t ("closebtn"))

???????? {

???????????? Close ();

????????}

????}

}

?

?

Handlemessage

?

Handlemessage is a message-handling function in Duilib for message loops.

Duilib can be initialized in this function.

The source file can be defined as follows:

LRESULT cduilib_dialog::handlemessage (UINT umsg, WPARAM WPARAM, LPARAM LPARAM)

{

???? if (umsg = = wm_create)

???? {

?

???????? Cpaintmanagerui::setinstance (AfxGetInstanceHandle ()); ///load XML, you need to use this handle to locate the path of the EXE in order to load the XML path

???????? Cpaintmanagerui::setresourcepath (Cpaintmanagerui::getinstancepath () + _t ("Skin")); //location of resources such as images

?

???????? M_PM. Init (m_hwnd);

???????? Cdialogbuilder Builder;

???????? Ccontrolui *proot = Builder. Create (_t ("Mainactivity.xml"), (UINT) 0, NULL, &m_pm); //The name of the XML file to load

???????? ASSERT (proot && "Failed to parse XML");

???????? M_PM. Attachdialog (Proot);

???????? M_PM. Addnotifier (this);

?

???????? return 0;

????}

???? Else if (umsg = = Wm_destroy)

???? {

????????::P ostquitmessage (0);

????}

???? LRESULT lres = 0;

???? if (M_PM. MessageHandler (umsg, WParam, LParam, lres)) return lres;

???? return Cwindowwnd::handlemessage (umsg, WParam, LParam);

?

}

?

?

    1. Create a form

?

Create this duilib in the main form,

?

In this class of the main form, add a class object that you just added M_dlgduilib (object name is arbitrary)

Create with the following code

???? if (m_dlgduilib = = NULL)

???? {

???????? m_dlgduilib. Create (This,m_hwnd, NULL, ui_wndstyle_dialog & (~ ( ws_border | ws_caption )) , 0, 0, 0, 800, 600);

????}

???? m_dlgduilib. CenterWindow ();

???? m_dlgduilib. ShowWindow (TRUE);

You can set the open form style to

ui_wndstyle_dialog & (ws_caption | ws_border))

?

    1. Design layouts and styles

?

The form layout of Duilib is represented by XML, and in Duilib there is a DUI designer that can be designed by it. You can view this article about the use of Duilib: http://www.cnblogs.com/lin1270/p/4106944.html

?

demo:http://pan.baidu.com/s/1mghv74g

Mixed use Duilib authoring interface in MFC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.