ActiveX Control MFC design tour

Source: Internet
Author: User
In csdn, I met several friends who asked me how to use MFC to design ActiveX controls. I thought I had done this before and suddenly wanted to write something. Article Describes some of the design skills I know.
Helpless, I don't know how to start. Finally, I decided to simply design a control and write down some of the problems encountered in the control. Think about it. Design a grid control named litegrid.

(I forgot to mention it. This article is a bit deeper. If you want to see how to add attributes and events, sorry, this article does not provide)

The first cool feature to be added is to add a hierarchical structure. Let's see how many widgets in VB have such a structure,
Taking the listview control as an example, listview1.listitems (0). Checked = true

How is this structure based on objects as attributes implemented,
Information available on the Internet, from instructor Yang
<Implementation of the lpdispatch attribute of the idispatch interface>
This article introduces
In the tutorial autoclick in msdn,
In short, idispatch is used as the control property.

Well, let's just talk about it in a few minutes. Then we will start:
1. Add a ccell class derived from csf-target to use this class to represent a grid control. Note that automation uses the creatable by type ID Option.

2. Add the upper property text for the ccell class in classwizard

3. Implement the text attribute as follows:
Void ccell: ontextchanged ()
{
// Todo: Add notification handler code
Afxmessagebox (m_text, mb_ OK | mb_iconinformation, 0 );
}

4. Add the read-only cell (long ncol, long nrow) of the lpdispatch type to clitegrid. I 'd like to add it in general. Let's just briefly talk about it.
In the addproperty dialog box in automation of classwizard,
In implementation, select get/set methods,
Deletes all content in the Set function item and sets it as a read-only attribute.
In the parameter list field, add the preceding two parameters long ncol and long nrow.
Here we need to declare two points. One is that the integer type in VB corresponds to short, and the long type corresponds to long, the other one is that the parameter attributes here are different from the listitems of the previous listview. The specifics will be discussed later.

5. Now we will implement this cell attribute.
Lpdispatch clitegridctrl: getcell (short ncol, short nrow)
{
// Todo: add your property handler here
Ccell * pcell = new ccell;
Return pcell-> getidispatch (false );
}
Note:
The prototype of the getidispatch function of cve-target is

Lpdispatch getidispatch (boolBaddref
);

Here we set baddref to false because the reference value is already set to 1 when constructing ccell, and after getcell, we do not need a pcell object. If pcell is a member variable and needs it elsewhere in the control, set it to true.

In addition, note # include "cell. H", ^ _ ^

Okay, okay. compile it. Let's try it in VB.
Create a VB project and add the litegrid control to the form.
Add the following statement to form_load:
Litegrid1.cell (0, 0). Text = "Happy New Year"
Run it to see how it works.

However, it is different from other controls in VB ,. text cannot be prompted, although it can be used, but there is no prompt, always feel something bad, how can this prompt be made out, huh, and listen to the next Decomposition

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.