﻿<?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++博客-C++世界-随笔分类-VC常用</title><link>http://www.cppblog.com/fdsajhg/category/14932.html</link><description>管理系统--&lt;</description><language>zh-cn</language><lastBuildDate>Sat, 16 Oct 2010 13:34:07 GMT</lastBuildDate><pubDate>Sat, 16 Oct 2010 13:34:07 GMT</pubDate><ttl>60</ttl><item><title>VC 托盘</title><link>http://www.cppblog.com/fdsajhg/archive/2010/10/13/129698.html</link><dc:creator>傅先生</dc:creator><author>傅先生</author><pubDate>Tue, 12 Oct 2010 22:53:00 GMT</pubDate><guid>http://www.cppblog.com/fdsajhg/archive/2010/10/13/129698.html</guid><wfw:comment>http://www.cppblog.com/fdsajhg/comments/129698.html</wfw:comment><comments>http://www.cppblog.com/fdsajhg/archive/2010/10/13/129698.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/fdsajhg/comments/commentRss/129698.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/fdsajhg/services/trackbacks/129698.html</trackback:ping><description><![CDATA[<p>//////<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 命令栏处理---------隐藏<br>/////<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;&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>1,定义基础消息处理机制<br>2,为创建托盘注册<br>3,定义消息处理机制.<br><br><br>///////////////全局化<br>#define UM_TRAYNOTIFICATION (WM_USER+100)<br>&nbsp;NOTIFYICONDATA m_nid;<br><br>///////////////////////////////////////<br>&nbsp;//初始化m_nid&nbsp; <br></p>
<p>&nbsp;m_nid.cbSize = sizeof(NOTIFYICONDATA);&nbsp; <br>&nbsp;m_nid.hWnd = this-&gt;m_hWnd;&nbsp; <br>&nbsp;m_nid.uID = IDR_MENU1;&nbsp;&nbsp; <br>&nbsp;m_nid.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;&nbsp;&nbsp; <br>&nbsp;m_nid.hIcon = AfxGetApp()-&gt;LoadIcon(IDR_MAINFRAME);&nbsp;&nbsp; <br>&nbsp;strcpy (m_nid.szTip, "我的托盘听我的");&nbsp;&nbsp; <br>m_nid.uCallbackMessage = UM_TRAYNOTIFICATION;</p>
<p><br>增加一个<br>&nbsp;Shell_NotifyIcon(NIM_ADD, &amp;m_nid);<br>/////////////////////////////////<br><br><br>////////消息处理/////////////////////<br>void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)<br>{<br>if ((nID &amp; 0xFFF0) == SC_CLOSE)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //触发关闭按钮&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //OnClose();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //不进行关闭&nbsp;&nbsp; <br>//&nbsp; AfxMessageBox("dfddfd");<br>&nbsp;RemoveTray();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;PostQuitMessage(0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<p>&nbsp;&nbsp;&nbsp; }&nbsp; </p>
<p>CWnd::OnSysCommand(nID,lParam);<br>if (nID==SC_MINIMIZE)<br>&nbsp;{<br>&nbsp; /*<br>&nbsp;NOTIFYICONDATA nid;<br>&nbsp;nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);<br>&nbsp;nid.hWnd=this-&gt;m_hWnd;<br>&nbsp;nid.uID=IDR_MAINFRAME;<br>&nbsp;nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP ;<br>&nbsp;nid.uCallbackMessage=UM_TRAYNOTIFICATION;//自定义的在托盘区显示图标的消息<br>&nbsp;nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));<br>&nbsp;strcpy(nid.szTip,"要发消息点我!");//信息提示条<br>&nbsp;Shell_NotifyIcon(NIM_ADD,&amp;nid);//在托盘区添加图标<br>&nbsp;*/<br>Shell_NotifyIcon(NIM_ADD, &amp;m_nid);<br>&nbsp;ShowWindow(SW_HIDE);//隐藏窗口<br>&nbsp;}<br>}<br>//移除托盘图标，在程序退出时一定要记得调用，否则图标会残留在托盘上 <br>void CMainFrame::RemoveTray() {&nbsp; <br>&nbsp;Shell_NotifyIcon(NIM_DELETE, &amp;m_nid); <br>} <br><br><br><br>LRESULT CMainFrame::OnTrayNotification(WPARAM wId, LPARAM lEvent) <br>{&nbsp;&nbsp; <br>&nbsp;if(wId!=m_nid.uID || (lEvent!=WM_LBUTTONUP &amp;&amp; lEvent!=WM_RBUTTONUP))&nbsp;&nbsp;&nbsp; <br>&nbsp; return lEvent; </p>
<p>&nbsp;ShowWindow(SW_SHOW);<br>//加载菜单&nbsp;&nbsp; <br>&nbsp;CMenu menu;&nbsp;&nbsp; <br>&nbsp;if(!menu.LoadMenu(wId))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; return 0;&nbsp;&nbsp; //获取弹出菜单&nbsp;&nbsp; <br>&nbsp;CMenu *pSubMenu = menu.GetSubMenu(0);&nbsp;&nbsp; <br>&nbsp;if(!pSubMenu)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; return 0;&nbsp;&nbsp;&nbsp; </p>
<p>&nbsp;if(lEvent == WM_RBUTTONUP)&nbsp;&nbsp; <br>&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设置默认菜单项&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ::SetMenuDefaultItem(pSubMenu-&gt;m_hMenu, 0, TRUE);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //获取鼠标位置&nbsp; <br>&nbsp; CPoint mouse;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; GetCursorPos(&amp;mouse);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设置快捷菜单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ::SetForegroundWindow(m_nid.hWnd);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; ::TrackPopupMenu(pSubMenu-&gt;m_hMenu, 0, mouse.x, mouse.y, 0, m_nid.hWnd, NULL);&nbsp;&nbsp; <br>}&nbsp;&nbsp; <br>&nbsp;else&nbsp;&nbsp; <br>&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;::SendMessage(m_nid.hWnd, WM_COMMAND, pSubMenu-&gt;GetMenuItemID(0), 0);&nbsp;&nbsp; <br>} <br>return 1;&nbsp; <br>}<br><br></p>
<p><br></p>
<img src ="http://www.cppblog.com/fdsajhg/aggbug/129698.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/fdsajhg/" target="_blank">傅先生</a> 2010-10-13 06:53 <a href="http://www.cppblog.com/fdsajhg/archive/2010/10/13/129698.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vc模拟鼠标键盘操作实用类</title><link>http://www.cppblog.com/fdsajhg/archive/2010/10/06/128830.html</link><dc:creator>傅先生</dc:creator><author>傅先生</author><pubDate>Wed, 06 Oct 2010 14:56:00 GMT</pubDate><guid>http://www.cppblog.com/fdsajhg/archive/2010/10/06/128830.html</guid><wfw:comment>http://www.cppblog.com/fdsajhg/comments/128830.html</wfw:comment><comments>http://www.cppblog.com/fdsajhg/archive/2010/10/06/128830.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/fdsajhg/comments/commentRss/128830.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/fdsajhg/services/trackbacks/128830.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: vc模拟鼠标键盘操作实用类CND8学院　VC教程　发布日期：2008年12月11日&nbsp;将本文收藏到：&nbsp;|&nbsp;收藏到本地&nbsp;|&nbsp;复制本文地址----------------------------------------------------&nbsp;mouse_event(MOUSEEVENTF_LEFTDOWN,1,1,1,1);---------...&nbsp;&nbsp;<a href='http://www.cppblog.com/fdsajhg/archive/2010/10/06/128830.html'>阅读全文</a><img src ="http://www.cppblog.com/fdsajhg/aggbug/128830.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/fdsajhg/" target="_blank">傅先生</a> 2010-10-06 22:56 <a href="http://www.cppblog.com/fdsajhg/archive/2010/10/06/128830.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用Visual C++操作INI文件</title><link>http://www.cppblog.com/fdsajhg/archive/2010/09/29/128010.html</link><dc:creator>傅先生</dc:creator><author>傅先生</author><pubDate>Tue, 28 Sep 2010 21:32:00 GMT</pubDate><guid>http://www.cppblog.com/fdsajhg/archive/2010/09/29/128010.html</guid><wfw:comment>http://www.cppblog.com/fdsajhg/comments/128010.html</wfw:comment><comments>http://www.cppblog.com/fdsajhg/archive/2010/09/29/128010.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/fdsajhg/comments/commentRss/128010.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/fdsajhg/services/trackbacks/128010.html</trackback:ping><description><![CDATA[<div id=art_title>
<h3><a href="http://tangfeng.javaeye.com/blog/79843"><u><font color=#7d0000>VC中INI文件读写</font></u></a></h3>
<p><br><br><br>&nbsp;</p>
<h2>VC: 程序如何得到本身的执行路径</h2>
<p><input id=search-key type=hidden value="VC: 程序如何得到本身的执行路径" name=search-key> </p>
<div class="rl entry-titlerl fenlei-Span">分类:<a href="http://coosign.bokee.com/cat.10343942.html"><font color=#8d8d8d>技术笔记</font></a></div>
<div class=fbzt><span class=f><span class=pub-date title=发布日期>2007.7.28</span> <span class=pub-time title=发布时间>22:10</span> <span class=ln-author>作者：<a class=author href="http://id.bokee.com/showInfo.b?username=coosign.bokee.com"><font color=#8d8d8d>coosign</font></a></span> | <a class=author href="http://coosign.bokee.com/viewdiary.17170974.html#remark"><font color=#8d8d8d>评论：0</font></a> | <span class=ln-viewed id=h17170974>阅读：1525</span> </span></div>
<div class="entry-body nerr">调用GetCurrentPath，如果使用了对话框选择文件什么的，那么得到的目录就是那个对话框的了。<br>应该使用：GetModuleFileName<br>代码示例：<br>&nbsp;&nbsp;&nbsp; char *temp;<br>&nbsp;&nbsp;&nbsp; char *drive;<br>&nbsp;&nbsp;&nbsp; char *dir;<br>&nbsp;&nbsp;&nbsp; temp = new char[256];<br>&nbsp;&nbsp;&nbsp; drive = new char[256];<br>&nbsp;&nbsp;&nbsp; dir = new char[256];<br><br>&nbsp;&nbsp;&nbsp; CString str1, str2;<br><br>&nbsp;&nbsp;&nbsp; GetModuleFileName(NULL, temp, 256);<br>&nbsp;&nbsp;&nbsp; _splitpath(temp, drive, dir, NULL, NULL&nbsp; );<br><br>&nbsp;&nbsp;&nbsp; str1 = drive;<br>&nbsp;&nbsp;&nbsp; str2 = str1+dir;&nbsp; /* 这个str2就是工程的目录&nbsp; * /<br>&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; delete temp;<br>&nbsp;&nbsp; delete drive;<br>&nbsp;&nbsp; delete dir;<br>&nbsp;&nbsp;&nbsp; <br>关于_splitpath， 从MSDN摘抄如下：<br>Code<br>&nbsp; _makepath( path_buffer, "c", "\\sample\\crt\\", "makepath", "c" );<br>&nbsp;&nbsp; printf( "Path created with _makepath: %s\n\n", path_buffer );<br>&nbsp;&nbsp; _splitpath( path_buffer, drive, dir, fname, ext );<br>Output<br><br>Path created with _makepath: c:\sample\crt\makepath.c<br><br>Path extracted with _splitpath:<br>&nbsp; Drive: c:<br>&nbsp; Dir: \sample\crt\<br>&nbsp; Filename: makepath<br>&nbsp; Ext: .c<br></div>
<div class=blog_content>
<div class=cnt>
<p>在VC程序中利用系统提供的GetPrivateProfileString及WritePrivateProfileString函数直接读写系统配置ini文件(指定目录下的Ini文件)</p>
<p>假设在当前目录下有一个文件名为Tets.ini的文件<br>用于保存用户名和密码<br>文件格式如下：<br>[Section1]<br>Item1=huzhifeng<br>Item2=1234565</p>
<p>1.写INI文件<br>void CINI_File_TestDlg::OnButtonWrite() <br>{<br>// TODO: Add your control notification handler code here</p>
<p>CString strSection&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = "Section1";<br>&nbsp;&nbsp; CString strSectionKey&nbsp;&nbsp;&nbsp;&nbsp; = "Item1";<br>char strBuff[256];<br>&nbsp;&nbsp; CString strValue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = _T("");<br>CString strFilePath;</p>
<p>strFilePath=GetCurrentDirectory(256,strBuff);&nbsp;&nbsp; //获取当前路径<br>strFilePath.Format("%s\\Test.ini",strBuff);</p>
<p>GetDlgItemText(IDC_EDIT_NAME,strValue);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //获取文本框内容：即姓名<br>WritePrivateProfileString(strSection,strSectionKey,strValue,strFilePath);&nbsp;&nbsp; //写入ini文件中相应字段</p>
<p>strSectionKey="Item2";<br>GetDlgItemText(IDC_EDIT_PASSWORD,strValue);&nbsp;&nbsp;&nbsp; //获取文本框内容：即密码<br>WritePrivateProfileString(strSection,strSectionKey,strValue,strFilePath);<br>}</p>
<p>2.读INI文件内容<br>void CINI_File_TestDlg::OnButtonRead() <br>{<br>// TODO: Add your control notification handler code here<br>CString strSection&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = "Section1";<br>&nbsp;&nbsp; CString strSectionKey&nbsp;&nbsp;&nbsp;&nbsp; = "Item1";<br>char strBuff[256];<br>CString strValue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = _T("");<br>CString strFilePath;</p>
<p>strFilePath=GetCurrentDirectory(256,strBuff);&nbsp;&nbsp; //获取当前路径<br>strFilePath.Format("%s\\Test.ini",strBuff);</p>
<p>GetPrivateProfileString(strSection,strSectionKey,NULL,strBuff,80,strFilePath); //读取ini文件中相应字段的内容<br>strValue=strBuff;<br>SetDlgItemText(IDC_EDIT_NAME,strValue);</p>
<p>strSectionKey="Item2";<br>GetPrivateProfileString(strSection,strSectionKey,NULL,strBuff,80,strFilePath);<br>strValue=strBuff;<br>SetDlgItemText(IDC_EDIT_PASSWORD,strValue);</p>
<p>UpdateData(FALSE);<br>}</p>
</div>
</div>
<br><br><br>用Visual C++操作INI文件</div>
<div class=d2><span class=d2_r>【<a href="javascript:doZoom(16,19)"><u><font color=#0000ff>大</font></u></a> <a href="javascript:doZoom(14,17)"><u><font color=#0000ff>中</font></u></a> <a href="javascript:doZoom(12,15)"><u><font color=#0000ff>小</font></u></a>】【<a href="http://www.7880.com/Print.php?PID=b0a7ffc0"><u><font color=#0000ff>打印</font></u></a>】【<a href="http://www.7880.com/Favorite.php?Go=Info::5853ffe0"><u><font color=#0000ff>加入收藏</font></u></a>】【<a href="javascript:window.close()"><u><font color=#0000ff>关闭</font></u></a>】</span> 【<a title=收藏的网页将被永久地保存到新浪ViVi收藏夹http://vivi.sina.com.cn href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(vivi=window.open('http://vivi.sina.com.cn/collect/icollect.php?pid=2008&amp;title='+escape(d.title)+'&amp;url='+escape(d.location.href)+'&amp;desc='+escape(t),'vivi','scrollbars=no,width=480,height=480,left=75,top=20,status=no,resizable=yes'));vivi.focus();"><u><font color=#0000ff>收藏到新浪ViVi</font></u></a>】【<a title=功能强大的网络收藏夹，一秒钟操作就可以轻松实现保存带来的价值、分享带来的快乐 href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();"><u><font color=#0000ff>收藏到365KEY</font></u></a>】 浏览字号:</div>
<div class=d3>日期：2005-06-09 人气： <script language=javascript src="../Read.php?ID=5853ffe0"></script>出处：<a href="http://www.csdn.net/" target=_blank><span class=px12><u><font color=#0000ff>csdn</font></u></span></a> 作者: bluebohe <br><script language=javascript src="/u/_sponsor/infoa1.js"></script><script type=text/javascript>
cpro_client='7880com_cpr';
cpro_at='text_image';
cpro_161=2;
cpro_flush=4;
cpro_w=468;
cpro_h=60;
cpro_template='text_default_468_60';
cpro_cbd='#FFFFFF';
cpro_cbg='#FFFFFF';
cpro_ctitle='#0000ff';
cpro_cdesc='#444444';
cpro_curl='#008000';
cpro_cflush='#e10900';
cpro_uap=1;
cpro_cad=1;
</script><script language=JavaScript src="http://cpro.baidu.com/cpro/ui/cp.js" type=text/javascript></script>
<div style="DISPLAY: none">-</div>
<iframe align=center,center marginWidth=0 marginHeight=0 src="http://cpro.baidu.com/cpro/ui/uijs.php?fv=10&amp;tn=text_default_468_60&amp;n=7880com_cpr&amp;rsi1=60&amp;rsi0=468&amp;rad=&amp;rss0=%23FFFFFF&amp;rss1=%23FFFFFF&amp;rss2=%230000ff&amp;rss3=%23444444&amp;rss4=%23008000&amp;rss5=&amp;rss6=%23e10900&amp;rsi5=4&amp;ts=1&amp;at=7&amp;if=0&amp;word=http%3A%2F%2Fwww.7880.com%2FInfo%2FArticle-5853ffe0.html&amp;refer=&amp;ch=0&amp;lmt=1273041028&amp;csp=1024,768&amp;ccd=16&amp;chi=4&amp;cja=true&amp;cpl=0&amp;cmi=0&amp;cce=true&amp;csl=zh-cn&amp;rt=0&amp;cad=1&amp;aurl=&amp;rss7=&amp;cpa=1&amp;dt=1285709442&amp;pn=2|text_default_468_60&amp;ev=33554432&amp;jn=3&amp;cn=0" frameBorder=0 width=468 scrolling=no height=60 allowTransparency></iframe></div>
<div id=content>
<p>在我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下:</p>
<p>　　一.将信息写入.INI文件中.</p>
<p>　　1.所用的WINAPI函数原型为: </p>
<p>BOOL WritePrivateProfileString(<br>LPCTSTR lpAppName,<br>LPCTSTR lpKeyName,<br>LPCTSTR lpString,<br>LPCTSTR lpFileName<br>); </p>
<p>　　其中各参数的意义:</p>
<p>　　　LPCTSTR lpAppName 是INI文件中的一个字段名.</p>
<p>　　　LPCTSTR lpKeyName 是lpAppName下的一个键名,通俗讲就是变量名.</p>
<p>　　　LPCTSTR lpString 是键值,也就是变量的值,不过必须为LPCTSTR型或CString型的.</p>
<p>　　　LPCTSTR lpFileName 是完整的INI文件名.</p>
<p>　　2.具体使用方法:设现有一名学生,需把他的姓名和年龄写入 c:\stud\student.ini 文件中. </p>
<p>CString strName,strTemp;<br>int nAge;<br>strName="张三";<br>nAge=12;<br>::WritePrivateProfileString("StudentInfo","Name",strName,"c:\\stud\\student.ini"); </p>
<p>　　此时c:\stud\student.ini文件中的内容如下:</p>
<p>　　　[StudentInfo]<br>　　　Name=张三</p>
<p>　　3.要将学生的年龄保存下来,只需将整型的值变为字符型即可:</p>
<p>strTemp.Format("%d",nAge);<br>::WritePrivateProfileString("StudentInfo","Age",strTemp,"c:\\stud\\student.ini"); <br>　二.将信息从INI文件中读入程序中的变量.</p>
<p>　　1.所用的WINAPI函数原型为:</p>
<p>DWORD GetPrivateProfileString(<br>LPCTSTR lpAppName, <br>LPCTSTR lpKeyName, <br>LPCTSTR lpDefault, <br>LPTSTR lpReturnedString, <br>DWORD nSize, <br>LPCTSTR lpFileName <br>); </p>
<p>　　其中各参数的意义: </p>
<p>　　　前二个参数与 WritePrivateProfileString中的意义一样.</p>
<p>　　　lpDefault : 如果INI文件中没有前两个参数指定的字段名或键名,则将此值赋给变量. </p>
<p>　　　lpReturnedString : 接收INI文件中的值的CString对象,即目的缓存器.</p>
<p>　　　nSize : 目的缓存器的大小.</p>
<p>　　　lpFileName : 是完整的INI文件名.</p>
<p>　　2.具体使用方法:现要将上一步中写入的学生的信息读入程序中.</p>
<p>CString strStudName;<br>int nStudAge; <br>GetPrivateProfileString("StudentInfo","Name","默认姓名",strStudName.GetBuffer(MAX_PATH),MAX_PATH,"c:\\stud\\student.ini"); </p>
<p>　　执行后 strStudName 的值为:"张三",若前两个参数有误,其值为:"默认姓名".</p>
<p>　　3.读入整型值要用另一个WINAPI函数: </p>
<p>UINT GetPrivateProfileInt(<br>LPCTSTR lpAppName, <br>LPCTSTR lpKeyName, <br>INT nDefault, <br>LPCTSTR lpFileName <br>); </p>
<p>　　这里的参数意义与上相同.使用方法如下:</p>
<p>nStudAge=GetPrivateProfileInt("StudentInfo","Age",10,"c:\\stud\\student.ini"); <br>三.循环写入多个值,设现有一程序,要将最近使用的几个文件名保存下来,具体程序如下:</p>
<p>　　1.写入:</p>
<p>CString strTemp,strTempA;<br>int i;<br>int nCount=6;<br>file://共有6个文件名需要保存<br>for(i=0;i {strTemp.Format("%d",i);<br>strTempA=文件名;<br>file://文件名可以从数组,列表框等处取得.<br>::WritePrivateProfileString("UseFileName","FileName"+strTemp,strTempA,<br>"c:\\usefile\\usefile.ini");<br>}<br>strTemp.Format("%d",nCount);<br>::WritePrivateProfileString("FileCount","Count",strTemp,"c:\\usefile\\usefile.ini");<br>file://将文件总数写入,以便读出. </p>
<p>　　2.读出:</p>
<p>nCount=::GetPrivateProfileInt("FileCount","Count",0,"c:\\usefile\\usefile.ini");<br>for(i=0;i {strTemp.Format("%d",i);<br>strTemp="FileName"+strTemp;<br>::GetPrivateProfileString("CurrentIni",strTemp,"default.fil", strTempA.GetBuffer(MAX_PATH),MAX_PATH,"c:\\usefile\\usefile.ini");</p>
<p>file://使用strTempA中的内容.</p>
<p>} </p>
<p>　　补充四点:</p>
<p>　　　1.INI文件的路径必须完整,文件名前面的各级目录必须存在,否则写入不成功,该函数返回 FALSE 值.</p>
<p>　　　2.文件名的路径中必须为 \\ ,因为在VC++中, \\ 才表示一个 \ .</p>
<p>　　　3.也可将INI文件放在程序所在目录,此时 lpFileName 参数为: ".\\student.ini".</p>
</div>
<img src ="http://www.cppblog.com/fdsajhg/aggbug/128010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/fdsajhg/" target="_blank">傅先生</a> 2010-09-29 05:32 <a href="http://www.cppblog.com/fdsajhg/archive/2010/09/29/128010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>实用类</title><link>http://www.cppblog.com/fdsajhg/archive/2010/09/26/127692.html</link><dc:creator>傅先生</dc:creator><author>傅先生</author><pubDate>Sat, 25 Sep 2010 20:27:00 GMT</pubDate><guid>http://www.cppblog.com/fdsajhg/archive/2010/09/26/127692.html</guid><wfw:comment>http://www.cppblog.com/fdsajhg/comments/127692.html</wfw:comment><comments>http://www.cppblog.com/fdsajhg/archive/2010/09/26/127692.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/fdsajhg/comments/commentRss/127692.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/fdsajhg/services/trackbacks/127692.html</trackback:ping><description><![CDATA[<code><font style="font: 10pt Comic Sans MS; color: #008000; ">////////OnTimer&nbsp;四步曲<br>
<br>
///第一步:在头文件添加---<br>
</font><font style="font: 10pt Fixedsys; color: #0000FF; ">class&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">CPop3Dlg&nbsp;</font><font style="font: 10pt Fixedsys; color: #000080; ">:&nbsp;</font><font style="font: 10pt Fixedsys; color: #0000FF; ">public&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">CDialog<br>
</font><font style="font: 10pt Fixedsys; color: #000080; ">{<br>
</font><font style="font: 10pt Comic Sans MS; color: #008000; ">//&nbsp;Construction<br>
</font><font style="font: 10pt Fixedsys; color: #0000FF; ">public</font><font style="font: 10pt Fixedsys; color: #000080; ">:<br>
........<br>
</font><font style="font: 10pt Fixedsys; color: #000000; ">afx_msg&nbsp;</font><font style="font: 10pt Fixedsys; color: #0000FF; ">void&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">OnTimer</font><font style="font: 10pt Fixedsys; color: #000080; ">(</font><font style="font: 10pt Fixedsys; color: #000000; ">UINT&nbsp;nIDEvent</font><font style="font: 10pt Fixedsys; color: #000080; ">);<br>
........<br>
}<br>
<br>
</font><font style="font: 10pt Comic Sans MS; color: #008000; ">///第二步:在文件中添加....<br>
</font><font style="font: 10pt Fixedsys; color: #000000; ">BEGIN_MESSAGE_MAP</font><font style="font: 10pt Fixedsys; color: #000080; ">(</font><font style="font: 10pt Fixedsys; color: #000000; ">CPop3Dlg</font><font style="font: 10pt Fixedsys; color: #000080; ">,&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">CDialog</font><font style="font: 10pt Fixedsys; color: #000080; ">)<br>
{<br>
.........<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">ON_WM_TIMER</font><font style="font: 10pt Fixedsys; color: #000080; ">()<br>
.........<br>
}<br>
<br>
</font><font style="font: 10pt Comic Sans MS; color: #008000; ">////第三步:初始化地方添加<br>
</font><font style="font: 10pt Fixedsys; color: #000000; ">BOOL&nbsp;CPop3Dlg</font><font style="font: 10pt Fixedsys; color: #000080; ">::</font><font style="font: 10pt Fixedsys; color: #000000; ">OnInitDialog</font><font style="font: 10pt Fixedsys; color: #000080; ">()<br>
{<br>
.......<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">SetTimer</font><font style="font: 10pt Fixedsys; color: #000080; ">(</font><font style="font: 10pt Fixedsys; color: #800080; ">1</font><font style="font: 10pt Fixedsys; color: #000080; ">,&nbsp;</font><font style="font: 10pt Fixedsys; color: #800080; ">4000</font><font style="font: 10pt Fixedsys; color: #000080; ">,&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">NULL</font><font style="font: 10pt Fixedsys; color: #000080; ">);<br>
.......<br>
}&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
</font><font style="font: 10pt Comic Sans MS; color: #008000; ">////&nbsp;&nbsp;&nbsp;&nbsp;函数添加<br>
</font><font style="font: 10pt Fixedsys; color: #0000FF; ">void&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">CPop3Dlg</font><font style="font: 10pt Fixedsys; color: #000080; ">::</font><font style="font: 10pt Fixedsys; color: #000000; ">OnTimer</font><font style="font: 10pt Fixedsys; color: #000080; ">(</font><font style="font: 10pt Fixedsys; color: #000000; ">UINT&nbsp;nIDEvent</font><font style="font: 10pt Fixedsys; color: #000080; ">)<br>
{<br>
.......<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font style="font: 10pt Fixedsys; color: #000000; ">OnConn</font><font style="font: 10pt Fixedsys; color: #000080; ">();<br>
......&nbsp;&nbsp;&nbsp;&nbsp;<br>
</font><font style="font: 10pt Comic Sans MS; color: #008000; ">//&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox(&quot;tttttttt&quot;);<br>
</font><font style="font: 10pt Fixedsys; color: #000080; ">}</font></code><img src ="http://www.cppblog.com/fdsajhg/aggbug/127692.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/fdsajhg/" target="_blank">傅先生</a> 2010-09-26 04:27 <a href="http://www.cppblog.com/fdsajhg/archive/2010/09/26/127692.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CString的构造函数</title><link>http://www.cppblog.com/fdsajhg/archive/2010/09/14/126619.html</link><dc:creator>傅先生</dc:creator><author>傅先生</author><pubDate>Tue, 14 Sep 2010 14:27:00 GMT</pubDate><guid>http://www.cppblog.com/fdsajhg/archive/2010/09/14/126619.html</guid><wfw:comment>http://www.cppblog.com/fdsajhg/comments/126619.html</wfw:comment><comments>http://www.cppblog.com/fdsajhg/archive/2010/09/14/126619.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/fdsajhg/comments/commentRss/126619.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/fdsajhg/services/trackbacks/126619.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: CString&nbsp;成员函数用法大全&nbsp;Posted&nbsp;on&nbsp;2009-02-16&nbsp;00:17&nbsp;蔡清华&nbsp;阅读(6995)&nbsp;评论(2)&nbsp;编辑&nbsp;收藏&nbsp;&nbsp;&nbsp;&nbsp;CString的构造函数CString(&nbsp;);例：CString&nbsp;csS...&nbsp;&nbsp;<a href='http://www.cppblog.com/fdsajhg/archive/2010/09/14/126619.html'>阅读全文</a><img src ="http://www.cppblog.com/fdsajhg/aggbug/126619.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/fdsajhg/" target="_blank">傅先生</a> 2010-09-14 22:27 <a href="http://www.cppblog.com/fdsajhg/archive/2010/09/14/126619.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>