﻿<?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++博客-我住包子山-随笔分类-MFC/SDK</title><link>http://www.cppblog.com/gohan/category/4394.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 27 Jun 2008 18:31:22 GMT</lastBuildDate><pubDate>Fri, 27 Jun 2008 18:31:22 GMT</pubDate><ttl>60</ttl><item><title>向Vista学习，实现XP下重命名文件忽略选取扩展名</title><link>http://www.cppblog.com/gohan/archive/2008/05/17/50122.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Fri, 16 May 2008 18:05:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/05/17/50122.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/50122.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/05/17/50122.html#Feedback</comments><slash:comments>12</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/50122.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/50122.html</trackback:ping><description><![CDATA[<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="129" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/VistaXP_105A/image_1bf4b754-9e02-4945-9552-b70650bc5dbe.png" width="124" align="right" border="0">&nbsp;&nbsp; 这两天对于HOOK的技术有了一个入门的学习，用过vista的同学会发现vista重命名一个文件比如vista.exe，他会自动选中vista忽略掉扩展名，带来比较方便的用户体验，学了一些hook我也想试试xp下能不能做这样的事情。于是参考一些文章，勉强实现了，有一点儿缺陷（请看最后）。</p> <p>&nbsp;&nbsp; 经过观察我发现重命名时，资源管理器会向他的子窗口listview发送一个LVM_EDITLABELA的控制消息，所以我使用了WH_CALLWNDPROCRET类型的全局挂钩，这个挂钩可以在sendmessage结束以后处理传送和返回的数据。发送了LVM_EDITLABELA消息后，会在lParam得到一个编辑窗口的句柄，只需之后对这个窗口发送EM_SETSEL控制消息就能够改变重命名时候的高亮区域。hook回调函数如下：</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">static</span> LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">if</span>(nCode &lt; 0)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         CallNextHookEx(hook,nCode,wParam,lParam);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         <span style="color: #0000ff">return</span> 0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     LPCWPRETSTRUCT msg = (LPCWPRETSTRUCT) lParam;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     <span style="color: #0000ff">if</span>(msg-&gt;message == LVM_EDITLABELA || msg-&gt;message == LVM_EDITLABELW)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>         GetClassName(msg-&gt;hwnd,className,255);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>         GetWindowText(msg-&gt;hwnd,wndName,255);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>         <span style="color: #0000ff">if</span>(0==_tcscmp(className,_TEXT(<span style="color: #006080">"SysListView32"</span>)))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>             <span style="color: #0000ff">if</span>(0==_tcscmp(wndName,_TEXT(<span style="color: #006080">"FolderView"</span>)))</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>             {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>                 hEditWnd = (HWND)msg-&gt;lResult;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>                 GetWindowText(hEditWnd,className,255);<span style="color: #008000">//暂时放入className</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>                 SendMessage(hEditWnd,EM_SETSEL,0,findDot(className));</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>             }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span>     <span style="color: #0000ff">return</span> CallNextHookEx(hook,nCode,wParam,lParam);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span> }</pre></div></div>
<p>&nbsp;</p>
<p>className与wndName是两个TCHAR数组，从hwnd获取信息存在那里进行判断是否为Shell中的listview，避免在其它使用listview的应用程序里会进行之后的处理。</p>
<p>&nbsp;&nbsp; 工程文件下载，<a href="http://www.cppblog.com/Files/gohan/HookDemoSrc.rar" target="_blank">点这里</a></p>
<p>&nbsp;&nbsp; 程序下载，<a href="http://www.cppblog.com/Files/gohan/GRenamer.rar" target="_blank">点这里</a></p>
<p>&nbsp;&nbsp; 使用方法，编译以后直接运行GRnamer就可以，如果不想用了，从任务管理器把它关闭，没有做trayicon之类的东西，因为只是个demo。</p>
<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="48" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/VistaXP_105A/image_11463743-357a-4d42-ac50-b9eeb0b9fa1d.png" width="165" align="left" border="0">&nbsp;&nbsp; 最后说一下缺陷，缺陷就是这样做没有办法判断文件与文件夹的区别，所以会有如图的效果，我自己没有想到解决的方法，请达人们指点。：） </p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; 参考的文章：</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms632589(VS.85).aspx" target="_blank">msdn Hooks</a> hook的全部参考</p>
<p><a href="http://www.codeproject.com/KB/DLL/hooks.aspx" target="_blank">codeproject Hooks and DLLs</a> 我的hook dll都是照着它写的。</p><img src ="http://www.cppblog.com/gohan/aggbug/50122.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-05-17 02:05 <a href="http://www.cppblog.com/gohan/archive/2008/05/17/50122.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>获取给定路径的图标，演示SHGetFileInfo用法</title><link>http://www.cppblog.com/gohan/archive/2008/05/02/48617.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 01 May 2008 20:54:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/05/02/48617.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/48617.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/05/02/48617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/48617.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/48617.html</trackback:ping><description><![CDATA[<div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000"><font color="#000000">基于上次那个</font><a href="http://www.cppblog.com/gohan/archive/2008/04/24/47993.html" target="_blank"><font color="#000000">SHBrowseForFolder用法的演示代码</font></a></span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000"><font color="#000000">建立的仍然是Win32 命令行的工程，所以入口点为main(),需要手动获取HINSTANCE结构。程序在WINXP+VS2005测试通过</font><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="145" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/SHGetFileInfo_3B22/image_3.png" width="199" align="right" border="0"></span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000">/********************************************************************<br>&nbsp; created:&nbsp; 2008/05/02<br>&nbsp; created:&nbsp; 2:5:2008&nbsp;&nbsp; 3:40</span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; main.cpp<br>&nbsp; author:&nbsp;&nbsp;&nbsp; Gohan <br>&nbsp; purpose:&nbsp; 演示SHBrowseForFolder用法<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 演示SHGetFileInfo获取路径图标&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 演示Picture Box在SDK里的使用方法</span></div> <div class="code" style="font-size: 9pt; font-family: consolas"><span style="color: #008000">*********************************************************************/<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">&lt;Windows.h&gt;<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">&lt;ShlObj.h&gt;<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"resource.h"<br></span><span style="color: #000000">HICON</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">g_icon</span><span style="color: #000000">; <br></span><span style="color: #000000">RECT</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">g_rect</span><span style="color: #000000">;<br></span><span style="color: #000000">TCHAR</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">g_path</span><span style="color: #000000">[</span><span style="color: #000000">MAX_PATH</span><span style="color: #000000">];<br></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">OnInitDlg</span><span style="color: #000000">(</span><span style="color: #000000">HWND</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hwnd</span><span style="color: #000000">)<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">GetWindowRect</span><span style="color: #000000">(</span><span style="color: #000000">GetDlgItem</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">, </span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">), &amp;</span><span style="color: #000000">g_rect</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">MapWindowPoints</span><span style="color: #000000">(</span><span style="color: #000000">NULL</span><span style="color: #000000">, </span><span style="color: #000000">hwnd</span><span style="color: #000000">, (</span><span style="color: #000000">LPPOINT</span><span style="color: #000000">) &amp;</span><span style="color: #000000">g_rect</span><span style="color: #000000">, 2);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DestroyWindow</span><span style="color: #000000">(</span><span style="color: #000000">GetDlgItem</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">, </span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">));<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SetDlgItemText</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">,</span><span style="color: #000000">IDC_PATH</span><span style="color: #000000">,</span><span style="color: #000000">g_path</span><span style="color: #000000">);<br>}<br></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">OnPaint</span><span style="color: #000000">(</span><span style="color: #000000">HWND</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hwnd</span><span style="color: #000000">)<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">PAINTSTRUCT</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">ps</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">HDC</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hdc</span><span style="color: #000000"> = </span><span style="color: #000000">BeginPaint</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">, &amp;</span><span style="color: #000000">ps</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DrawIcon</span><span style="color: #000000">(</span><span style="color: #000000">hdc</span><span style="color: #000000">,</span><span style="color: #000000">g_rect</span><span style="color: #000000">.</span><span style="color: #000000">left</span><span style="color: #000000">,</span><span style="color: #000000">g_rect</span><span style="color: #000000">.</span><span style="color: #000000">left</span><span style="color: #000000">,</span><span style="color: #000000">g_icon</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">EndPaint</span><span style="color: #000000">(</span><span style="color: #000000">hwnd</span><span style="color: #000000">,&amp;</span><span style="color: #000000">ps</span><span style="color: #000000">);<br>}<br></span><span style="color: #000000">BOOL</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">CALLBACK</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">DlgProc</span><span style="color: #000000"> (</span><span style="color: #000000">HWND</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hDlg</span><span style="color: #000000">, </span><span style="color: #000000">UINT</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">message</span><span style="color: #000000">, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">WPARAM</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">wParam</span><span style="color: #000000">, </span><span style="color: #000000">LPARAM</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">lParam</span><span style="color: #000000">)<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (</span><span style="color: #000000">message</span><span style="color: #000000">)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">WM_INITDIALOG</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">OnInitDlg</span><span style="color: #000000">(</span><span style="color: #000000">hDlg</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">TRUE</span><span style="color: #000000"> ;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">WM_PAINT</span><span style="color: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">OnPaint</span><span style="color: #000000">(</span><span style="color: #000000">hDlg</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">TRUE</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">WM_COMMAND</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">switch</span><span style="color: #000000"> (</span><span style="color: #000000">LOWORD</span><span style="color: #000000"> (</span><span style="color: #000000">wParam</span><span style="color: #000000">))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDOK</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDCANCEL</span><span style="color: #000000"> :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">EndDialog</span><span style="color: #000000"> (</span><span style="color: #000000">hDlg</span><span style="color: #000000">, 0) ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">TRUE</span><span style="color: #000000"> ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">break</span><span style="color: #000000"> ;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">FALSE</span><span style="color: #000000"> ;<br>}<br></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">main</span><span style="color: #000000">()<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">HINSTANCE</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hInstance</span><span style="color: #000000"> = (</span><span style="color: #000000">HINSTANCE</span><span style="color: #000000">)</span><span style="color: #000000">GetModuleHandle</span><span style="color: #000000">(</span><span style="color: #000000">NULL</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">BROWSEINFO</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">bi</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">ZeroMemory</span><span style="color: #000000">(&amp;</span><span style="color: #000000">bi</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #000000">BROWSEINFO</span><span style="color: #000000">));<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">LPMALLOC</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">pMalloc</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">LPITEMIDLIST</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">pidl</span><span style="color: #000000"> = </span><span style="color: #000000">SHBrowseForFolder</span><span style="color: #000000">(&amp;</span><span style="color: #000000">bi</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">pidl</span><span style="color: #000000"> != </span><span style="color: #000000">NULL</span><span style="color: #000000">)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SHGetPathFromIDList</span><span style="color: #000000">(</span><span style="color: #000000">pidl</span><span style="color: #000000">,</span><span style="color: #000000">g_path</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SHFILEINFO</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">sfi</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">ZeroMemory</span><span style="color: #000000">(&amp;</span><span style="color: #000000">sfi</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #000000">SHFILEINFO</span><span style="color: #000000">));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">SHGetFileInfo</span><span style="color: #000000">(</span><span style="color: #000000">g_path</span><span style="color: #000000">,0,&amp;</span><span style="color: #000000">sfi</span><span style="color: #000000">,</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(</span><span style="color: #000000">SHFILEINFO</span><span style="color: #000000">),</span><span style="color: #000000">SHGFI_ICON</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">g_icon</span><span style="color: #000000"> = </span><span style="color: #000000">sfi</span><span style="color: #000000">.</span><span style="color: #000000">hIcon</span><span style="color: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DialogBox</span><span style="color: #000000"> (</span><span style="color: #000000">hInstance</span><span style="color: #000000">, </span><span style="color: #000000">MAKEINTRESOURCE</span><span style="color: #000000">(</span><span style="color: #000000">IDD_DIALOG1</span><span style="color: #000000">), 0, </span><span style="color: #000000">DlgProc</span><span style="color: #000000">) ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #008000">//MessageBox(NULL,path,TEXT("Choose"),MB_OK);<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">SUCCEEDED</span><span style="color: #000000">(</span><span style="color: #000000">SHGetMalloc</span><span style="color: #000000">(&amp;</span><span style="color: #000000">pMalloc</span><span style="color: #000000">)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">pMalloc</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Free</span><span style="color: #000000">(</span><span style="color: #000000">pidl</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">pMalloc</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Release</span><span style="color: #000000">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">else<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">MessageBox</span><span style="color: #000000">(</span><span style="color: #000000">NULL</span><span style="color: #000000">,</span><span style="color: #000000">TEXT</span><span style="color: #000000">(</span><span style="color: #800000">"</span><span style="color: #000000">),</span><span style="color: #000000">TEXT</span><span style="color: #000000">(</span><span style="color: #800000">"Choose"</span><span style="color: #000000">),</span><span style="color: #000000">MB_OK</span><span style="color: #000000">);<br>&nbsp;&nbsp;&nbsp; }<br>}<br><span style="color: #008000">/************************************************************************/<br>/* resource.h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>/************************************************************************/<br></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDD_DIALOG1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 101<br></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDC_PATH</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1001<br></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1002<br></span><span style="color: #008000">/************************************************************************/<br>/* demo.rc Microsoft Visual C++ generated resource script.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */<br>/************************************************************************/<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"resource.h"<br></span><span style="color: #0000ff">#include</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"afxres.h"<br></span><span style="color: #008000">/////////////////////////////////////////////////////////////////////////////<br>//<br>// Dialog<br>//<br><br></span><span style="color: #000000">IDD_DIALOG1</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">DIALOGEX</span><span style="color: #000000"> 0, 0, 126, 83<br></span><span style="color: #000000">STYLE</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">DS_SETFONT</span><span style="color: #000000"> | </span><span style="color: #000000">DS_MODALFRAME</span><span style="color: #000000"> | </span><span style="color: #000000">DS_FIXEDSYS</span><span style="color: #000000"> | </span><span style="color: #000000">DS_CENTER</span><span style="color: #000000"> | </span><span style="color: #000000">WS_POPUP<br>FONT</span><span style="color: #000000"> 8, </span><span style="color: #800000">"MS Shell Dlg"</span><span style="color: #000000">, 400, 0, 0x1<br></span><span style="color: #000000">BEGIN<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">DEFPUSHBUTTON</span><span style="color: #000000">&nbsp;&nbsp; </span><span style="color: #800000">"确定"</span><span style="color: #000000">,</span><span style="color: #000000">IDOK</span><span style="color: #000000">,69,7,50,14<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">PUSHBUTTON</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #800000">"取消"</span><span style="color: #000000">,</span><span style="color: #000000">IDCANCEL</span><span style="color: #000000">,69,24,50,14<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">CONTROL</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #800000">""</span><span style="color: #000000">,</span><span style="color: #000000">IDC_ICON1</span><span style="color: #000000">,</span><span style="color: #800000">"Static"</span><span style="color: #000000">,</span><span style="color: #000000">SS_WHITEFRAME</span><span style="color: #000000"> | </span><span style="color: #000000">SS_REALSIZEIMAGE</span><span style="color: #000000">,13,10,20,20,</span><span style="color: #000000">WS_EX_TRANSPARENT<br></span><span style="color: #000000">&nbsp;&nbsp;&nbsp; </span><span style="color: #000000">LTEXT</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #800000">"静态"</span><span style="color: #000000">,</span><span style="color: #000000">IDC_PATH</span><span style="color: #000000">,14,44,89,21,0,</span><span style="color: #000000">WS_EX_CLIENTEDGE<br>END<br><br><br></span><span style="color: #008000">/////////////////////////////////////////////////////////////////////////////<br></span></div><img src ="http://www.cppblog.com/gohan/aggbug/48617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-05-02 04:54 <a href="http://www.cppblog.com/gohan/archive/2008/05/02/48617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>浏览文件夹对话框，演示SHBrowseForFolder用法</title><link>http://www.cppblog.com/gohan/archive/2008/04/24/47993.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 24 Apr 2008 05:15:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/04/24/47993.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/47993.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/04/24/47993.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/47993.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/47993.html</trackback:ping><description><![CDATA[<div class="code" style="font-size: 9pt; font-family: consolas;"><a href="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/SHBrowseForFolder_BA3A/image_2.png"><img style="border: 0px none ;" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/SHBrowseForFolder_BA3A/image_thumb.png" align="right" border="0" height="240" width="244"></a> </div>
<div class="code" style="font-size: 9pt; font-family: consolas;"><span style="color: #008000;">/********************************************************************<br>&nbsp; created:&nbsp; 2008/04/24<br>&nbsp; created:&nbsp; 24:4:2008&nbsp;&nbsp; 12:47<br>&nbsp; author:&nbsp;&nbsp;&nbsp; Gohan <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http://feed.feedsky.com/gohan<br>&nbsp; purpose:&nbsp; 演示SHBrowseForFolder用法<br>*********************************************************************/<br></span><span style="color: #0000ff;">#include</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">&lt;Windows.h&gt;<br></span><span style="color: #0000ff;">#include</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">&lt;ShlObj.h&gt;<br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">main</span><span style="color: #000000;">()<br>{<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">BROWSEINFO</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">bi</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">ZeroMemory</span><span style="color: #000000;">(&amp;</span><span style="color: #000000;">bi</span><span style="color: #000000;">,</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(</span><span style="color: #000000;">BROWSEINFO</span><span style="color: #000000;">));<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">LPMALLOC</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">LPITEMIDLIST</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">pidl</span><span style="color: #000000;"> = </span><span style="color: #000000;">SHBrowseForFolder</span><span style="color: #000000;">(&amp;</span><span style="color: #000000;">bi</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">TCHAR</span><span style="color: #000000;"> * </span><span style="color: #000000;">path</span><span style="color: #000000;"> = </span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">TCHAR</span><span style="color: #000000;">[</span><span style="color: #000000;">MAX_PATH</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #000000;">pidl</span><span style="color: #000000;"> != </span><span style="color: #000000;">NULL</span><span style="color: #000000;">)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">SHGetPathFromIDList</span><span style="color: #000000;">(</span><span style="color: #000000;">pidl</span><span style="color: #000000;">,</span><span style="color: #000000;">path</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">MessageBox</span><span style="color: #000000;">(</span><span style="color: #000000;">NULL</span><span style="color: #000000;">,</span><span style="color: #000000;">path</span><span style="color: #000000;">,</span><span style="color: #000000;">TEXT</span><span style="color: #000000;">(</span><span style="color: #800000;">"Choose"</span><span style="color: #000000;">),</span><span style="color: #000000;">MB_OK</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #000000;">SUCCEEDED</span><span style="color: #000000;">(</span><span style="color: #000000;">SHGetMalloc</span><span style="color: #000000;">(&amp;</span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">)))</span><span style="color: #008000;">//pidl指向的对象用完应该释放，之前忽略了<br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Free</span><span style="color: #000000;">(</span><span style="color: #000000;">pidl</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">pMalloc</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Release</span><span style="color: #000000;">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">else<br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #000000;">MessageBox</span><span style="color: #000000;">(</span><span style="color: #000000;">NULL</span><span style="color: #000000;">,</span><span style="color: #000000;">TEXT</span><span style="color: #000000;">(</span><span style="color: #800000;">"</span><span style="color: #800000;">选择为空"</span><span style="color: #000000;">),</span><span style="color: #000000;">TEXT</span><span style="color: #000000;">(</span><span style="color: #800000;">"Choose"</span><span style="color: #000000;">),</span><span style="color: #000000;">MB_OK</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff;">delete</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">path</span><span style="color: #000000;">;</span><span style="color: #008000;">//谢谢true的提醒，以后我一定会更加慎重<br></span><span style="color: #000000;">}<br></span></div>
<div class="code" style="font-size: 9pt; font-family: consolas;"><span style="color: #008000;"></span><span style="color: #000000;"><br></span></div><img src ="http://www.cppblog.com/gohan/aggbug/47993.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-04-24 13:15 <a href="http://www.cppblog.com/gohan/archive/2008/04/24/47993.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>LPC 的一个示例（Ntdll Port API test）</title><link>http://www.cppblog.com/gohan/archive/2008/02/28/43367.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Wed, 27 Feb 2008 16:48:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/02/28/43367.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/43367.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/02/28/43367.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/43367.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/43367.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 之前小小学了一点win32 LPC的知识，这个sample是wine ref的一个test，感觉已经很全面。今天还找来了两本关于Ntdll方面的电子书，Windows_2000_Native_API_Reference，Undocumented Windows 2000 Secrets..都是英文书，慢慢啃。  1 /* Unit test suite for Ntdll Port API fun...&nbsp;&nbsp;<a href='http://www.cppblog.com/gohan/archive/2008/02/28/43367.html'>阅读全文</a><img src ="http://www.cppblog.com/gohan/aggbug/43367.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-02-28 00:48 <a href="http://www.cppblog.com/gohan/archive/2008/02/28/43367.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Up/Down控件（spin control）使用方法的一点小心得</title><link>http://www.cppblog.com/gohan/archive/2008/02/06/42558.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Tue, 05 Feb 2008 18:14:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/02/06/42558.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/42558.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/02/06/42558.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/42558.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/42558.html</trackback:ping><description><![CDATA[<table cellspacing="0" cellpadding="2" width="768" border="0"> <tbody> <tr> <td valign="top" width="10"><a href="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/UpDownspincontrol_1F69/image_4.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="175" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/UpDownspincontrol_1F69/image_thumb_1.png" width="244" border="0"></a>&nbsp;</td> <td valign="top" width="505">&nbsp; 学用纯SDK写win32程序，资料有一个<a href="http://www.douban.com/subject/1456779/" target="_blank">英文版Windows Programming</a>电子书，以及MSDN，用到了Up/Down控件让用户输入数据，同时也提供了Edit box.两者的同步是否会有问题呢？<br>&nbsp; 尝试了半天，终于有了点结果：<br>1、初始化控件，对控件句柄发送<a href="http://msdn2.microsoft.com/en-us/library/bb759968(VS.85).aspx" target="_blank">UDM_SETRANGE32</a>消息，进行范围的初始话。<a href="http://msdn2.microsoft.com/en-us/library/bb759958(VS.85).aspx" target="_blank">UDM_SETPOS32</a>消息设置初值。<br>&nbsp;&nbsp;&nbsp; </td> <td valign="top" width="250"><a href="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/UpDownspincontrol_1F69/image_2.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="145" alt="image" src="http://www.cppblog.com/images/cppblog_com/gohan/WindowsLiveWriter/UpDownspincontrol_1F69/image_thumb.png" width="244" border="0"></a><br> </td></tr></tbody></table> <table cellspacing="0" cellpadding="2" width="770" border="0"> <tbody> <tr> <td valign="top" width="770">2、关联Edit Box 控件，这个我弄了半天才明白，首先要在资源编辑中的对话框编辑界面，设定Tab控件的顺序（格式-&gt;Tab键顺序）。<font color="#ff0000">将Edit Box的序号设置成Up/Down控件序号减一，设定Up/Down的属性Auto Buddy为True，Set Buddy Integer为true。<br></font><font color="#000000">3、现在已经能够正常的使用Up/Down功能了。<br>&nbsp; <font color="#ff0000">可是如果不想用控件关联</font>，而是自己设定逻辑怎么办呢？几个小时之前我不会关联的方法，想要努力实现手动维护Edit box的功能。最后终于有了些教训，得到了点心得：<br>&nbsp; 在Up/Down的父窗口（一般是对话框）的消息处理函数中，对<a href="http://msdn2.microsoft.com/en-us/library/ms912690.aspx" target="_blank">WM_VSCROLL</a>消息做一个处理，<font color="#000000">当lParam与Up/Down的窗口句柄相等时，对Up/Down的操作结束</font> ，其中wParam中的高位部分是Up/Down的值，用这个值来更新Edit Box。<br>WM_VSCROLL nScrollCode = (int)LOWORD(wParam); <br>&nbsp; nPos = (short int)HIWORD(wParam); <br>&nbsp; hwndScrollBar = (HWND) lParam;<br><br>&nbsp; 今天我的教训是使用了<a href="http://msdn2.microsoft.com/en-us/library/bb775583%28VS.85%29.aspx" target="_blank">WM_NOTIFY</a>的消息，处理<a href="http://msdn2.microsoft.com/en-us/library/bb759903(VS.85).aspx" target="_blank">UDN_DELTAPOS</a>的通知，lParam是一个结构：<a href="http://msdn2.microsoft.com/en-us/library/bb759893%28VS.85%29.aspx" target="_blank">NMUPDOWN</a>，通过这个结构来更新Edit box，因为这个通知不等操作结束就已经发出，并且这个结构体中有当时的位置以及变化量，更新时候还需要将当时位置加上变化量。这样的更新就会出现一定的问题，有时候pos已经到了设定好的范围边界，pos加上变化量就会超出边界，还要继续判断，效率等等问题就出现了，而且十分麻烦。所以最好使用关联的方法，如果有特殊要求就用<font color="#000000"><a href="http://msdn2.microsoft.com/en-us/library/ms912690.aspx" target="_blank">WM_VSCROLL</a>响应，<font color="#ff0000">千万不要使用</font><a href="http://msdn2.microsoft.com/en-us/library/bb759903(VS.85).aspx" target="_blank"><font color="#ff0000">UDN_DELTAPOS</font></a><font color="#ff0000">，白花功夫</font>，呵呵。就写到这里.<br> <h4><strong><font color="#004080">今天是除夕了，祝所有程序员朋友新春快乐！！</font></strong></h4></font></font></td></tr></tbody></table><img src ="http://www.cppblog.com/gohan/aggbug/42558.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-02-06 02:14 <a href="http://www.cppblog.com/gohan/archive/2008/02/06/42558.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>翻译习作:Create your own controls - the art of subclassing 子类化,继承公共控件</title><link>http://www.cppblog.com/gohan/archive/2008/01/25/41852.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Thu, 24 Jan 2008 16:02:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2008/01/25/41852.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/41852.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2008/01/25/41852.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/41852.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/41852.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Create your own controls - the art of subclassingBy Chris MaunderAn introduction to subclassing the Windows common controls using MFCIntroduction程序员们可以用许多windows通用控件提供的功能方便的编程,这些控件从list到button甚至...&nbsp;&nbsp;<a href='http://www.cppblog.com/gohan/archive/2008/01/25/41852.html'>阅读全文</a><img src ="http://www.cppblog.com/gohan/aggbug/41852.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2008-01-25 00:02 <a href="http://www.cppblog.com/gohan/archive/2008/01/25/41852.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC++编程内幕学习心得(2)--下</title><link>http://www.cppblog.com/gohan/archive/2007/12/08/38045.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sat, 08 Dec 2007 10:04:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/12/08/38045.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/38045.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/12/08/38045.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/38045.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/38045.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 接着上回开始 书上的第二个例子 直接贴我略加修改的代码,后面附有注释: void Cfont2View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) {//想说的是OnPrepareDC在每次调用OnDraw之前调用,可在里面进行初始化的一些操作 &nbsp;&nbsp;&nbsp; CRect clientRect; &nbsp;&nbsp;&nbsp;  ...&nbsp;&nbsp;<a href='http://www.cppblog.com/gohan/archive/2007/12/08/38045.html'>阅读全文</a><img src ="http://www.cppblog.com/gohan/aggbug/38045.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-12-08 18:04 <a href="http://www.cppblog.com/gohan/archive/2007/12/08/38045.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC++编程内幕学习心得(2)--上</title><link>http://www.cppblog.com/gohan/archive/2007/11/26/37345.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Mon, 26 Nov 2007 13:46:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/11/26/37345.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/37345.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/11/26/37345.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/37345.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/37345.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 第六章 GDI,字体,位图 第五章的例子就有简单的CDC类型的应用 这次更加详细的总结了设备环境类型及其应用常用类型CClientDC和CWindowDC,算做显示设备函数 CDC::GetClipBox(LPRECT lpRect)能够获取当前操作dc可见的区域矩形吧,我大概这样子理解.当然,映射模式不同的情况得到的值也不一样,是逻辑坐标单位 只有改写视图类的OnPaint类时才会用CPaint...&nbsp;&nbsp;<a href='http://www.cppblog.com/gohan/archive/2007/11/26/37345.html'>阅读全文</a><img src ="http://www.cppblog.com/gohan/aggbug/37345.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-11-26 21:46 <a href="http://www.cppblog.com/gohan/archive/2007/11/26/37345.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vc++技术内幕学习心得1</title><link>http://www.cppblog.com/gohan/archive/2007/11/23/37213.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Fri, 23 Nov 2007 08:37:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/11/23/37213.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/37213.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/11/23/37213.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/37213.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/37213.html</trackback:ping><description><![CDATA[<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">这篇心得关于技术内幕第五章,比较的基础..<br>我是VC++的初学者<br>vc++</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">技术内幕这本书我是去年暑假开始看的<span lang=EN-US>,</span>那时候刚学<span lang=EN-US>windows</span>编程<span lang=EN-US>,</span>虽然之前用过<span lang=EN-US>c#,vb,</span>不过都没怎么练习<span lang=EN-US>,</span>这本书我大概看了前面的<span lang=EN-US>80%,</span>不过都未曾动手<span lang=EN-US>,</span>近日打算从头练习一下<span lang=EN-US>,</span>在这里记些笔记<span lang=EN-US><br></span><strong style="mso-bidi-font-weight: normal">第五章第一个例子很简单</strong><span lang=EN-US><br></span>一个单文档<span lang=EN-US>MFC</span>应用程序<span lang=EN-US>,View</span>类中一个<span lang=EN-US>CRect</span>类型变量保存矩形的信息<span lang=EN-US>,</span>一个<span lang=EN-US>int</span>型保存矩形颜色的属性<span lang=EN-US><br>WM_LBUTTONDOWN</span>响应函数判断单击左键时鼠标位置是不是在之前那个矩形区域内<span lang=EN-US>,</span>是的话变换矩形颜色的属性<span lang=EN-US>,</span>而且命令矩形区域重绘<span lang=EN-US>..<br>OnDraw()</span>中用<span lang=EN-US>dc</span>选取矩形颜色<span lang=EN-US>,</span>绘制矩形的内切椭圆<span lang=EN-US><br><br></span>应用的函数有<span lang=EN-US>:<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">virtual CGdiObject* <strong>CDC::SelectStockObject</strong>(<o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">int nIndex<o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">);//</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">选取颜色<span lang=EN-US>,</span>这里只选画刷大概有如下画刷<span lang=EN-US><br>BLACK_BRUSH DKGRAY_BRUSH GRAY_BRUSH HOLLOW_BRUSH LTGRAY_BRUSH NULL_BRUSH WHITE_BRUSH<br>BOOL <strong>CDC::Ellipse</strong>(LPCRECT lpRect);//</span>画矩形对应的内切椭圆<span lang=EN-US><br>BOOL <strong>CRECT::PtInRect</strong>( <o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">POINT point&nbsp; <o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">) const throw( );//</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">判断<span lang=EN-US>point</span>是否在矩形中<span lang=EN-US><o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">注意一点就是</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">CView::OnLButtonDown(UINT nFlags, CPoint point)<br></span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">这里的</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">Point</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">坐标是</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">View</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">的</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">client</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">坐标</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">如果需要全局坐标需要转换</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">&nbsp; <o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">第二个例子关于映射模式</span></strong><strong style="mso-bidi-font-weight: normal"><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p></o:p></span></strong></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">不同的映射模式</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">对应的坐标是有区别的</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">而且他们的逻辑单位比例都不同</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">固定比例的映射模式有</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></span></p>
<table class=MsoNormalTable style="mso-cellspacing: 1.5pt; mso-padding-alt: 0cm 0cm 0cm 0cm" cellPadding=0 border=0>
    <thead>
        <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">Mapping Mode<o:p></o:p></span></p>
            </td>
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">Logical Unit<o:p></o:p></span></p>
            </td>
        </tr>
    </thead>
    <tbody>
        <tr style="mso-yfti-irow: 1">
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">MM_LOENGLISH<o:p></o:p></span></p>
            </td>
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">0.01 inch<o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 2">
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">MM_HIENGLISH<o:p></o:p></span></p>
            </td>
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">0.001 inch<o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 3">
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">MM_LOMETRIC<o:p></o:p></span></p>
            </td>
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><st1:chmetcnv tcsc="0" numbertype="1" negative="False" hasspace="True" sourcevalue=".1" unitname="mm" w:st="on"><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">0.1 mm</span></st1:chmetcnv><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 4">
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">MM_HIMETRIC<o:p></o:p></span></p>
            </td>
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><st1:chmetcnv tcsc="0" numbertype="1" negative="False" hasspace="True" sourcevalue=".01" unitname="mm" w:st="on"><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">0.01 mm</span></st1:chmetcnv><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes">
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">MM_TWIPS<o:p></o:p></span></p>
            </td>
            <td style="PADDING-RIGHT: 0cm; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; PADDING-TOP: 0cm">
            <p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">1/1440 inch<o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">可变比例的映射模式</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">MM_ISOTROPIC and MM_ANISOTROPIC<o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">我自己写了一个</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">Demo</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">看了一下</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">好像只有</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">MM_ANISOTROPIC</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">跟</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">MM_TEXT</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">是</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">x</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">轴左向右</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,y</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">轴上到下</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,DC</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">原点为</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">0,0<o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">其他的映射模式</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">x</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">轴一样</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,y</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">轴变成了从下至上</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">,DC</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">原点还是</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">0,0<o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">CDC</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">的几个函数这里有必要说说</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><br>virtual int CDC::SetMapMode(<br>&nbsp;&nbsp; int nMapMode <br>);<br>int CDC::GetMapMode() const;<br></span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">设置</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">/</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">读取</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">DC</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">的映射模式</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">virtual CSize CDC::SetWindowExt(<br>&nbsp;&nbsp; int cx,<br>&nbsp;&nbsp; int cy <br>);//</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: courier; mso-bidi-font-size: 10.5pt">设置窗体范围</span><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">virtual CSize CDC::SetViewportExt(<br>&nbsp;&nbsp; int cx,<br>&nbsp;&nbsp; int cy <br>);//</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-size: 10.5pt">设置视口范围</span><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">virtual CPoint CDC::SetViewportOrg(<br>&nbsp;&nbsp; int x,<br>&nbsp;&nbsp; int y <br>);//</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-size: 10.5pt">设置</span><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">(0,0)</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-size: 10.5pt">点的位置</span><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">窗体范围和视口范围的设置会影响可变比例映射</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><br></span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">可变比例映射的</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt">x,y</span><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: arial; mso-font-kerning: 0pt; mso-ascii-font-family: arial; mso-hansi-font-family: arial">计算方法参看下面的公式</span><span lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: arial; mso-font-kerning: 0pt"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><strong style="mso-bidi-font-weight: normal"><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">x scale factor = x viewport extent / x window extent<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></strong></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><strong style="mso-bidi-font-weight: normal"><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">y scale factor = y viewport extent / y window extent<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></strong></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><strong style="mso-bidi-font-weight: normal"><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">device x = logical x* x scale factor + x origin offset<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></strong></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align=left><strong style="mso-bidi-font-weight: normal"><span lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">device y = logical y* y scale factor + y origin offset<o:p></o:p></span></strong></p>
