﻿<?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>IT博客-老马侠客</title><link>http://www.cnitblog.com/mashang/</link><description>   江湖心中谱，人生脚下路 。




   老马知识途，三思不停步 ……</description><language>zh-cn</language><lastBuildDate>Wed, 29 Apr 2026 05:58:32 GMT</lastBuildDate><pubDate>Wed, 29 Apr 2026 05:58:32 GMT</pubDate><ttl>60</ttl><item><title>转：windows字符串</title><link>http://www.cnitblog.com/mashang/archive/2008/11/27/51953.html</link><dc:creator>马上</dc:creator><author>马上</author><pubDate>Thu, 27 Nov 2008 12:30:00 GMT</pubDate><guid>http://www.cnitblog.com/mashang/archive/2008/11/27/51953.html</guid><wfw:comment>http://www.cnitblog.com/mashang/comments/51953.html</wfw:comment><comments>http://www.cnitblog.com/mashang/archive/2008/11/27/51953.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/mashang/comments/commentRss/51953.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/mashang/services/trackbacks/51953.html</trackback:ping><description><![CDATA[<p>首先，char是ascii编码，wchar_t是unicode，这是大家都知道的，但是这也是纠结所在。所以个人经验，在做windows程序
时，最好是忘记这两种变量的存在，而记住windows里只有一种字符变量，那就是TCHAR。（虽然TCHAR只不过是对char或tchar的宏定义
而已）</p>
<p>也就是说，程序里既不要出现char也不要出现wchar，只能出现TCHAR，这样就把纠结统一起来了。这也是程序通用性的要求。</p>
<p>接下来，还必须注意以下几点：</p>
<p>1、既然程序里不能出现char，那表示字符串时，就不能再习惯性的用char*了。应该改为TCHAR*，或者是PTSTR。后一种是
windows的变量，类似的有：PSTR、PTSTR、LPTSTR、LPSTR、PCTSTR等等等等。这也是让人一开始接触会头大的地方。其实并非
如此恐怖，我以PCTSTR为例做个解释：P代表指针(和LP是一个东西，LP的本意是Long
Pointer，16位windows时代的遗留物。)，C代表const，T代表TCHAR，STR代表字符串。所以PCTSTR其实就是const
TCHAR* 的意思。而PSTR也就是char* 的意思。所以我们在表示字符串时也不能使用PSTR等不带T的变量类型名。</p>
<p>2、表示字符串常量时，不能简单的用双引号括起来，因为那代表ascii字符串。同样也不能在前面加L，因为那代表unicode。我们的程序要做
到的是通用性，即不是ascii也不是unicode。所以我们在字符串前应该加的是TEXT，
比如MessageBox(NULL,TEXT("Fypher"),TEXT("FF"),MB_OK)。TEXT还可用于字符。比如TCHAR
m=TEXT('A');</p>
<p>3、TCHAR FF[50]。FF能装多少字符？哈！不要习惯性的sizeof(FF)了，应该_countof(FF)或者sizeof(FF)/sizeof(TCHAR)。因为我们不确定TCHAR到底是char 还是 wchar_t。</p>
<p>4、该和一堆老朋友说再见了&#8230;&#8230;我们不能再使用以前的字符串处理函数或者字符处理函数了。比如strlen、strcat、strcmp等等等
等&#8230;&#8230;因为这些是ascii专用的，通通改成使用T家族的吧。前缀都换成_tcs。比如_tcslen、_tcscat、_tcscmp等等&#8230;&#8230;顺便补充
一下wcs前缀是wchar_t使用的。恩，还有大家用得超爽的sprintf，今后就改成_stprintf了吧~呵呵。补充：swprintf是
wchar_t它家的。对了，windows认为_tcscpy、_tcscat等不安全，所以使用这些函数编译器会报警。可以改用windows推出的
_tcscpy_s、_tcscat_s等&#8220;安全&#8221;函数，其实就是多了个参数用来指明缓冲区大小（记得用_countof哦~！^_^）。windows
还推出了形如StringCchCat的一套字符串处理函数，我没怎么用过。windows也有一个字符串比较函数CompareString。功能比
_tcscmp强大多了。比如可以设置忽略大小写等。</p>
<p>5、IsTextUnicode函数可以用过一系列统计学的方法判断某个字符串是不是unicode字符串。
MultiByteToWideChar和WideCharToMultiByte函数可实现Ascii和Unicode字符串的相互转化。这些的使用场
合都不大。因为我们的程序应该做到&#8220;没有&#8221;ascii和unicode。</p>
<p>6、恩，虽然绝大多数情况下应该使用TCHAR，但是记住GetProcAdress这个特殊的函数吧，它的参数只能是char*。因为在导出函数表里函数名是用ascii码写的&#8230;&#8230;</p>
<p>7、最后一点，记得要#include &lt;tchar.h&gt;哦！呵呵~
由于windows内核采用的是UNICODE，UNICODE版的程序必然比ASCII版的程序效率高（比如不用在调用函数时在堆里分配空间把参数转成
UNICODE，然后再调用UNICODE版的函数），所以我们最好是在程序的开头加上#define UNICODE和#define
_UNICODE，把程序转换成UNICODE版的。如果程序的字符串处理完全按照上面的通用性要求做了是不会出错的。</p>
<p><br></p>
<p><br></p><img src ="http://www.cnitblog.com/mashang/aggbug/51953.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/mashang/" target="_blank">马上</a> 2008-11-27 20:30 <a href="http://www.cnitblog.com/mashang/archive/2008/11/27/51953.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转：深入浅出ShellExecute </title><link>http://www.cnitblog.com/mashang/archive/2008/11/27/51951.html</link><dc:creator>马上</dc:creator><author>马上</author><pubDate>Thu, 27 Nov 2008 12:23:00 GMT</pubDate><guid>http://www.cnitblog.com/mashang/archive/2008/11/27/51951.html</guid><wfw:comment>http://www.cnitblog.com/mashang/comments/51951.html</wfw:comment><comments>http://www.cnitblog.com/mashang/archive/2008/11/27/51951.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/mashang/comments/commentRss/51951.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/mashang/services/trackbacks/51951.html</trackback:ping><description><![CDATA[Q: 如何打开一个应用程序？
<pre>ShellExecute(this-&gt;m_hWnd,"open","calc.exe","","", SW_SHOW );</pre>
或
<pre>ShellExecute(this-&gt;m_hWnd,"open","notepad.exe",<br>    "c:\\MyLog.log","",SW_SHOW );</pre>
正如您所看到的，我并没有传递程序的完整路径。<br>
<img  src="http://www.vckbase.com/document/image/paragraph.gif" width="14" height="16">Q: 如何打开一个同系统程序相关连的文档？
<pre>ShellExecute(this-&gt;m_hWnd,"open",<br>    "c:\\abc.txt","","",SW_SHOW );</pre>
<img  src="http://www.vckbase.com/document/image/paragraph.gif" width="14" height="16">Q: 如何打开一个网页？
<pre>ShellExecute(this-&gt;m_hWnd,"open",<br>    "http://www.google.com","","", SW_SHOW );</pre>
<img  src="http://www.vckbase.com/document/image/paragraph.gif" width="14" height="16">Q: 如何激活相关程序，发送EMAIL？
<pre>ShellExecute(this-&gt;m_hWnd,"open",<br>    "mailto:nishinapp@yahoo.com","","", SW_SHOW );</pre>
<img  src="http://www.vckbase.com/document/image/paragraph.gif" width="14" height="16">Q: 如何用系统打印机打印文档？
<pre>ShellExecute(this-&gt;m_hWnd,"print",<br>    "c:\\abc.txt","","", SW_HIDE);</pre>
<img  src="http://www.vckbase.com/document/image/paragraph.gif" width="14" height="16">Q: 如何用系统查找功能来查找指定文件？
<pre>ShellExecute(m_hWnd,"find","d:\\nish",<br>    NULL,NULL,SW_SHOW);</pre>
<img  src="http://www.vckbase.com/document/image/paragraph.gif" width="14" height="16">Q: 如何启动一个程序，直到它运行结束？
<pre>SHELLEXECUTEINFO ShExecInfo = {0};<br>ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);<br>ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;<br>ShExecInfo.hwnd = NULL;<br>ShExecInfo.lpVerb = NULL;<br>ShExecInfo.lpFile = "c:\\MyProgram.exe";		<br>ShExecInfo.lpParameters = "";	<br>ShExecInfo.lpDirectory = NULL;<br>ShExecInfo.nShow = SW_SHOW;<br>ShExecInfo.hInstApp = NULL;	<br>ShellExecuteEx(&amp;ShExecInfo);<br>WaitForSingleObject(ShExecInfo.hProcess,INFINITE);</pre>
或：
<pre>PROCESS_INFORMATION ProcessInfo; <br>STARTUPINFO StartupInfo; //This is an [in] parameter<br>ZeroMemory(&amp;StartupInfo, sizeof(StartupInfo));<br>StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field<br>if(CreateProcess("c:\\winnt\\notepad.exe", NULL, <br>    NULL,NULL,FALSE,0,NULL,<br>    NULL,&amp;StartupInfo,&amp;ProcessInfo))<br>{ <br>    WaitForSingleObject(ProcessInfo.hProcess,INFINITE);<br>    CloseHandle(ProcessInfo.hThread);<br>    CloseHandle(ProcessInfo.hProcess);<br>}  <br>else<br>{<br>    MessageBox("The process could not be started...");<br>}<br></pre>
<img  src="http://www.vckbase.com/document/image/paragraph.gif" width="14" height="16">Q: 如何显示文件或文件夹的属性？
<pre>SHELLEXECUTEINFO ShExecInfo ={0};<br>ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);<br>ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;<br>ShExecInfo.hwnd = NULL;<br>ShExecInfo.lpVerb = "properties";<br>ShExecInfo.lpFile = "c:\\"; //can be a file as well<br>ShExecInfo.lpParameters = ""; <br>ShExecInfo.lpDirectory = NULL;<br>ShExecInfo.nShow = SW_SHOW;<br>ShExecInfo.hInstApp = NULL; <br>ShellExecuteEx(&amp;ShExecInfo);<br><br>打开拔号网络这样<br>::ShellExecute(NULL,&nbsp;"open",&nbsp;"C:\\WINDOWS\\rundll32.exe",&nbsp;"shell32.dll,Control_RunDLL&nbsp;c:\\windows\\system\\Telephon.cpl",NULL,SW_SHOW);<br></pre><img src ="http://www.cnitblog.com/mashang/aggbug/51951.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/mashang/" target="_blank">马上</a> 2008-11-27 20:23 <a href="http://www.cnitblog.com/mashang/archive/2008/11/27/51951.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>初入江湖</title><link>http://www.cnitblog.com/mashang/archive/2007/12/15/37721.html</link><dc:creator>马上</dc:creator><author>马上</author><pubDate>Sat, 15 Dec 2007 02:05:00 GMT</pubDate><guid>http://www.cnitblog.com/mashang/archive/2007/12/15/37721.html</guid><wfw:comment>http://www.cnitblog.com/mashang/comments/37721.html</wfw:comment><comments>http://www.cnitblog.com/mashang/archive/2007/12/15/37721.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/mashang/comments/commentRss/37721.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/mashang/services/trackbacks/37721.html</trackback:ping><description><![CDATA[开张啦！！！<br>特此庆祝加勉励自己！！<br>向上向上不停步啊！<br><br><br><img src ="http://www.cnitblog.com/mashang/aggbug/37721.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/mashang/" target="_blank">马上</a> 2007-12-15 10:05 <a href="http://www.cnitblog.com/mashang/archive/2007/12/15/37721.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>