Differences between superclass and subclasses

Source: Internet
Author: User

Q: I have read the winx Development Kit documentation. What is the concept of a superclass? I have heard of subclass only ).

A: subclass refers to the process of replacing Windows (wndproc ).
Superclass is the process of replacing the window (wndproc) and replacing the classname.
Subclass is not like inheritance, but like a plug-in (Hook) action.
Superclass is more like inheritance, because a new window class is generated and the behavior is inherited.
In winx, subclass and superclass are implemented using the same class. All are winx: subclasswindow.
Other interface libraries generally do not provide superclass.

Q: Do you say other interface libraries do not provide superclass? Should the inheritance in MFC belong to superclass?

A: No. Subclass is used in MFC.

Q: Why can't I see the difference between the two? I mean in terms of usage and results.

A: The two are different in usage, but the obtained results are indeed not much different.
Take the button as an example. If subclass is used, the user must first have a button and then subclass.
That is to say, subclass occurs after createwindow.
If it is a superclass, you can directly input a new window class name during createwindow. No button is generated.
Of course, this requires that the registerclass of the window class be called before createwindow.
MFC uses subclass. Because the cbutton class is associated with the button on the dialog box through DDX technology.
That is to say, in MFC, a button is first available, and then it is subclass by DDX technology.
Therefore, you generally cannot see the subclass process.

Q: under what circumstances do superclasses need to be used?
Oh, I understand, is there a superclass technology that allows users to easily create their own control?

A: Yes. It does not need to start from scratch.

Q: Yes. Most custom controls are related to system controls.

A: Yes. This is exactly the meaning of the existence of superclass.
You can imagine: In the past, you provided a control, you want to tell it, first create a button, and then call my subclass function.
With superclass, you only need to tell it the name of the window class.
Because superclass hides the fact that you inherit from the button.

Q: Yes.

A: The reason why winx can have superclass and other interface libraries is not, it is related to the starting point of shielding the "window class.

Q: Yes, yes, yes. You can also visually develop custom controls in the future.

A: Yes.

Q: Just specify our own window class.
Winx is a control between system controls and ActiveX controls.

A: Yes. This control is actually the implementation of Windows system controls.
However, you do not need to register the system control. Windows has already completed registration for you.

Q: Didn't the system implement these system controls through superclass? It should be inherited from the most general window.

A: Oh, of course not. They have nothing to borrow, so they have to inherit from the most basic winx: window.

Q: whether it's a startup or a little basic, It's A superclass.
Because winx: Windows is based on defwindowproc and is also a window process.

A: This is understandable.

Q: Is it understandable that subclass only changes wndproc, while superclass also changes other window properties?

A: Yes. Your understanding is completely correct. This is the essential difference between subclass and superclass.
Superclass can change any data of window class (wndclassex. This is how winx is implemented.

Subclass sample code:

//-------------------------------------------------------------------------
// Class cmyedit-use subclass Technology

Class cmyedit: Public winx: Edit <cmyedit>
{
Public:
Void oncontextmenu (hwnd, winx: cpoint pt)
{
// Disabled the right-click menu...
}
};

//-------------------------------------------------------------------------
// Chellodlg

Class chellodlg: Public winx: modaldialog <chellodlg, idd_hello>
{
Public:
Bool oninitdialog (hwnd hdlg, hwnd hwnddefaultfocus)
{
Cmyedit: dosubclassdlgitem (hdlg, idc_edit1 );
Return true;
}
};

//-------------------------------------------------------------------------

Int apientry winmain (hinstance,
Hinstance hprevinstance,
Lpstr lpcmdline,
Int ncmdshow)
{
Chellodlg DLG;
DLG. domodal ();
Return 0;
}

//-------------------------------------------------------------------------

 

Code of the superclass:

 

//-------------------------------------------------------------------------
// Class cmyedit2-using superclass Technology

Class cmyedit2: Public winx: Edit <cmyedit2>
{
Winx_class ("myedit ");
Public:
Void oncontextmenu (hwnd, winx: cpoint pt)
{
// Disabled the right-click menu...
}
};

//-------------------------------------------------------------------------
// Chellodlg

Class chellodlg: Public winx: modaldialog <chellodlg, idd_hello>
;

//-------------------------------------------------------------------------

Int apientry winmain (hinstance,
Hinstance hprevinstance,
Lpstr lpcmdline,
Int ncmdshow)
{
Cmyedit2: registerclass ();
Chellodlg DLG;
DLG. domodal ();
Return 0;
}

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.