<p class=MsoNormal><span lang=EN-US>CDC</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">成员函数的参数大都是用逻辑坐标</span><span lang=EN-US>,</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是</span><span lang=EN-US>CWnd</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的成员却以设备坐标为参数</span></p>
<p class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是</span><span lang=EN-US>CDC</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">成员中有函数</span></p>
<p class=MsoNormal><span lang=EN-US>LPtoDP,</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将逻辑坐标转换为设备坐标</span></p>
<div style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: white 1pt solid; PADDING-LEFT: 0cm; BACKGROUND: #f7f7ff; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 4pt; BORDER-BOTTOM: medium none; mso-element: para-border-div; mso-border-top-alt: solid white .75pt">
<p class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f7f7ff; MARGIN-BOTTOM: 7.5pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 4.0pt 0cm 0cm 0cm; mso-border-top-alt: solid white .75pt" align=left><span lang=EN-US style="FONT-SIZE: 9pt; COLOR: #000066; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt">void LPtoDP( LPPOINT lpPoints, int nCount = 1 ) const; void LPtoDP( LPRECT lpRect ) const; void LPtoDP( LPSIZE lpSize ) const;<br></span><span lang=EN-US>DPtoLP,</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: 9pt; COLOR: #000066; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt"><o:p></o:p></span></p>
<p class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f7f7ff; MARGIN-BOTTOM: 7.5pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 4.0pt 0cm 0cm 0cm; mso-border-top-alt: solid white .75pt" align=left><span lang=EN-US style="FONT-SIZE: 9pt; COLOR: #000066; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt">void DPtoLP( LPPOINT lpPoints, int nCount = 1 ) const; void DPtoLP( LPRECT lpRect ) const; void DPtoLP( LPSIZE lpSize ) const;<o:p></o:p></span></p>
</div>
<p class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第三个例子关于滚动条</span></p>
<p class=MsoNormal><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文档视图的工程建立向导中可以让</span><span lang=EN-US>View</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">继承自</span><span lang=EN-US>CScrollView,</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使得</span><span lang=EN-US>View</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">带有滚动条</span></p>
<p class=MsoNormal><span lang=EN-US>OnInitialUpdate</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数在视图建立后</span><span lang=EN-US>,OnDraw</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">执行之前执行</span><span lang=EN-US>,</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="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><strong><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">void</span></strong><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"> CScrollingViewWindowView<span style="COLOR: red">::</span>OnInitialUpdate<span style="COLOR: red">()<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </span>CScrollView<span style="COLOR: red">::</span>OnInitialUpdate<span style="COLOR: red">();<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </span>CSize sizeTotal<span style="COLOR: red">;<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: green">// TODO: </span></span><span style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">计算此视图的合计大小</span><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </span>sizeTotal<span style="COLOR: red">.</span>cx <span style="COLOR: red">=</span> 20000<span style="COLOR: red">;</span> <span style="COLOR: green">//<st1:chmetcnv tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="20" unitname="cm" w:st="on">20cm</st1:chmetcnv><o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>sizeTotal<span style="COLOR: red">.</span>cy <span style="COLOR: red">=</span> 30000<span style="COLOR: red">;</span> <span style="COLOR: green">//<st1:chmetcnv tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="30" unitname="cm" w:st="on">30cm</st1:chmetcnv><o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>CSize sizePage<span style="COLOR: red">(</span>sizeTotal<span style="COLOR: red">.</span>cx<span style="COLOR: red">/</span>2<span style="COLOR: red">,</span>sizeTotal<span style="COLOR: red">.</span>cy<span style="COLOR: red">/</span>2<span style="COLOR: red">);<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>CSize sizeLine<span style="COLOR: red">(</span>sizeTotal<span style="COLOR: red">.</span>cx<span style="COLOR: red">/</span>50<span style="COLOR: red">,</span>sizeTotal<span style="COLOR: red">.</span>cy<span style="COLOR: red">/</span>50<span style="COLOR: red">);<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>SetScrollSizes<span style="COLOR: red">(</span>MM_TEXT<span style="COLOR: red">,</span> sizeTotal<span style="COLOR: red">,</span>sizePage<span style="COLOR: red">,</span>sizeLine<span style="COLOR: red">);<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">虽然是初始化了滚动条</span><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">,</span><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">但是不能够使用快捷键</span><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">(</span><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">上下左右</span><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">,pagedown</span><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">啥的</span><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">),</span><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">需要手动重载</span><span lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">afx_msg <strong><span style="COLOR: blue">void</span></strong> OnKeyDown<span style="COLOR: red">(</span>UINT nChar<span style="COLOR: red">,</span> UINT nRepCnt<span style="COLOR: red">,</span> UINT nFlags<span style="COLOR: red">);<o:p></o:p></span></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">需要用到</span><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes">CWnd::OnVScroll, CWnd::OnHScroll,</span><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: consolas; mso-hansi-font-family: consolas; mso-no-proof: yes">分别控制纵向与横向两个滚动条</span><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: consolas; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class=MsoNormal style="TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><em><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">nSBCode</span></em><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 3pt 0cm 3pt 47.25pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">Specifies a scroll-bar code that indicates the user's scrolling request. This parameter can be one of the following:<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_BOTTOM</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Scroll to bottom.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_ENDSCROLL</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; End scroll.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_LINEDOWN</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Scroll one line down.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_LINEUP</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Scroll one line up.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_PAGEDOWN</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Scroll one page down.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_PAGEUP</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Scroll one page up.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_THUMBPOSITION</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Scroll to the absolute position. The current position is provided in </span><em><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">nPos</span></em><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_THUMBTRACK</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Drag scroll box to specified position. The current position is provided in </span><em><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">nPos</span></em><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">.<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 1.5pt 0cm 1.5pt 60pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1" align=left><span lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: symbol; mso-bidi-font-family: symbol; mso-font-kerning: 0pt; mso-bidi-font-size: 8.5pt; mso-fareast-font-family: symbol"><span style="mso-list: ignore">&#183;<span style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SB_TOP</span></strong><span lang=EN-US style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&nbsp;&nbsp; Scroll to top.<o:p></o:p></span></p>
<blockquote>
<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; by gohan 11.23</o:p></span></p>
</blockquote>
<img src ="http://www.cppblog.com/gohan/aggbug/37213.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-11-23 16:37 <a href="http://www.cppblog.com/gohan/archive/2007/11/23/37213.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SubclassWindow 一个函数,其实是个宏</title><link>http://www.cppblog.com/gohan/archive/2007/06/03/25361.html</link><dc:creator>Gohan</dc:creator><author>Gohan</author><pubDate>Sat, 02 Jun 2007 16:26:00 GMT</pubDate><guid>http://www.cppblog.com/gohan/archive/2007/06/03/25361.html</guid><wfw:comment>http://www.cppblog.com/gohan/comments/25361.html</wfw:comment><comments>http://www.cppblog.com/gohan/archive/2007/06/03/25361.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/gohan/comments/commentRss/25361.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/gohan/services/trackbacks/25361.html</trackback:ping><description><![CDATA[#define&nbsp;&nbsp;&nbsp;&nbsp; SubclassWindow(hwnd, lpfn)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((WNDPROC)SetWindowLongPtr((hwnd), GWLP_WNDPROC, (LPARAM)(WNDPROC)(lpfn)))<br><br>这个宏是我看第七章winshellprograming看到的,很强大的功能,例子是用FindWindowEx找到windows开始按钮的窗口句柄,之后用该宏加入开始按钮的消息处理函数.总之还不错,winshell还真不是一般..<br>MSDN上查SubclassWindow都不是我要的这个,虽然功能大体相同吧.<br>下面这个就是SetWindowLongPtr函数:<br>
<div class="title">SetWindowLongPtr Function</div>
<!--content type: SDKML. Transform: psdk2mtps.xslt.-->
<div class="clsDocBody">
<p>
</p>
<p>The <strong>SetWindowLongPtr</strong> function changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory.<br><br>这个函数改变一个指定窗口的一个属性.它也可设定窗口储存区指定偏移位置的值。<br></p>
<p>This function supersedes the <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl01',this);" href="http://msdn2.microsoft.com/en-us/library/ms633591.aspx"><u><font color="#0000ff">SetWindowLong</font></u></a> function. To write code that is compatible with both 32-bit and 64-bit versions of Microsoft Windows, use <strong>SetWindowLongPtr</strong>.<br>这个函数取代了SetWindowLong函数,为了兼容32位64位windows os,就用这个函数吧 .<br></p>
<p class="clsRef">Syntax</p>
<blockquote>
<div class="code" id="ctl00_LibFrame_ctl02_">LONG_PTR&nbsp;SetWindowLongPtr(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;HWND&nbsp;<em>hWnd</em>,<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;<em>nIndex</em>,<br>&nbsp;&nbsp;&nbsp;&nbsp;LONG_PTR&nbsp;<em>dwNewLong</em><br>);</div>
</blockquote>
<p class="clsRef">Parameters</p>
<blockquote>
<dl>
<dt><em>hWnd</em>
</dt><dd>[in]&nbsp;Handle to the window and, indirectly, the class to which the window belongs. The <strong>SetWindowLongPtr</strong> function fails if the process that owns the window specified by the <em>hWnd</em> parameter is at a higher process privilege in the User Interface Privilege Isolation (UIPI) hierarchy than the process the calling thread resides in.
</dd><dd>返回fail当拥有指定窗口的京城比用户UI权限隔绝(??)高的时候..不知道翻译对不
</dd><dd>
<p><strong>Microsoft Windows XP and earlier:</strong> The <strong>SetWindowLongPtr</strong> function fails if the window specified by the <em>hWnd</em> parameter does not belong to the same process as the calling thread.<br><br>这个意思大概是函数失败如果调用进程传入的hWnd句柄不属于调用包含这个函数的线程的进程（应用程序）.</p>
</dd><dt><em>nIndex</em>
</dt><dd>[in]&nbsp;Specifies the zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer. To set any other value, specify one of the following values.
</dd><dd>这个不用翻译了,很明了哈哈
</dd><dd>
<dl>
<dt><span class="clsRange"><!----></span>
</dt><dd>
<dl>
<dt><code>GWL_EXSTYLE</code>
</dt><dd>Sets a new extended window style. For more information, see <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl03',this);" href="http://msdn2.microsoft.com/en-us/library/ms632680.aspx"><u><font color="#0000ff">CreateWindowEx</font></u></a>.
</dd><dt><code>GWL_STYLE</code>
</dt><dd>Sets a new <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl04',this);" href="http://msdn2.microsoft.com/en-us/library/ms632600.aspx"><u><font color="#0000ff">window style</font></u></a>.
</dd><dt><code>GWLP_WNDPROC</code>
</dt><dd>Sets a new address for the window procedure.
</dd><dt><code>GWLP_HINSTANCE</code>
</dt><dd>Sets a new application instance handle.
</dd><dt><code>GWLP_ID</code>
</dt><dd>Sets a new identifier of the window.
</dd><dt><code>GWLP_USERDATA</code>
</dt><dd>Sets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.</dd></dl>
</dd><dt><span class="clsRange"><!----></span>
</dt><dd>The following values are also available when the <em>hWnd</em> parameter identifies a dialog box.
<dl>
<dt><code>DWLP_DLGPROC</code>
</dt><dd>Sets the new pointer to the dialog box procedure.
</dd><dt><code>DWLP_MSGRESULT</code>
</dt><dd>Sets the return value of a message processed in the dialog box procedure.
</dd><dt><code>DWLP_USER</code>
</dt><dd>Sets new extra information that is private to the application, such as handles or pointers.</dd></dl></dd></dl>
</dd><dt><em>dwNewLong</em>
</dt><dd>[in]&nbsp;Specifies the replacement value. </dd></dl></blockquote>
<p class="clsRef">Return Value</p>
<blockquote>
<p>If the function succeeds, the return value is the previous value of the specified offset.<br>成功返回的是设置前的值LONG_PTR这个类型<br></p>
<p>If the function fails, the return value is zero. To get extended error information, call <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl05',this);" href="http://msdn2.microsoft.com/en-us/library/ms679360.aspx"><u><font color="#0000ff">GetLastError</font></u></a>. </p>
<p>If the previous value is zero and the function succeeds, the return value is zero, but the function does not clear the last error information. To determine success or failure, clear the last error information by calling <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl06',this);" href="http://msdn2.microsoft.com/en-us/library/ms680627.aspx"><u><font color="#0000ff">SetLastError</font></u></a>(0), then call <strong>SetWindowLongPtr</strong>. Function failure will be indicated by a return value of zero and a <strong>GetLastError</strong> result that is nonzero.</p>
<br></blockquote>
<p class="clsRef">Remarks</p>
<blockquote>
<p>Certain window data is cached, so changes you make using <strong>SetWindowLongPtr</strong> will not take effect until you call the <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl07',this);" href="http://msdn2.microsoft.com/en-us/library/ms633545.aspx"><u><font color="#0000ff">SetWindowPos</font></u></a> function.</p>
<p>If you use <strong>SetWindowLongPtr</strong> with the GWLP_WNDPROC index to replace the window procedure, the window procedure must conform to the guidelines specified in the description of the <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl08',this);" href="http://msdn2.microsoft.com/en-us/library/ms633573.aspx"><u><font color="#0000ff">WindowProc</font></u></a> callback function. </p>
<p>If you use <strong>SetWindowLongPtr</strong> with the DWLP_MSGRESULT index to set the return value for a message processed by a dialog box procedure, the dialog box procedure should return TRUE directly afterward. Otherwise, if you call any function that results in your dialog box procedure receiving a window message, the nested window message could overwrite the return value you set by using DWLP_MSGRESULT. </p>
<p>Calling <strong>SetWindowLongPtr</strong> with the GWLP_WNDPROC index creates a subclass of the window class used to create the window. An application can subclass a system class, but should not subclass a window class created by another process. The <strong>SetWindowLongPtr</strong> function creates the window subclass by changing the window procedure associated with a particular window class, causing the system to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl09',this);" href="http://msdn2.microsoft.com/en-us/library/ms633571.aspx"><u><font color="#0000ff">CallWindowProc</font></u></a>. This allows the application to create a chain of window procedures. </p>
<p>Reserve extra window memory by specifying a nonzero value in the <strong>cbWndExtra</strong> member of the <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl10',this);" href="http://msdn2.microsoft.com/en-us/library/ms633577.aspx"><u><font color="#0000ff">WNDCLASSEX</font></u></a> structure used with the <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl11',this);" href="http://msdn2.microsoft.com/en-us/library/ms633587.aspx"><u><font color="#0000ff">RegisterClassEx</font></u></a> function. </p>
<p>Do not call <strong>SetWindowLongPtr</strong> with the GWLP_HWNDPARENT index to change the parent of a child window. Instead, use the <a onclick="javascript:Track('ctl00_LibFrame_ctl00|ctl00_LibFrame_ctl12',this);" href="http://msdn2.microsoft.com/en-us/library/ms633541.aspx"><u><font color="#0000ff">SetParent</font></u></a> function. </p>
<p>If the window has a class style of CS_CLASSDC or CS_PARENTDC, do not set the extended window styles WS_EX_COMPOSITED or WS_EX_LAYERED.</p>
<p><strong>Windows XP/Vista:</strong> Calling <strong>SetWindowLongPtr</strong> to set the style on a progressbar will reset its position.</p>
</blockquote>
<p class="clsRef">Function&nbsp;Information</p>
</div>
<br><br>先到这里,以后会写更多Win32的基础知识,当我学到的时候..<br><br>btw,有本叫the old new thing 似乎很强,不知道什么时候能有一本... <img src ="http://www.cppblog.com/gohan/aggbug/25361.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/gohan/" target="_blank">Gohan</a> 2007-06-03 00:26 <a href="http://www.cppblog.com/gohan/archive/2007/06/03/25361.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>