﻿<?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</title><link>http://www.cppblog.com/zhcen/</link><description>C/C++</description><language>zh-cn</language><lastBuildDate>Wed, 08 Apr 2026 21:05:21 GMT</lastBuildDate><pubDate>Wed, 08 Apr 2026 21:05:21 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><item><title>Destroy modeless dialog box</title><link>http://www.cppblog.com/zhcen/archive/2008/04/14/47017.html</link><dc:creator>陈振辉</dc:creator><author>陈振辉</author><pubDate>Mon, 14 Apr 2008 02:19:00 GMT</pubDate><guid>http://www.cppblog.com/zhcen/archive/2008/04/14/47017.html</guid><wfw:comment>http://www.cppblog.com/zhcen/comments/47017.html</wfw:comment><comments>http://www.cppblog.com/zhcen/archive/2008/04/14/47017.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/zhcen/comments/commentRss/47017.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhcen/services/trackbacks/47017.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="FONT-FAMILY: Verdana">When you implement a modeless dialog box, always override the <span style="COLOR: #0000ff">OnCancel</span> member function and call <span style="COLOR: #0000ff">DestroyWindow</span> from within&nbsp;&nbsp; it. Don&#8217;t call the base class <span style="COLOR: #0000ff">CDialog::OnCancel</span>, because it calls <span style="COLOR: #0000ff">EndDialog</span>, which will make the dialog box invisible but&nbsp;will not destroy it.&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;You should also override <span style="COLOR: #0000ff">PostNcDestroy </span>for modeless dialog boxes in order to delete this, since modeless dialog boxes are usually allocated with new. Modal dialog boxes are usually constructed on the frame and do not need <span style="COLOR: #0000ff">PostNcDestroy</span> cleanup.</span>
<img src ="http://www.cppblog.com/zhcen/aggbug/47017.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-04-14 10:19 <a href="http://www.cppblog.com/zhcen/archive/2008/04/14/47017.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Z-Order</title><link>http://www.cppblog.com/zhcen/archive/2008/04/07/zhcen20080408.html</link><dc:creator>陈振辉</dc:creator><author>陈振辉</author><pubDate>Mon, 07 Apr 2008 06:24:00 GMT</pubDate><guid>http://www.cppblog.com/zhcen/archive/2008/04/07/zhcen20080408.html</guid><description><![CDATA[<h3><a name=zorder></a>Z-Order</h3>
<p>The <em>z-order</em> of a window indicates the window's position in a stack of overlapping windows. This window stack is oriented along an imaginary axis, the z-axis, extending outward from the screen. The window at the top of the z-order overlaps all other windows. The window at the bottom of the z-order is overlapped by all other windows.</p>
<p>The system maintains the z-order in a single list. It adds windows to the z-order based on whether they are topmost windows, top-level windows, or child windows. A <em>topmost window</em> overlaps all other non-topmost windows, regardless of whether it is the active or foreground window. A topmost window has the <mshelp:link tabIndex=0 keywords="_mfc_extended_window_styles" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>WS_EX_TOPMOST</font></u></mshelp:link> style. All topmost windows appear in the z-order before any non-topmost windows. A child window is grouped with its parent in z-order.</p>
<p>When an application creates a window, the system puts it at the top of the z-order for windows of the same type. You can use the <mshelp:link tabIndex=0 keywords="_win32_BringWindowToTop_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>BringWindowToTop</font></u></mshelp:link> function to bring a window to the top of the z-order for windows of the same type. You can rearrange the z-order by using the <mshelp:link tabIndex=0 keywords="_win32_SetWindowPos_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>SetWindowPos</font></u></mshelp:link> and <mshelp:link tabIndex=0 keywords="_win32_DeferWindowPos_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>DeferWindowPos</font></u></mshelp:link> functions.</p>
<p>The user changes the z-order by activating a different window. The system positions the active window at the top of the z-order for windows of the same type. When a window comes to the top of z-order, so do its child windows. You can use the <mshelp:link tabIndex=0 keywords="_win32_GetTopWindow_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>GetTopWindow</font></u></mshelp:link> function to search all child windows of a parent window and return a handle to the child window that is highest in z-order. The <mshelp:link tabIndex=0 keywords="_win32_GetNextWindow_cpp" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><u><font color=#0000ff>GetNextWindow</font></u></mshelp:link> function retrieves a handle to the next or previous window in z-order.</p>
<img src ="http://www.cppblog.com/zhcen/aggbug/46420.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-04-07 14:24 <a href="http://www.cppblog.com/zhcen/archive/2008/04/07/zhcen20080408.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>