﻿<?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++博客-Impossible is nothing-文章分类-Windows/MFC</title><link>http://www.cppblog.com/apollo/category/1231.html</link><description>　　爱过知情重醉过知酒浓
　　花开花谢终是空
　　缘份不停留像春风来又走
　　女人如花花似梦</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 13:37:38 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 13:37:38 GMT</pubDate><ttl>60</ttl><item><title>MFC代码收集</title><link>http://www.cppblog.com/apollo/articles/9503.html</link><dc:creator>笑笑生</dc:creator><author>笑笑生</author><pubDate>Thu, 06 Jul 2006 11:36:00 GMT</pubDate><guid>http://www.cppblog.com/apollo/articles/9503.html</guid><wfw:comment>http://www.cppblog.com/apollo/comments/9503.html</wfw:comment><comments>http://www.cppblog.com/apollo/articles/9503.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/apollo/comments/commentRss/9503.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/apollo/services/trackbacks/9503.html</trackback:ping><description><![CDATA[
		<div class="postText">
				<p>MFC代码收集<br />2006-03-30 14:24<br />让列表CListCtrl第一列居中显示<br />LVCOLUMN   lvc;<br />lvc.mask   =   LVCF_FMT;<br />m_list2.GetColumn(0, &amp;lvc);<br />lvc.fmt   &amp;=   ~LVCFMT_JUSTIFYMASK;<br />lvc.fmt   |=   LVCFMT_CENTER;<br />m_listLayer.SetColumn(0, &amp;lvc); </p>
				<p>
						<br />2006-03-31 15:49<br />得到文件大小<br />struct _stat ST;<br />_stat(strFileName, &amp;ST);<br />int nFileSize = ST.st_size;</p>
				<p>
						<br />//列表整行选择和GridLine风格<br />m_list.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP/*|LVS_EX_CHECKBOXES*/);<br />当鼠标提留在某项上指定时间时把该项设为选中状态。需要列表有LVS_EX_TRACKSELECT风格<br />m_ListCtrl.SetExtendedStyle(LVS_EX_TRACKSELECT|LVS_EX_FLATSB|LVS_EX_UNDERLINEHOT);</p>
				<p>
						<br />2006-06-04 16:45</p>
				<p>#include &lt;io.h&gt;<br />判断一个文件是否存在<br />if( _access( lpszFileName, 00 ) == -1 )<br />/*<br />00 Existence only 存在<br />02  Write permission 可写<br />04 Read permission 可读<br />06 Read and write permission 可读写<br />*/</p>
				<p>选择目录<br /> BROWSEINFO bi;<br /> char dispname[MAX_PATH],path[MAX_PATH];<br /> ITEMIDLIST *pidl;</p>
				<p> bi.hwndOwner = NULL; <br /> bi.pidlRoot=0;<br /> bi.pszDisplayName=dispname;<br /> bi.lpszTitle="请选择备份目录：";<br /> bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_EDITBOX|BIF_DONTGOBELOWDOMAIN ;<br /> bi.lpfn=0;<br /> bi.lParam=0;<br /> bi.iImage=0;<br /> if(pidl=SHBrowseForFolder(&amp;bi))<br /> {<br />  SHGetPathFromIDList(pidl,path);<br />  m_strBackPath = CString(path);</p>
				<p> }</p>
				<p>
						<br />2006-07-06 17:41<br />//获取CTabCtrl的标签文字<br />TCHAR szBuf[256];<br />TCITEM item;<br />item.mask= TCIF_TEXT;<br />item.pszText= szBuf;<br />item.cchTextMax= sizeof(szBuf)/sizeof(TCHAR);</p>
				<p>m_tbCtr.GetItem(m_tbCtr.GetCurSel(), &amp;item);<br />SetDlgItemText(IDC_EDIT2, szBuf);</p>
				<p>给系统菜单添加关于选项<br /> CMenu* pSysMenu = GetSystemMenu(FALSE);<br /> if (pSysMenu != NULL)<br /> {<br />  CString strAboutMenu;<br />  strAboutMenu.LoadString(IDS_ABOUTBOX);<br />  if (!strAboutMenu.IsEmpty())<br />  {<br />   pSysMenu-&gt;AppendMenu(MF_SEPARATOR);<br />   pSysMenu-&gt;AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);<br />  }<br /> } </p>
				<br />
				<br />
				<p id="TBPingURL">Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=885908</p>
		</div>
		<div class="postFoot">
				<script src="http://localhost:82/PromoteIcon.aspx?id=885908">
				</script>
