﻿<?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++博客-chlf-随笔分类-其它</title><link>http://www.cppblog.com/chlf/category/920.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 25 May 2008 20:13:23 GMT</lastBuildDate><pubDate>Sun, 25 May 2008 20:13:23 GMT</pubDate><ttl>60</ttl><item><title>独立的界面肤化库</title><link>http://www.cppblog.com/chlf/archive/2006/02/16/3296.html</link><dc:creator>VC进阶</dc:creator><author>VC进阶</author><pubDate>Thu, 16 Feb 2006 14:46:00 GMT</pubDate><guid>http://www.cppblog.com/chlf/archive/2006/02/16/3296.html</guid><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><A name=_Toc94754440><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">引言：</SPAN><SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></A></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-bookmark: _Toc94754440"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></B></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现在的应用软件都讲究个性化，因此提供一套漂亮的皮肤就必不可少。这就需要用到一些控件肤化技术。常规是重载</SPAN><SPAN lang=EN-US>MFC</SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的消息列表或虚函数来实现的，但引来的问题是肤化库和应用程序的耦合性太强。经常会由于肤化代码的一处小改动而引起逻辑上并没有关联的整个应用程序大规模的编译和链接，并带来开发效率的急剧下降，这在开发大型软件时是很难忍受的。</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-bookmark: _Toc94754440"><SPAN lang=EN-US><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">本文在参考了一些常用肤化技术后提供了自己的解决方案：采用替换窗体过程，皮肤库高度独立，内部完善与修改毫不影响应用程序。</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-bookmark: _Toc94754440"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="mso-bookmark: _Toc94754440"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">常见肤化方法：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; mso-para-margin-left: 2.0gd"><SPAN style="mso-bookmark: _Toc94754440"><A name=_Toc94754441><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第一种：利用继承关系直接子类化</SPAN></A></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="mso-bookmark: _Toc94754440"><A name=_Toc94754442><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第二种：在一个对话框的</SPAN><SPAN lang=EN-US> OnInitDialog </SPAN></A></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754442"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中逐控件子类化</SPAN></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="mso-bookmark: _Toc94754440"><A name=_Toc94754443><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">第三种：在</SPAN></A></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754443"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"> Hook </SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754443"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">中拦截窗口创建消息，并进行子类化</SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754443"></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="mso-bookmark: _Toc94754440"><A name=_Toc94754444><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">第四种</SPAN></A></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754444"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"> </SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754444"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #a000a0; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">SetWindowLong</SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754444"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">替换窗口过程</SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754444"></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 23.45pt; mso-char-indent-count: 2.13"><SPAN style="mso-bookmark: _Toc94754440"><A name=_Toc94754445><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">第五种</SPAN></A></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754445"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"> </SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754445"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">在</SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754445"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">Hook</SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN style="mso-bookmark: _Toc94754445"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">中替换窗口过程</SPAN></SPAN></SPAN><SPAN style="mso-bookmark: _Toc94754445"></SPAN><SPAN style="mso-bookmark: _Toc94754440"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></SPAN></P><SPAN style="mso-bookmark: _Toc94754440"></SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><A name=_Toc94754446><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">各种肤化技术的原理：</SPAN></B></A><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; mso-para-margin-left: 2.0gd"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 黑体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">第一类方法采用的是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana; mso-fareast-font-family: 黑体">MFC</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 黑体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">子类化方法来实现（前三种）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-para-margin-left: 2.0gd; mso-list: l2 level1 lfo1; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">1.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></B><SPAN lang=EN-US>MFC </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">通过维护内部一张</SPAN><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">ChandleMap</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来记录</SPAN><SPAN lang=EN-US>Window</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件与控件子类对象之间的关系。在</SPAN><SPAN lang=EN-US>MFC</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的全局窗口过程</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #880000; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">AfxWndProc</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">(</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">HWND</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">hWnd</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">, </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">UINT</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">nMsg</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">, </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">WPARAM</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">wParam</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">, </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">LPARAM</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">lParam</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">)</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">中，</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">通过调用</SPAN><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">CWnd</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">::</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #880000; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">FromHandlePermanent</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">(</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">HWND</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt"> </SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">hWnd</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">)</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">得到参数句柄所依附的</SPAN><SPAN lang=EN-US>C+</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件子类对象，并调用虚函数</SPAN><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">CWnd</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">::</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">WindowProc</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将相应的消息送给相应的控件子类对象的窗口过程</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-para-margin-left: 2.0gd; mso-list: l2 level1 lfo1; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">2.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件子类对象调用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">CWnd</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">::</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: #880000; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">SubclassWindow</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 0pt">登记</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件与控件子类对象之间的关系</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; mso-para-margin-left: 2.0gd"><A name=_Toc94754448><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 黑体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">第二类方法采用替换窗口过程方法来实现（第四、五种）</SPAN></A><SPAN style="mso-bookmark: _Toc94754448"></SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana; mso-fareast-font-family: 黑体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">肤化技术</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">分析：</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 10.5pt; TEXT-INDENT: 10.5pt; mso-para-margin-left: 1.0gd"><SPAN lang=EN-US style="mso-bidi-font-weight: bold">MFC</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">采用具有层次结构的控件子类设计：通过一张</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">Map</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表建立控件句柄与</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">C++</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象（控件子类对象）的联系，通过控件子类对象的变量来记录和维护控件的状态信息</SPAN><B><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">“肤化”的本质：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt"><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）响应发送给该控件的</SPAN><SPAN lang=EN-US>Windows</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">消息，</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt"><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）用恰当的数据表现出恰当的行为。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其中：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US>1)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以用替换窗体过程来实现，</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"><SPAN lang=EN-US>2)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以用维护自定义控件子类对象和控件句柄的关系来实现。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; mso-para-margin-left: 2.0gd"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">本文独立肤化库采用的方法：</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 42.0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana; mso-fareast-font-family: Verdana; mso-font-kerning: 22.0pt; mso-bidi-font-family: Verdana"><SPAN style="mso-list: Ignore">1.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 22.0pt">目标：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana; mso-font-kerning: 22.0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt; mso-para-margin-left: 2.0gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">肤化目标窗口，接口简单，并且被肤化的窗口影响小。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 42.0pt"><B><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">2.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN></B><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">采用方法：</SPAN><B><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt; mso-para-margin-left: 2.0gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">替换窗口过程</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 42.0pt"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana; mso-fareast-font-family: Verdana; mso-font-kerning: 22.0pt; mso-bidi-font-family: Verdana"><SPAN style="mso-list: Ignore">3.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">难点</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 22.0pt">：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana; mso-font-kerning: 22.0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt; mso-para-margin-left: 2.0gd"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">窗口过程的设计，是否需要为每个类都设计单独的窗口过程？工作量是否过大？</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt; mso-para-margin-left: 2.0gd"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">维护状态变量，当有多个控件共享同一窗口过程时，如何维护它们各自的状态？</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">实现方法</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana">:<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l3 level1 lfo3; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">1.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">仿照</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">MFC</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，建立统一的窗体过程</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">SkinWndProc<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l3 level1 lfo3; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">2.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">建立一张</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">Map</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表，用来登记</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">hWnd</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和自定义控件子类对象之间的联系。</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l3 level1 lfo3; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">3.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建一个皮肤父类，所有的肤化控件均从它派生（类似与</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">MFC</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">CWnd</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">），可以在统一的窗体过程</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">SkinWndProc</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中通过</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">Map</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表找到相应的自定义控件子类对象，并调用其虚函数实现对</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">Windows</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">消息的响应</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l3 level1 lfo3; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">4.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">重载</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">:SubclassWindow</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数，用来完成窗体过程的替换。</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">外部接口：</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo4; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">1.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">SkinDlg(HWND hWnd)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">完成对对话框及其子控件的肤化</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo4; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">2.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">SkinBtn(HWND hWnd, LPCTSTR lpszSection)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">指定采用配制文件的哪一节属性肤化按钮</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo4; tab-stops: list 42.0pt"><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">3.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果需要，提供</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">DonotSkinCtrl(HWND hWnd)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用来指定不需要肤化的控件</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo4; tab-stops: list 42.0pt"><B><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">4.<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">ChangeSkin</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold">LPCTSTR lpszSkinName</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）更换皮肤</SPAN><B><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">框架原理图：<BR><IMG height=351 alt=框架原理图.bmp src="http://www.cppblog.com/images/cppblog_com/chlf/独立的界面肤化库/框架原理图.bmp" width=653 border=0><BR></SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时序图：</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Verdana"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><IMG height=578 alt=时序图：.bmp src="http://www.cppblog.com/images/cppblog_com/chlf/独立的界面肤化库/时序图：.bmp" width=750 border=0></SPAN></P><img src ="http://www.cppblog.com/chlf/aggbug/3296.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/chlf/" target="_blank">VC进阶</a> 2006-02-16 22:46 <a href="http://www.cppblog.com/chlf/archive/2006/02/16/3296.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>