How to Use duilib in wtl and MFC and how to use the duilib library statically! (A demo is attached to the preliminary explanation)

Source: Internet
Author: User

I will not talk much about the history of duilib. Anyone who can see this article can only find this article if they have some knowledge.

Let me talk about the basic usage of this database.



I am personally interested in some good technologies.

For personal reasons, I like to use a good technology.

So when I met this library, I decided to use this library to write a part of the project, that is, the Treeview control.

This is because my project is already a molding project, just as an improvement. If you completely change an existing project to duilib, there is no difference from rewriting.

So I chose a seemingly treasure path-embedding duilib in the existing wtl project. Create a Treeview control.



Now, let's list the problems and solutions I encountered in the implementation process so that you can make a reference when you encounter problems in the future.



1. I like static libraries, but I don't like dynamic libraries. It's like wearing clothes and carrying clothes hangers with me. It's too much trouble.

So the first thing to do when using this library is to convert the dynamic library into a static library. You can also use the Unicode Character Set instead.

(1) locate the uilib. h header file and comment out the original definition: Add a new macro # define uilib_api

// # Ifdef uilib_exports
// # Define uilib_api _ declspec (dllexport)
// # Else
// # Define uilib_api _ declspec (dllimport)
// # Endif

(2) No error will be reported after compilation, and the static library can be directly included during use. Note that the static library oledlg. Lib DUI. Lib winmm. Lib comctl32.lib must be included.

Although it is not simple, it can make the program generate only one EXE and there is no other burden.

2. The createtextserver is not defined in the compilation project after the inclusion. This is because RichEdit support is added to the new version. This directui requires texthost and textserver to reference RichEdit. DLL and RichEdit. lib for convenience, I put this part of the import into the duilib library. So I will not post any code.
The Code imported into the database is a programmer.



3. If your wtl atl mfc file already contains a header file such as atltypes, you will find that n more crect cpoint csize and other statements do not know which one to use. Duilib implements the conflicts between these three functions and the atl mfc wl. So what should we do at this time ?.. Of course, macros are used. We can find them under uibase. h of duilib and add # ifndef before definition.
After dui_notypes is defined, append # endif so that we can add # define dui_notypes before the duilib library is introduced in wtl to block those errors.



4. The problem that follows will almost cause me to crash, but it will be solved in the end.

After solving the preceding problems one by one, you will find that errors are inexplicably reported in many aspects of the project, and even the most basic CDC cmemerydc cpen reports a bunch of errors.

The error is caused by the Windows X. h header file in duilib. This is a header file that SDK programmers cannot know. It contains macro definitions, which greatly facilitates SDK programming.

But it becomes an obstacle here. What should I do? After reading the error message, I read the Macros in Windows x again. I found that the cause is very simple. Some macro definitions in it conflict with the wtl function definitions. At this time, we need to use the function protection mechanism of Microsoft. In my project, the following functions selectfont selectpen have many selectbrushes. When an error is reported, it is not necessary to add the information once.

# Ifdef _ inc_windowsx
# UNDEF selectfont
# UNDEF selectpen
# Endif // _ inc_windowsx



5. At this time, you can use the duilib library in wtl normally.



6. Let's talk about the implementation of that tree.

The tree is undoubtedly implemented by indentation for the list in it. I chose the following mode for the node. In this way, I only need to switch the chorizontallayoutui.

Clistcontainerelementui index number.

Clistcontainerelementui

Chorizontallayoutui

Widget

Widget

Chorizontallayoutui

Clistcontainerelementui

7. automatically calculate the scroll bar!

Clistcontainerelementui does not have the function of automatically calculating the scroll bar. It may be because there is no way to determine the location of things in the container.

For my project, I inserted ctextui IN THE chorizontallayoutui to add the logic to automatically calculate the width of ctextui in the underlying library and set the clistcontainerelementui width.

In this process, you always need to note that the clistcontainerelementui's setfixwight refresh will lead to an endless loop. Therefore, you need to add a default parameter.



8. the principle of sorting and sorting is simple and fast, the chorizontallayoutui and tag can be reversed. It seems that my fast writing is troublesome because I was in a hurry to write it, but I can at least implement the function, however, it is only for sorting leaf nodes. If you want to sort non-leaf nodes, it is not impossible, but it will be troublesome because I don't need to write it. If you are interested, write it yourself.



9. At last, I simply wrote a demo because someone in the Group wanted a demo, but I didn't use wtl any more because I was afraid of trouble.

The demo is really very simple. There is only one treeviwe, and nothing else. Even the title bar is nothing to write. I believe everyone can write it easily. I want to download the demo on csdn.

First texture: treeviewdemo click here to download the source code

Oh, you forgot QQ: 672496008. If you cannot compile or understand anything, you can ask me... for this demo, I will.

Beyond the scope of this demo, I may not be able to help. I have only been in touch for one week!

Original article: http://blog.csdn.net/lin98666lin/article/details/6580461

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.