[<a href="javascript:StorePage()">点击此处收藏本文</a>]   wuhran发表于 2006年07月06日 18:09:00 </div>
		<link href="http://blog.csdn.net/wuhuiran/Services/Pingback.aspx" rel="pingback" />
		<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://blog.csdn.net/wuhuiran/archive/2006/07/06/885908.aspx"
dc:identifier="http://blog.csdn.net/wuhuiran/archive/2006/07/06/885908.aspx"
dc:title="MFC代码收集"
trackback:ping="http://tb.blog.csdn.net/TrackBack.aspx?PostId=885908" />
</rdf:RDF>
-->
		<script><![CDATA[unction hide(){showComment();}]]&gt;</script>
		<br />
		<script type="text/javascript"><![CDATA[ocument.write("<img src=http://counter.csdn.net/pv.aspx?id=24 border=0 width=0 height=0>");]]&gt;</script>
		<img height="0" src="http://counter.csdn.net/pv.aspx?id=24" width="0" border="0" />
		<a name="885917"> </a>
		<div class="post">
				<div class="postTitle">wuhran 发表于2006-07-06 18:12:00  IP: 222.141.18.*</div>
				<div class="postText">如何让工具条具有按下状态 <br />CToolBar m_wndFuncBar; <br />int m_curTool; <br /><br />m_wndFuncBar.GetToolBarCtrl().CheckButton(m_curTool,FALSE); <br />CToolBarCtrl::CheckButton(int nID, BOOL bCheck = TRUE); <br /></div>
		</div>
		<br />
		<a name="885919"> </a>
		<div class="post">
				<div class="postTitle">wuhran 发表于2006-07-06 18:12:00  IP: 222.141.18.*</div>
				<div class="postText">把CPropertySheet的标签放到下方时出现的错误 <br />CTabCtrl* pTabCtrl = m_sheet.GetTabControl(); <br />if(pTabCtrl) <br />{ <br />pTabCtrl-&gt;ModifyStyle(0, TCS_BOTTOM); <br />} <br />这个是我的实现代码： <br /><br />CRect rect; <br />DWORD dwStyle = WS_CHILD | WS_VISIBLE; <br />DWORD dwStyleEx = WS_EX_CONTROLPARENT; <br /><br />m_sheet.AddPage(&amp;m_dlgFileBack); <br />m_sheet.AddPage(&amp;m_dlgFileDel); <br />m_sheet.Create(this, dwStyle, dwStyleEx); <br /><br />CTabCtrl* pTabCtrl = m_sheet.GetTabControl(); <br />if(pTabCtrl) <br />{ <br />pTabCtrl-&gt;ModifyStyle(0, TCS_BOTTOM); <br />} <br /><br />这样运行的时候就会出现下面的样子，就是标签只能看到小小的一条，其他的都看不到。 <br /><br />这个问题花了我很长时间，最后在准备发帖子询问的时候才突然想到原因 <br />希望对遇到同样问题的朋友有点帮助 <br /><br />原来，创建CPropertySheet的时候，自动创建了一个CTabCtrl,我们可以用CPropertyShhet::GetTabControl()得到该TabCtrl的指针 <br />如果要放到下面就要改变这个TabCtrl的大小，否则就会遮住属性页标签 <br /><br />完整的代码如下： <br />CRect rect; <br />DWORD dwStyle = WS_CHILD | WS_VISIBLE; <br />DWORD dwStyleEx = WS_EX_CONTROLPARENT; <br /><br />m_sheet.AddPage(&amp;m_dlgFileBack); <br />m_sheet.AddPage(&amp;m_dlgFileDel); <br />m_sheet.Create(this, dwStyle, dwStyleEx); <br /><br />CTabCtrl* pTabCtrl = m_sheet.GetTabControl(); <br />if(pTabCtrl) <br />{ <br />pTabCtrl-&gt;ModifyStyle(0, TCS_BOTTOM); <br />} <br /><br />// 调整属性表到静态框大小 <br />CWnd* pWnd = (CWnd*)GetDlgItem(IDC_STATIC_SHEET); <br />if(pWnd) <br />{ <br />CRect rect; <br />pWnd-&gt;GetWindowRect(rect); <br />ScreenToClient(rect); <br />m_sheet.MoveWindow(rect); <br /><br />// <br />// 调整TabCtrl大小 <br />// <br />// rect.top += 5; <br />// rect.left += 5; <br />rect.bottom -= 5; <br />rect.right -= 10; <br />if(pTabCtrl) <br />{ <br />pTabCtrl-&gt;MoveWindow(rect); <br />} <br /><br />// <br />// 调整当前活动页大小 <br />// <br />rect.top += 5; <br />rect.left += 5; <br />rect.bottom -= 20; <br />rect.right -= 20; <br /><br />CPropertyPage* page = m_sheet.GetActivePage(); <br />if(page) <br />{ <br />page-&gt;MoveWindow(rect); <br />} <br /><br />pWnd-&gt;ShowWindow(SW_HIDE); <br />} <br /></div>
		</div>
