﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-zhcen-随笔分类-Others</title><link>http://www.cppblog.com/zhcen/category/6402.html</link><description>C/C++</description><language>zh-cn</language><lastBuildDate>Sun, 01 Jun 2008 11:14:46 GMT</lastBuildDate><pubDate>Sun, 01 Jun 2008 11:14:46 GMT</pubDate><ttl>60</ttl><item><title>Window Superclassing</title><link>http://www.cppblog.com/zhcen/archive/2008/06/01/51768.html</link><dc:creator>陈振辉</dc:creator><author>陈振辉</author><pubDate>Sun, 01 Jun 2008 09:39:00 GMT</pubDate><guid>http://www.cppblog.com/zhcen/archive/2008/06/01/51768.html</guid><wfw:comment>http://www.cppblog.com/zhcen/comments/51768.html</wfw:comment><comments>http://www.cppblog.com/zhcen/archive/2008/06/01/51768.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhcen/comments/commentRss/51768.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhcen/services/trackbacks/51768.html</trackback:ping><description><![CDATA[<p><em style="COLOR: #ff0000; BACKGROUND-COLOR: yellow">Superclassing</em> is a technique that allows an application to create a new window class with the basic functionality of the existing class, plus enhancements provided by the application. A superclass is based on an existing window class called the <em style="BACKGROUND-COLOR: yellow">base class</em>. Frequently, the base class is a system global window class such as an edit control, but it can be any window class. </p>
<p>A superclass has its own window procedure, called the superclass procedure. The <span style="COLOR: #0000ff; BACKGROUND-COLOR: yellow">superclass procedure</span> can take three actions upon receiving a message: It can pass the message to the original window procedure, modify the message and pass it to the original window procedure, or process the message and not pass it to the original window procedure. If the superclass procedure processes a message, it can do so before, after, or both before and after it passes the message to the original window procedure. </p>
<p>Unlike a subclass procedure, a superclass procedure can process window creation messages (<a href="mk:@MSITStore:d:\msdn\98VSa\1033\winui.chm::/devdoc/live/pdui/windows_8fol.htm"><font color=#336699>WM_NCCREATE</font></a>, <a href="mk:@MSITStore:d:\msdn\98VSa\1033\winui.chm::/devdoc/live/pdui/windows_41d1.htm"><font color=#336699>WM_CREATE</font></a>, and so on), but it must also pass them to the original base-class window procedure so that the base-class window procedure can perform its initialization procedure. </p>
<p>To superclass a window class, an application first calls the <a href="mk:@MSITStore:d:\msdn\98VSa\1033\winui.chm::/devdoc/live/pdui/winclass_40rz.htm"><strong><font style="COLOR: #0000ff" color=#336699>GetClassInfo</font></strong></a> function to retrieve information about the base class.<span style="COLOR: #0000ff"> <strong>GetClassInfo</strong></span> fills a <a href="mk:@MSITStore:d:\msdn\98VSa\1033\winui.chm::/devdoc/live/pdui/winclass_8yk2.htm"><strong><font style="COLOR: #0000ff" color=#336699>WNDCLASS</font></strong></a> structure with the values from the <span style="COLOR: #0000ff"><strong>WNDCLASS</strong> </span>structure of the base class. Next, the application copies its own instance handle into the <strong>hInstance</strong> member of the <strong>WNDCLASS</strong> structure and copies the name of the superclass into the <strong>lpszClassName</strong> member. If the base class has a menu, the application must provide a new menu with the same menu identifiers and copy the menu name into the <strong>lpszMenuName</strong> member. If the superclass procedure processes the <a href="mk:@MSITStore:d:\msdn\98VSa\1033\winui.chm::/devdoc/live/pdui/editcon_8wh0.htm"><font color=#336699>WM_COMMAND</font></a> message and does not pass it to the window procedure of the base class, the menu need not have corresponding identifiers. <span style="COLOR: #0000ff"><strong>GetClassInfo</strong> </span>does not return the <strong>lpszMenuName</strong>, <strong>lpszClassName</strong>, or <strong>hInstance</strong> member of the <strong style="COLOR: #0000ff">WNDCLASS</strong> structure. </p>
<p>An application must also set the <strong>lpfnWndProc</strong> member of the <strong>WNDCLASS</strong> structure. The <strong>GetClassInfo</strong> function fills this member with the address of the original window procedure for the class. The application must save this address, to pass messages to the original window procedure, and then copy the address of the superclass procedure into the <strong>lpfnWndProc</strong> member. The application can, if necessary, modify any other members of the <strong>WNDCLASS</strong> structure. After it fills the <strong>WNDCLASS</strong> structure, the application registers the superclass by passing the address of the structure to the <a href="mk:@MSITStore:d:\msdn\98VSa\1033\winui.chm::/devdoc/live/pdui/winclass_70s3.htm"><strong><font style="COLOR: #0000ff" color=#336699>RegisterClass</font></strong></a> function. The superclass can then be used to create windows. </p>
<p>Because superclassing registers a new window class, an application can add to both the extra class bytes and the extra window bytes. The superclass must not use the original extra bytes for the base class or the window for the same reasons that an instance subclass or a global subclass should not use them. Also, if the application adds extra bytes for its use to either the class or the window instance, it must reference the extra bytes relative to the number of extra bytes used by the original base class. Because the number of bytes used by the base class may vary from one version of the base class to the next, the starting offset for the superclass's own extra bytes may also vary from one version of the base class to the next.<br></p>
<img src ="http://www.cppblog.com/zhcen/aggbug/51768.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhcen/" target="_blank">陈振辉</a> 2008-06-01 17:39 <a href="http://www.cppblog.com/zhcen/archive/2008/06/01/51768.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>