﻿<?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++博客-程序描绘人生-随笔分类-Windows开发</title><link>http://www.cppblog.com/humanchao/category/20273.html</link><description>知识改变命运，学习成就未来。</description><language>zh-cn</language><lastBuildDate>Wed, 28 May 2014 02:33:14 GMT</lastBuildDate><pubDate>Wed, 28 May 2014 02:33:14 GMT</pubDate><ttl>60</ttl><item><title>转：CTime与CString相互转化  </title><link>http://www.cppblog.com/humanchao/archive/2014/05/13/206944.html</link><dc:creator>胡满超</dc:creator><author>胡满超</author><pubDate>Tue, 13 May 2014 08:05:00 GMT</pubDate><guid>http://www.cppblog.com/humanchao/archive/2014/05/13/206944.html</guid><wfw:comment>http://www.cppblog.com/humanchao/comments/206944.html</wfw:comment><comments>http://www.cppblog.com/humanchao/archive/2014/05/13/206944.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/humanchao/comments/commentRss/206944.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/humanchao/services/trackbacks/206944.html</trackback:ping><description><![CDATA[<p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>转自：</span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px;">http://blog.163.com/javy1225@126/blog/static/459230342009230115919910/</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span><br />一.CTime转化为CString</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>CTime&nbsp; tmSCan =&nbsp;CTime::GetCurrentTime();</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>CString szTime = tmScan.Format("'%Y-%m-%d %H:%M:%S'");</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>这样得到的日期时间字符串就是以"2006-11-27 23:30:59"的格式.这是不是很方便呢?</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>&nbsp;//取得CTime中的日期</span><br /><span>&nbsp;CString cstrDate = tmScan.Format("%Y-%m-%d");</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>&nbsp;//取得CTime中的时间</span><br /><span>&nbsp;CString cstrTime = tmScan.Format("%H:%M-%S");</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>二.CString转化为CTime的几种方法</span></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;">CString &nbsp; timestr &nbsp; = &nbsp; "2000年04月05日"; &nbsp;&nbsp;<br />&nbsp; int &nbsp; a,b,c &nbsp; ; &nbsp;&nbsp;<br />&nbsp; sscanf(timestr.GetBuffer(timestr.GetLength()),"%d年%d月%d日",&amp;a,&amp;b,&amp;c); &nbsp;&nbsp;<br />&nbsp; CTime &nbsp; time(a,b,c,0,0,0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><br /><br />--------or - ---------------------<br /><br />&nbsp;CString &nbsp; s("2001-8-29 &nbsp; 19:06:23"); &nbsp;&nbsp;<br />&nbsp; int &nbsp; nYear, &nbsp; nMonth, &nbsp; nDate, &nbsp; nHour, &nbsp; nMin, &nbsp; nSec; &nbsp;&nbsp;<br />&nbsp;<strong> sscanf(s, &nbsp; "%d-%d-%d &nbsp; %d:%d:%d", &nbsp; &amp;nYear, &nbsp; &amp;nMonth, &nbsp; &amp;nDate, &nbsp; &amp;nHour, &nbsp; &amp;nMin, &nbsp; &amp;nSec); &nbsp;&nbsp;</strong><br />&nbsp; CTime &nbsp; t(nYear, &nbsp; nMonth, &nbsp; nDate, &nbsp; nHour, &nbsp; nMin, &nbsp; nSec);<br /><br />---- or ------------------------<br />CString &nbsp; timestr &nbsp; = &nbsp; "2000年04月05日"; &nbsp;&nbsp;<br />&nbsp; int &nbsp; year,month,day; &nbsp;&nbsp;<br />&nbsp; BYTE &nbsp; tt[5]; &nbsp;&nbsp;<br />&nbsp; //get &nbsp; year &nbsp;&nbsp;<br />&nbsp; memset(tt, &nbsp; 0, &nbsp; sizeof(tt)); &nbsp;&nbsp;<br />&nbsp; tt[0] &nbsp; = &nbsp; timestr[0]; &nbsp;&nbsp;<br />&nbsp; tt[1] &nbsp; = &nbsp; timestr[1]; &nbsp;&nbsp;<br />&nbsp; tt[2] &nbsp; = &nbsp; timestr[2]; &nbsp;&nbsp;<br />&nbsp; tt[3] &nbsp; = &nbsp; timestr[3]; &nbsp;&nbsp;<br />&nbsp; year= &nbsp; atoi((char &nbsp; *)tt); &nbsp;&nbsp;<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; //get &nbsp; month &nbsp;&nbsp;<br />&nbsp; memset(tt, &nbsp; 0, &nbsp; sizeof(tt)); &nbsp;&nbsp;<br />&nbsp; tt[0] &nbsp; = &nbsp; timestr[6]; &nbsp;&nbsp;<br />&nbsp; tt[1] &nbsp; = &nbsp; timestr[7]; &nbsp;&nbsp;<br />&nbsp; month &nbsp; = &nbsp; atoi((char &nbsp; *)tt); &nbsp;&nbsp;<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; //get &nbsp; day &nbsp;&nbsp;<br />&nbsp; memset(tt, &nbsp; 0, &nbsp; sizeof(tt)); &nbsp;&nbsp;<br />&nbsp; tt[0] &nbsp; = &nbsp; timestr[10]; &nbsp;&nbsp;<br />&nbsp; tt[1] &nbsp; = &nbsp; timestr[11]; &nbsp;&nbsp;<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; CTime &nbsp; time(year,month,day,0,0,0);<br /></p><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #998a62; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fefefd;"><span>从上面来看,很明显使用sscanf()函数的优势.</span></p><img src ="http://www.cppblog.com/humanchao/aggbug/206944.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/humanchao/" target="_blank">胡满超</a> 2014-05-13 16:05 <a href="http://www.cppblog.com/humanchao/archive/2014/05/13/206944.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何写好UI程序</title><link>http://www.cppblog.com/humanchao/archive/2012/08/31/188912.html</link><dc:creator>胡满超</dc:creator><author>胡满超</author><pubDate>Fri, 31 Aug 2012 09:00:00 GMT</pubDate><guid>http://www.cppblog.com/humanchao/archive/2012/08/31/188912.html</guid><wfw:comment>http://www.cppblog.com/humanchao/comments/188912.html</wfw:comment><comments>http://www.cppblog.com/humanchao/archive/2012/08/31/188912.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/humanchao/comments/commentRss/188912.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/humanchao/services/trackbacks/188912.html</trackback:ping><description><![CDATA[<p><span style="font-family: 宋体; font-size: 14pt; ">在</span><span style="font-size: 14pt; ">Windows</span><span style="font-family: 宋体; font-size: 14pt; ">平台做开发肯定会接触到</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">程序的编写，以</span><span style="font-size: 14pt; ">MFC</span><span style="font-family: 宋体; font-size: 14pt; ">的</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">开发为例，可以开发单文档，多文档，对话框等形式的应用。写一个</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">程序容易，写好却不是一件简单的事情。在整个代码结构的清晰性与可维护性方面需要多加注意。写好</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">程序需求注意以下几点：</span></p>  <p>&nbsp;</p>  <p><strong style="font-size: 14pt; ">1</strong><strong style="font-size: 14pt; "><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、围绕数据编程与不是围绕</span>UI</strong><strong style="font-size: 14pt; "><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">编程</span></strong></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体; font-size: 14pt; ">当我们拿到需求最先接触到的就是</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">的设计，也许是美工画的，也许是设计草图。工程师在具体设计的时候容易受</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">的影响，或者干脆从</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">开始编程。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体; font-size: 14pt; ">这是一个错误的编程习惯，无论</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">如何展现与交互，最终都应该围绕数据编程。拿到需求后，应该先思考和推敲数据的设计与流转，</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">不过就是数据的一种展现形式而已。</span></p>  <p>&nbsp;</p>  <p><strong style="font-size: 14pt; ">2</strong><strong style="font-size: 14pt; "><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、做好</span>UI</strong><strong style="font-size: 14pt; "><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">与逻辑的解耦</span></strong></p>  <p>&nbsp;</p>  <p><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">的编程会涉及到许多控件的操作，消息的处理，不知不觉，一个</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">类的代码会越写越大，以至于一段时间以后，浏览和梳理都会变得不太方便。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体; font-size: 14pt; ">在</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">类里，除了与</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">本身的操作有关的代码以外，任何逻辑代码都应该与此解耦，并根据具体情况进行封装调用。如果一个控件关联了太多数据操作，应该把这些操作封装到控件的继承类中，把一类代码进行集中管理和维护。</span></p>  <p>&nbsp;</p>  <p><span style="font-family: 宋体; font-size: 14pt; ">上述问题，在程序写作的初期还不太明显，随着代码逐渐膨胀，会越会越让人难以忍受。</span></p>  <p>&nbsp;</p>  <p><strong style="font-size: 14pt; ">3</strong><strong style="font-size: 14pt; "><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">、数据单向依赖，单向更新</span></strong></p>  <p>&nbsp;</p>  <p><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">围绕的数据进行展现与更新，在这个过程中，所以对数据的操作应该进行封装，而不是散落在</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">程序在各个角落，数据的更新、获取和</span><span style="font-size: 14pt; ">UI</span><span style="font-family: 宋体; font-size: 14pt; ">传递消息时，应该单向操作，如果出现循环处理的情况，在以后维护调试的</span><span style="font-size: 14pt; ">BUG</span><span style="font-family: 宋体; font-size: 14pt; ">的过程中会变得比较困难，导致维护效率下降。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p><img src ="http://www.cppblog.com/humanchao/aggbug/188912.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/humanchao/" target="_blank">胡满超</a> 2012-08-31 17:00 <a href="http://www.cppblog.com/humanchao/archive/2012/08/31/188912.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>