1. Sub-class
Theory: Sub-class is a technique that allows an application to intercept messages destined for another window. an application implements the default behavior of adding, monitoring, or modifying that window by intercepting messages belonging to another window. Subclasses are an effective way to change or extend the behavior of an existing window without being re-developed. one convenient way to get the functionality of predefined control window classes (Button controls, edit controls, list controls, drop-down list controls, static controls, and scroll bar controls) and to modify some of their behavior is to subclass them. For example, for a multi-line edit box in a dialog box, the dialog box closes when the user presses the enter key. By subclasses of the edit control, an application can have an edit control that inserts a carriage return and a newline into the text without closing the dialog box, and the application does not specifically develop an edit control for this particular need.
Changes the nature of a window instance that already exists: message processing and other instance properties.
In the context of SDK programming, a subclass is a window function that alters a window instance (via GetWindowLong () and SetWindowLong ()), and what it does is to write a new window function for a window instance. Its operation is performed at the instance level. The
in MFC is different in the case of subclasses: All MFC windows have the same window function, by which the window function looks up a window instance based on the window handle, and then maps the message to the window class's message handler function. In order to take advantage of the message mapping mechanism of MFC, it is inappropriate to change the window function (name), MFC is also wrapped in the function SubclassWindow (). But the nature of the subclass has not changed: The message that affects the window at the instance level and its processing. Example:
class b:public a
{
...
}
a a;
b b;
HWND Ha=a.getsafehwnd ();
B.subclasswindow (ha); #当然A and B are not necessarily inheritance relationships.
Note: Before the quilt-like window is destroyed, you must perform the inverse subclass of the window:
B.unsubclasswindow ();
2 Hyper-Class
The window superclass is a window class --wndclass or Wndclassex (non-MFC class concept) at the level of the changes in the window classes feature .
Use procedure: First obtain an existing window class, then set the window class, and finally register the window class.
Cases:
Wndclassex WC;
Wc.cbsize=sizeof (WC); Windows is used for version checking, regardless of window characteristics
Getclassinfoex (hinst, "XXXXXX", &WC);
Hinst-defines a handle to the module of the window class xxxxxx, such as a system-defined window class (such as: EDIT, BUTTON) hinst=null.
Wc.lpszclassname = "yyyyyyy";//must change the name of the window class
Wc.hbrbackground = CreateSolidBrush (RGB (0,0.0));//Change background brush
Wc.lpfnwndproc = newwndproc;//changing window functions
......
RegisterClassEx (&WC);//Register New window class
Using the window class
......
:: CreateWindow (_t ("yyyyyyyy",......) ;
Therefore, hyper-class can only change the characteristics of the windows that you create, and cannot be used for Windows-created window (such as a button on a dialog box cannot be super-Class). Sub-class is at the instance level, as long as the instance of the window can be obtained, it can be sub-class, which is the only subclass of the advantages of the super-class. In addition, the sub-class can be achieved, super-class can be achieved, but the use of super-class is more troublesome.
3. Summary
(0) sub-class Modify window procedure function, superclass Modify window Class (new window class name)
(1) subclasses are at the window instance level, and superclass is at the window class (WNDCLASS) level.
(2) The superclass can accomplish more complex functions than subclasses, and in the context of the SDK, it can be considered that the subclass is a subset of super-class.
(3) Sub-class can only change the nature of the window creation, for the window creation during the inability (unable to intercept the On_create event), and super-class can be implemented; Superclass cannot be used for Windows created window, subclasses can.
4. Other
In the sight of Reality (2): Introduction windows, Messages, subclasses, and superclass here's an example.
Can come to the conclusion
A) The classname of subclasses will not change, and hyper-class use new registration classname
b) Subclass & Superclass Describes an action that is not related to the implementation method ..... Mainly sub-class is SubclassWindow, SubclassDlgItem, and super-class is RegisterClassEx (&newwindowclass)
c) feel specific there is no need to differentiate these, realize the function on the line, hehe
Reference: Http://www.cppblog.com/bigsml/archive/2007/08/24/30780.aspx
--------------------------------------------------------------------------------------------
Delphi's TButton is the use of hyper-class technology, packaging the windows of the native button, so as to become TButton
--------------------------------------------------------------------------------------------
Sub-class:
//Save window Default message response function pointerWNDPROC Psubclassoldeditproc;//message response function to replace a subclass windowLRESULT CALLBACK Jceditprocsubclass (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {Switch(message) { CaseWM_CHAR: {:: MessageBox (HWnd,"WM_CHAR Response","sub-class", MB_OK); return 0; } default:return:: CallWindowProc (Psubclassoldeditproc, hWnd, message, WParam, LParam); }}//subclass code for a created form { //CreateHWND Hedit = CreateWindowEx (NULL,"EDIT","Subclass", Ws_child| Ws_border|es_left|es_autohscroll, -, -, -, -, hWnd, NULL, HINSTANCE, NULL); Psubclassoldeditproc=(WNDPROC):: SetWindowLong (Hedit, GWL_WNDPROC, (DWORD) jceditprocsubclass); //ShowShowWindow (Hedit, ncmdshow); UpdateWindow (HWND); }
Hyper-Class:
WNDPROC Psuperoldeditproc;//Save window Default Message handler function//super-Class message response function for substitutionLRESULT CALLBACK Jceditprocsuper (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {Switch(message) { CaseWM_CHAR: {:: MessageBox (HWnd,"WM_CHAR Response","Hyper-Class", MB_OK); return 0; } default:return:: CallWindowProc (Psuperoldeditproc, hWnd, message, WParam, LParam); }}//To create a superclass control code { //get the original control informationWndclassex Myeditclass; :: Getclassinfoex (HINSTANCE,"EDIT", &Myeditclass); //Save the original control's default message handler functionPsuperoldeditproc =Myeditclass.lpfnwndproc; //set the replacement message handlerMyeditclass.lpfnwndproc =Jceditprocsuper; //Specify a new window class nameMyeditclass.lpszclassname ="Jcilyedit"; //Set structure body sizeMyeditclass.cbsize =sizeof(Wndclassex); //Register for new informationRegisterClassEx (&Myeditclass); //CreateHWND Hedit = CreateWindowEx (NULL, Myeditclass.lpszclassname,"Superclass", Ws_child| Ws_border|es_left|es_autohscroll, -, -, -, -, hWnd, NULL, HINSTANCE, NULL); //ShowShowWindow (Hedit, ncmdshow); UpdateWindow (HWND); }
Reference:
Http://www.cnblogs.com/jcily/archive/2009/10/22/1587778.html
http://blog.csdn.net/chenhao518530/article/details/628556
Http://www.cnblogs.com/tonybain/archive/2006/01/19/320366.html
Http://www.fmddlmyy.cn/text19.html
Sub-class and superclass of Windows--subclasses are window instance level, superclass is at window class (WNDCLASS) level