<img src ="http://www.cppblog.com/apollo/aggbug/9503.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/apollo/" target="_blank">笑笑生</a> 2006-07-06 19:36 <a href="http://www.cppblog.com/apollo/articles/9503.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Win32时间类型</title><link>http://www.cppblog.com/apollo/articles/Win32时间类型.html</link><dc:creator>笑笑生</dc:creator><author>笑笑生</author><pubDate>Wed, 29 Mar 2006 14:16:00 GMT</pubDate><guid>http://www.cppblog.com/apollo/articles/Win32时间类型.html</guid><wfw:comment>http://www.cppblog.com/apollo/comments/4806.html</wfw:comment><comments>http://www.cppblog.com/apollo/articles/Win32时间类型.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/apollo/comments/commentRss/4806.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/apollo/services/trackbacks/4806.html</trackback:ping><description><![CDATA[在Win32时间类型有这样几种类型<font face="Courier New">FILETIME/</font><code>SYSTEMTIME/WINDOWSTIME<br /><br /><font style="background-color: rgb(255, 255, 255);" color="#0000ff"><font face="Verdana" size="4">先提个问题，如何计算当前时间100天以后的时间，在win32中。</font><br /></font><br />1.SYSTEMTIME <br /><br /></code>SYSTEMTIME的定义是这样<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">typedef </span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);">  _SYSTEMTIME<br />    {<br />    WORD wYear;<br />    WORD wMonth;<br />    WORD wDayOfWeek;<br />    WORD wDay;<br />    WORD wHour;<br />    WORD wMinute;<br />    WORD wSecond;<br />    WORD wMilliseconds;<br />    } SYSTEMTIME;</span></div><br />
很大，总共16个字节。你可以调用GetSystemTime来取得当前的时间<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">SYSTEMTIME st;<br />::GetSystemTime(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st);</span></div>
但是如果你调用 st.wDay += 100;是达不到效果的，将会得到一个无效的时间格式<br /><br />
2. FILETIME<br />
FILETIME的定义是这样的<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">typedef </span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);">  _FILETIME<br />    {<br />    DWORD dwLowDateTime;<br />    DWORD dwHighDateTime;<br />    } FILETIME;</span></div>
FILETIME这个名字很奇怪，其实他跟FILE并没有直接关系，只是很多File的API中，都以这个为时间的类型，比如你可以调用GetFileTime来取得File的创建/修改/访问时间。<br />
FILETIME是一个__int64。可以这样转化成__int64<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">__int64 d </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">(__int64 </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st;<br /><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">or</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />__int64 d2;<br />memcpy(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">d2,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st,</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(d2));</span></div><br />
转化为__int64是一个以100纳秒为单位的值<br /><table style="width: 528px; height: 116px;" border="0" width="528"><tbody><tr><td width="108"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1ms (毫秒)</font></td><td width="269"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1毫秒=0.001秒=10-3秒(millisecond)</font></td></tr><tr><td width="108"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1μs (微秒) </font></td><td width="269"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1微秒=0.000001=10-6秒(microsecond)</font></td></tr><tr><td width="108"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1ns (纳秒)</font></td><td width="269"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1纳秒=0.000000001秒=10-9秒（<font color="#000000" size="3">nanosecond</font>)</font></td></tr><tr><td width="108"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1ps (皮秒)</font></td><td width="269"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1皮秒=0.000000000001秒=10-12秒</font></td></tr><tr><td width="108"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1fs (飞秒)</font></td><td width="269"><font color="#330099" face="黑体, 华文中宋, 隶书, 新宋体" size="2">1飞秒=0.00000000000001秒=10-15秒</font></td></tr></tbody></table><br />
SYSTEMTIME可以通过SystemTimeToFileTime来转化为FILETIME<br /><br />
3.Window Time<br />
::GetTickCount()可以返回当前的以微秒为单位的时间，用在精度要求不高的场合，返回的只是一个DWORD，四字节。高一点的使用timeGetTime<br /><br /><font color="#0000ff" face="Courier New">如何计算当前时间100天以后的时间，在win32中。<br />应该这样写<br /></font><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> __int64 nano100SecInDay</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">(__int64)</span><span style="color: rgb(0, 0, 0);">10000000</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">60</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">60</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">24</span><span style="color: rgb(0, 0, 0);">;<br /><br />SYSTEMTIME st;<br />::GetSystemTime(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st);<br />FILETIME f;<br />::SystemTimeToFileTime(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">f);<br />ULARGE_INTEGER now;<br />memcpy(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">now,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">f,</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(now));<br />now </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">nano100SecInDay;<br />memcpy(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">f,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">now,</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(f));<br />FileTimeToSystemTime(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">f,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st);<br /></span></div><br /><br />
最后：附上我写的一个小工具，删除指定文件夹下面的过期文件的一个工具，并可以备份，支持子文件夹嵌套。<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">windows.h</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">cstdio</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> std;<br /><br /></span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> __int64 nano100SecInDay</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">(__int64)</span><span style="color: rgb(0, 0, 0);">10000000</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">60</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">60</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">24</span><span style="color: rgb(0, 0, 0);">;<br />ULARGE_INTEGER now;<br /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> days </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">14</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);"> backup </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> dst_dir;<br /></span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> backup_dir;<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> make_sure_dir_exist(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> file)<br />{<br />    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> tag </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">;<br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        tag </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> file.find_first_of(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\\</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,tag</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tag</span><span style="color: rgb(0, 0, 0);">!=-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />        {<br />            </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> tmp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> file.substr(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,tag);<br />            ::CreateDirectory(tmp.c_str(),NULL);<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />        {<br />            </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />        }<br />    }<br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> xdel(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">dir)<br />{<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> tempFileFind[</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">];<br />    sprintf(tempFileFind,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">%s\\*.*</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,dir);<br />    <br />    WIN32_FIND_DATA ffd;<br />    HANDLE hFind;<br />    hFind </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ::FindFirstFile(tempFileFind,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ffd);<br />    <br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(hFind </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> INVALID_HANDLE_VALUE)<br />    {<br />        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">can't find %s\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,dir);<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">printf("find %s\n",ffd.cFileName);</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        FILETIME </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ft </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ffd.ftLastWriteTime;<br />        ULARGE_INTEGER ui;<br />        memcpy(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ui,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ft,</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(ui));<br />        __int64 t </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> now.QuadPart</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ui.QuadPart;<br />        <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(ffd.dwFileAttributes</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">FILE_ATTRIBUTE_DIRECTORY)<br />        {<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(strcmp(ffd.cFileName, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> strcmp(ffd.cFileName, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">..</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">))<br />            {<br />                </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> temp[</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">];<br />                sprintf(temp,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">%s\\%s</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,dir,ffd.cFileName);<br />                xdel(temp);<br />                <br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(t</span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);">nano100SecInDay</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">days)<br />                {<br />                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(::RemoveDirectory(temp))<br />                    {<br />                        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">del dir %s ok\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,temp);<br />                    }<br />                    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />                    {<br />                        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">del dir %s failed\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,temp);<br />                    }<br />                }<br />            }<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />        {<br />            </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> temp[</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">];<br />            sprintf(temp,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">%s\\%s</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,dir,ffd.cFileName);<br />            <br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(t</span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);">nano100SecInDay</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">days)<br />            {<br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(backup)<br />                {<br />                    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> backup_file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> temp;<br />                    backup_file.replace(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,dst_dir.length(),backup_dir.c_str());<br />                    make_sure_dir_exist(backup_file);<br />                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(::MoveFile(temp,backup_file.c_str()))<br />                    {<br />                        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">backup file %s ok\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,temp);<br />                    }<br />                    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />                    {<br />                        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">backup file %s failed\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,temp);<br />                    }<br />                }<br />                </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />                {<br />                    SetFileAttributes(temp,FILE_ATTRIBUTE_NORMAL);<br />                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(::DeleteFile(temp))<br />                    {<br />                        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">del file %s ok\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,temp);<br />                    }<br />                    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />                    {<br />                        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">del file %s failed\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,temp);<br />                    }<br />                }<br />            }<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">FindNextFile(hFind, </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ffd)) <br />        {<br />            </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />        }<br />    }<br />    FindClose(hFind);<br />}<br /><br /></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> main(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> argc,</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">**</span><span style="color: rgb(0, 0, 0);"> argv)<br />{<br />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(argc</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">)<br />    {<br />        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">usage: xdel directory /d= /m=\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">[optional] /d: config the expired days,default is 14 days\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">[optional] /m: config the backup directory\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); <br />        printf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">for example: xdel d:\\test /d=10 /m=d:\\backup</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />    }<br />    <br />    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">argc;</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">i)<br />    {<br />        </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> tmp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> argv[i];<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tmp.find(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/d=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">!=-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />        {<br />            </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> d </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> atoi(tmp.substr(</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">).c_str());<br />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(d</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            {<br />                days </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">d;<br />            }<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tmp.find(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/m=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">!=-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br />        {<br />            backup </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />            backup_dir </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> tmp.substr(</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">);<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />        {<br />            dst_dir </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> tmp;<br />        }<br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">Get system time</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    SYSTEMTIME st;<br />    ::GetSystemTime(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st);<br />    FILETIME f;<br />    ::SystemTimeToFileTime(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">st,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">f);<br />    memcpy(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">now,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">f,</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(now));<br />    <br />    xdel(argv[</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">]);<br />    <br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />}</span></div><img src ="http://www.cppblog.com/apollo/aggbug/4806.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/apollo/" target="_blank">笑笑生</a> 2006-03-29 22:16 <a href="http://www.cppblog.com/apollo/articles/Win32时间类型.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC中一些使用的方法</title><link>http://www.cppblog.com/apollo/articles/MFCCODE.html</link><dc:creator>笑笑生</dc:creator><author>笑笑生</author><pubDate>Sun, 26 Mar 2006 07:10:00 GMT</pubDate><guid>http://www.cppblog.com/apollo/articles/MFCCODE.html</guid><wfw:comment>http://www.cppblog.com/apollo/comments/4621.html</wfw:comment><comments>http://www.cppblog.com/apollo/articles/MFCCODE.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/apollo/comments/commentRss/4621.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/apollo/services/trackbacks/4621.html</trackback:ping><description><![CDATA[1．  在CSatic控件上增加图标及位图
<p>CStatic *pStat = NULL;</p><p>pStat = (CStatic*)GetDlgItem(控件ID);</p><p>       pStat-&gt;ModifyStyle(SWP_NOZORDER, SS_ICON);</p><p>   可用两种方法增加图标</p><p>(1)    pStat-&gt;SetIcon(AfxGetApp()-&gt;LoadIcon(图标ID));</p><p>(2)    pStat-&gt;SetIcon(LoadIcon(::AfxGetInstanceHandle(),”图标名称”)); //图标名字改为“IDI_ICON”的形式，因为这里要求的是字符串形式的名称。</p><p>   增加Bmp图片的形式同上，将ModifyStyle中的SS_ICON改为SS_BITMAP。用相应的位图增加函数即可。</p><p>2．  CClientDC，CWindowDC</p><p>这两个类都从CDC类派生，CClientDC类用于获取客户区的DC（不包括标题栏，菜单栏，工具栏），创建了CClientDC类对象后不需用ReleaseDC来释放。如：</p><p>CCleintDC dc(this);获取本窗口的dc，CClientDC dc(GetParent())可获取父窗口DC，此时就可在非客户区进行dc操作。</p><p>CWindowDC 获取整个窗口的dc，可对整个窗口进行操作，CWindowDC(GetParent())　注意在这获得的父窗口对于对话框情况下将是windows窗口，最后无需ReleaseDC释放</p><p>GetDesktopWindow()获取桌面窗口句柄。</p><p>::CreateIC("DISPLAY",NULL,NULL,NULL);获取桌面的HDC</p><p>3．  获取随机数rand()</p><p>要获取一定范围内的随机数可用：</p><p>Srand((unsigned) time(NULL));   //意思是每次产生的随机数都不相同.</p><p>(int)(rand())/(float) RAND_MAX * 10); //返回1－10之间的随机数</p><p><br /> 4．  获取路径：</p><p>char path[MAX_PATH] = "\0";</p><p> GetModuleFileName(NULL, path, MAX_PATH);  //应用程序路径</p><p> GetSystemDirectory();  //获取Windows系统目录路径</p><p> GetWindowDirectory()  //获取Windows目录路径</p><p><br /> 5．  动态加载ODBC数据源</p><p>//mdbName为数据库名称, DSN为数据源名称</p><p> void  SetODBCSource(char * mdbName ,char * DSNName)  </p><p>{</p><p>       char path[256]="";</p><p>       char pathMDB[256]="";</p><p>       GetAppPath(path);</p><p>       strcpy(pathMDB,path);</p><p>       strcat(pathMDB, "\\");</p><p>       strcat(pathMDB, mdbName);</p><p>       char MdbConfig[256]= "DSN=" ;// pwd</p><p>       strcat(MdbConfig , DSNName);</p><p>       char * pMconfig = MdbConfig + strlen(MdbConfig) + 1 ;</p><p>       strcpy(pMconfig,"DBQ=");</p><p>       pMconfig += 4;</p><p>       strcat(pMconfig,pathMDB);</p><p>       pMconfig += strlen(pathMDB) + 1 ;</p><p>       strcpy(pMconfig,"DEFAULTDIR=");</p><p>       strcat(pMconfig,path);</p><p>       strcat(pMconfig,"\0");</p><p>if(!SQLConfigDataSource(NULL,ODBC_ADD_SYS_DSN,"Microsoft  Access </p><p>Driver (*.mdb)\0",MdbConfig))  //注意Driver后的空格</p><p>       {</p><p>              TRACE("加载数据库失败,请检查数据库是否存在\n");</p><p>             
return;           
</p><p>       }</p><p><br />6．  线程退出</p><p>线程退出请使用return 或 ExitThread()来正常退出线程，尽是避免使用TerminateThread来终止线程，因为终止后线程资源将不会被释放。</p><p>一般情况下在CreateThread创建了线程后即使用CloseHandle()来关闭线程句柄，以防止TerminateThread得到句柄后，进行线程的强制终止。</p><p><br /> 7．  自定义宏检查错误BOOL错误。</p><p>#define ASSERT_ERROR(Code)\</p><p>{\</p><p>   If (Code)\</p><p>       AfxMessageBox(“提示1 “);\</p><p>   Else \</p><p>       AfxMessageBox(“错误1”);\</p><p>}</p><p>定义以后可在需要使用的地方使用，如：BOOL bStat = TRUE;</p><p>ASSERT_ERROR(bStat); //此时将执行“提示1”，bStat = FALSE时执行“错误1”</p><p><br /> 8．  将程序加入注册表启动项：</p><p>LPCTSTR lpcAppPath = “程序路径”;</p><p>CString str = “SOFTWARE\\Microsoft\\Windows\\CurrentverSion\\Run”;</p><p>HKEY hResult;</p><p>RegOpenKey(HKEY_LOCAL_MACHINE, (LPCSTR)str.GetBuffer(0), &amp;hResult);</p><p>RegSetValueEx(hResult, “程序名称”, 0, REG_SZ, (const unsigned char*)lpcAppPath,</p><p>       Sizeof(char) * strlen(lpcAppPath));</p><p>RegCloseKey(hResult);</p><p><br /> 9．  程序调试</p><p>在调试环境下的Vlaue窗口中输入” @err,hr”　可返回当前发生的错误原因</p><p><br /> 10．        获取工具条指针，工具条有一特殊标识(AFX_IDW_TOOLBAR)</p><p>CToolBar *pTool = (CToolBar*)AfxGetMainWnd()-&gt;GetDescendantWindow(特殊标识)</p><p>;</p><p>获取状态条指针。</p><p>(CStatusBar*)AfxGetMainWnd()-&gt;GetDescendantWindow(AFX_IDW_STATUS_BAR);</p><p><br /> 获取主窗口指针：</p><p>CMainFrame *pFrame = (CMainFrame*)(AfxGetApp()-&gt;m_pMainWnd);</p><p><br /><br />获取视类指针：</p><p>CMyView *pView= CMyView*)((CMainFrame*)AfxGetApp()-&gt;m_pMainWnd)-&gt;GetActiveView();</p><p> </p><p>或</p><p> </p><p>CMyView *pView=(CMyView*)GetActiveView();</p><p><br />11．显示或隐藏任务栏:</p><p> ::ShowWindow(::FindWindow(“Shell_TrayWnd”, NULL, SW_SHOW)，隐藏用SW_HIDE</p><p> 12．使用基于对话框的程序在任务栏隐藏。</p><p> This-&gt;ModifyStyleEx(WS_EX_APPWINDOW, 0);</p><p> 13．只允许程序运行一个实例：</p><p> HANDLE h_Muex = CreateMutex(NULL, TRUE, m_pszAppName);</p><p> If (GetLastError() == ERROR_ALREADY_EXISTS)</p>

    Return False;<img src ="http://www.cppblog.com/apollo/aggbug/4621.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/apollo/" target="_blank">笑笑生</a> 2006-03-26 15:10 <a href="http://www.cppblog.com/apollo/articles/MFCCODE.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>