??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲日本va中文字幕久久,狠狠色婷婷久久一区二区,久久精品国产2020http://www.shnenglu.com/flyingxu/category/824.htmlto get ready...zh-cnWed, 21 May 2008 20:10:07 GMTWed, 21 May 2008 20:10:07 GMT60我的新博客在 http://www.codediscuss.comhttp://www.shnenglu.com/flyingxu/archive/2007/10/02/33321.htmlflyingxuflyingxuTue, 02 Oct 2007 06:23:00 GMThttp://www.shnenglu.com/flyingxu/archive/2007/10/02/33321.htmlhttp://www.shnenglu.com/flyingxu/comments/33321.htmlhttp://www.shnenglu.com/flyingxu/archive/2007/10/02/33321.html#Feedback1http://www.shnenglu.com/flyingxu/comments/commentRss/33321.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/33321.html我的新博客在

http://www.codediscuss.com
   文章指数:0  
http://www.codediscuss.com 是我的博客的新地址。还是以VC++~程ZQ有mfcQ英语,q有点点shareware的内宏V?br>


flyingxu 2007-10-02 14:23 发表评论
]]>
Memory leak in CWinThread?http://www.shnenglu.com/flyingxu/archive/2006/07/26/10557.htmlflyingxuflyingxuWed, 26 Jul 2006 11:11:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/07/26/10557.htmlhttp://www.shnenglu.com/flyingxu/comments/10557.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/07/26/10557.html#Feedback3http://www.shnenglu.com/flyingxu/comments/commentRss/10557.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/10557.htmlcM的问题见http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20084406.html

下面的代码,当用AfxBeginThread开始一个线E时Q实际上是有内存泄漏?/p>

for  (ii  =   0 ; ii  <   1000 ; ii ++
{
  CWinThread 
*
pWinThread; 
  pWinThread 
=
 AfxBeginThread(ThreadLBProc, NULL);
  ::Sleep(
500
);
}

UINT ThreadLBProc(LPVOID pParam)
{
  
return   0
;
}

VC输出的典型提CZؓQ?br />Detected memory leaks!
Dumping objects ->
thrdcore.cpp(166) : {782} client block at 0x00425300, subtype 0, 112 bytes long.
实际上,只要看到?font style="BACKGROUND-COLOR: #ffff00">thrdcore.cpp(166) 的内存泄漏,基本是同一个原因,和上面的代码一栗?br />解决Ҏ(gu)Q?br />step 1)
在线E函CQ记得写AfxEndThread();(与AfxBeginThread对应Q其他的开始线E的函数Q有相应的函?
step 2)
?:WaitForSingleObject()保U程d退?br />
step 2是比较容易忽略的Q用sleep函数只能侥幸的保证线E退出,但不能确保?img src ="http://www.shnenglu.com/flyingxu/aggbug/10557.html" width = "1" height = "1" />

flyingxu 2006-07-26 19:11 发表评论
]]>
再调试状态下Q按下F12Q程序就出错了(VCQ?/title><link>http://www.shnenglu.com/flyingxu/archive/2006/07/13/9818.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 13 Jul 2006 10:29:00 GMT</pubDate><guid>http://www.shnenglu.com/flyingxu/archive/2006/07/13/9818.html</guid><wfw:comment>http://www.shnenglu.com/flyingxu/comments/9818.html</wfw:comment><comments>http://www.shnenglu.com/flyingxu/archive/2006/07/13/9818.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/flyingxu/comments/commentRss/9818.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/flyingxu/services/trackbacks/9818.html</trackback:ping><description><![CDATA[用VC调试E序Q只要按下F12Q程序就出错了,出错的代码还很奇怪,再PeekMessage中,但是只出现在调试Q按F5Q,不出现在全速运行(Ctrl+F5Q,release版本也没有问?br />|上的解{?<br /><a >http://support.microsoft.com/kb/q130667/</a> F12居然是q么定义的,ft<br /><br />所以,在定义程序功能的时候,尽量不要用到F12 Q哈<img src ="http://www.shnenglu.com/flyingxu/aggbug/9818.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/flyingxu/" target="_blank">flyingxu</a> 2006-07-13 18:29 <a href="http://www.shnenglu.com/flyingxu/archive/2006/07/13/9818.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Is MSDN wrong? or I made a mistake? about static member functionhttp://www.shnenglu.com/flyingxu/archive/2006/07/11/9697.htmlflyingxuflyingxuTue, 11 Jul 2006 11:14:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/07/11/9697.htmlhttp://www.shnenglu.com/flyingxu/comments/9697.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/07/11/9697.html#Feedback3http://www.shnenglu.com/flyingxu/comments/commentRss/9697.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/9697.htmlhttp://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&tid=402a414c-a125-45bd-9cf4-c1819db7e3e4Q?br />
in http://msdn2.microsoft.com/en-us/library/480b7kf7.aspx, it says that 
pGdiObject->DeleteTempMap()
;  // Causes compiler error

But I'm confused for a static member can be called by the object or a pointer.
Is there anything wrong of my understanding?

回答的h到蛮多,讨论的也很热烈,但都没有直接回答我的问题Q我的问题是Q对于静态函敎ͼ
pGdiObject->DeleteTempMap();  // Causes compiler errorQ?br />到底对不对?如果不对Q就是msdn错了Q不q总觉得比较奇怪,msdn不该L错的

flyingxu 2006-07-11 19:14 发表评论
]]>
[zz]MFCq回的时对象指针成?http://www.shnenglu.com/flyingxu/archive/2006/07/10/9663.htmlflyingxuflyingxuMon, 10 Jul 2006 15:18:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/07/10/9663.htmlhttp://www.shnenglu.com/flyingxu/comments/9663.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/07/10/9663.html#Feedback0http://www.shnenglu.com/flyingxu/comments/commentRss/9663.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/9663.htmlcsdn上难得的好文章,怕不争气的csdn|站q几天又找不到这文章了Q我得先转一下,保存一下:
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=193097

Q : MFCq回的时对象指针成?
主要解答? QunKangLi 提交? QunKangLi
感谢: oldforest、yu_hl、QunKangLi
审核? happyparrot C֌对应贴子: 查看
     A :

msdn在介lGetDlgItem的时候,明确指出Q? 
The  returned  pointer  may  be  temporary  and  should  not  be  stored  for  later  use.  
如果真是q样那我不惨了!在我的一个Y件中Q因为常常要使切换按钮的可用与不可用以及改变按钮文字Q所以我用DetDlgItem把它们存了v来,用的时候直接到数组里面取,q样的话q个软g不是犯了一个重大的错误了?可是用这么久也没出错? 
另外Q它也是说可能是临时的,那一定在某种情况下不是时的Q高手能不能解释一下这个问题?  
---------------------------------------------------------------  
//    Most  Windows  objects  are  represented  with  a  HANDLE,  including  
//            the  most  important  ones,  HWND,  HDC,  HPEN,  HFONT  etc.  
//    We  want  C++  objects  to  wrap  these  handle  based  objects  whenever  we  can.  
//    Since  Windows  objects  can  be  created  outside  of  C++  (eg:  calling  
//            ::CreateWindow  will  return  an  HWND  with  no  C++  wrapper)  we  must  
//            support  a  reasonably  uniform  mapping  from  permanent  handles  
//            (i.e.  the  ones  allocated  in  C++)  and  temporary  handles  (i.e.  
//            the  ones  allocated  in  C,  but  passed  through  a  C++  interface.  
//    We  keep  two  dictionaries  for  this  purpose.    The  permanent  dictionary  
//            stores  those  C++  objects  that  have  been  explicitly  created  by  
//            the  developer.    The  C++  constructor  for  the  wrapper  class  will  
//            insert  the  mapping  into  the  permanent  dictionary  and  the  C++  
//            destructor  will  remove  it  and  possibly  free  up  the  associated  
//            Windows  object.  
//    When  a  handle  passes  through  a  C++  interface  that  doesn't  exist  in  
//            the  permanent  dictionary,  we  allocate  a  temporary  wrapping  object  
//            and  store  that  mapping  into  the  temporary  dictionary.  
//    At  idle  time  the  temporary  wrapping  objects  are  flushed  (since  you  better  
//            not  be  holding  onto  something  you  didn't  create).  
//  
 
 
在CWinThread::OnIdle里调用AfxUnlockTempMapsQAfxUnlockTempMaps会释放temporary  maps.  
 
所以不要保留GetDlgItem{返回的临时指针Q可以直接保存HWND  objectsQ然后CWnd::FromHandle获取临时指针来用? 
 
---------------------------------------------------------------  
 
临时包装对象会在I闲旉删除.在同一函数中多ơ用是没用问题?不同函数中用先前保存下来的指针有可能出错,特别是对话框初化时候存下来的指?  
       在MFC层次上的函数使用CWnd对象,而本地Windows代码(API)使用句柄.?当Windowspȝ调用一个窗口过E时传递一个HWND参数,而MFC本n的消息机制用CWndc?Z更好更高效的实现,MFC需要与Windowspȝ合作,句柄与CWnd对象q行兌---它用CHandleMap完成兌.  
CHandleMap有两个CMapPtrToPtr的成员变?m_permanentMap(怹映射?E序q行q程中对?句柄之间的关p?,m_temporaryMap(临时映射?在消息存在的q程中才存在).怹表保存显式创建的CWnd对象,当对象创建时在怹目录下插入一个条?在CWnd::OnNcDestrory时删除对应条?但是Windows有时会传入某些不是由开发h员显式创建的H口的句?此时MFC会分配一个时对象来包装q个句柄q将它们的映保存到临时映射表中,q些临时对象会在I闲旉被删除ƈU走相应的时映表条目.cM的MFC对象与Windows句柄的映表?  
m_pmapHWND:                        H口句柄与CWnd对象  
m_pampHMENU:                        菜单句柄与CMenu对象  
m_pmapHDC:                        讑֤环境句柄与CDC对象  
m_pmapHGDIOBJ:                        GDI句柄与CGDI对象  
m_mapHIMAGELIST:            囑փ链表句柄到CImageList对象  
 
当给定句?如HWND?MFC单调用CWnd*  PASCAL  CWnd::FromHandle(HWND  hWnd),  此函数内部用CHandleMap::FromHandle(hWnd)获取相关联的CWnd对象.在CHandleMap::FromHandle(h)内部(源代码在WinHand.cpp),先用CObject*  pObject  =  LookupPermanent(h);            if  (pObject  !=  NULL)return  pObject;    查永久表;如永久表中不存在,使用pObject  =  LookupTemporary(h))  !=  NULL查时表,都不存在?使用pTemp  =  =  m_pClass->CreateObject();if  (pTemp  ==  NULL)AfxThrowMemoryException();m_temporaryMap.SetAt((LPVOID)h,  pTemp);创徏临时对象q将其插入到临时表中?同时q回该时对?  
void  CHandleMap::RemoveHandle(HANDLE  h)的注释说明时对象将在空闲时由O(jin)nIdel释放:  
           //  remove  only  from  permanent  map  --  temporary  objects  are  removed  
           //    at  idle  in  CHandleMap::DeleteTemp,  always!  
如果想不自动释放临时对象,使用void  AFXAPI  AfxLockTempMaps()/BOOL  AFXAPI  AfxUnlockTempMaps(BOOL  bDeleteTemps)q行锁定.  





flyingxu 2006-07-10 23:18 发表评论
]]>
bugQ?OnIdle called only while mouse's movinghttp://www.shnenglu.com/flyingxu/archive/2006/07/09/9593.htmlflyingxuflyingxuSat, 08 Jul 2006 18:03:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/07/09/9593.htmlhttp://www.shnenglu.com/flyingxu/comments/9593.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/07/09/9593.html#Feedback1http://www.shnenglu.com/flyingxu/comments/commentRss/9593.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/9593.htmlhttp://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&mid=1aa1eddf-7bcf-407b-84fe-234fe0975331&sloc=en-usQ?br />
I need to update one class data and the view during the idle, I used this  
method 
in the Cdoc:
void CMyAppDoc::OnIdle(){

    theClass
->
Update();
    POSITION pos 
=
 GetFirstViewPosition();
    CView
* pView =
 GetNextView(pos);
    pView
->Invalidate(true
);
    pView
->
UpdateWindow();    
}


It works only when I move the mouse, what
's wrong? Z_Z
q个问题的确比较搞,要好好看mfc源码的,下面是我的回{?br />Nothing is wrong, I can explain it  is by design.
Please take a look at the source code of int CWinThread::Run(), in that function, IsIdleMessage() is called, and in IsIdleMessage() WM_PAINT is ignored, which means WM_PAINT will not cause OnIdle to be called, for windows think it's just a WM_PAINT message and will not change the UI.
Your UpdateWindow() only post a WM_PAINT message, the message queue is not empty but it's ignored by IsIdleMessage(), that's why.
But when you move your mouse, the message queue is filled with some WM_MOUSEMOVE and it's not ignored for the position changes. So your OnIdle() is called again.
-
My suggestion is to move your Invalidate & UpdateWindow code to somewhere else.
OnIdleQ)的确是个有点复杂的问题,我可能还会写几篇文章 Q)
q里Q?a >http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/14f20aa5ffd6994d/66b6e5949a31bfa2?lnk=st&q=AfxUnlockTempMaps&rnum=40&hl=zh-CN#66b6e5949a31bfa2Q有文章讲的很C

flyingxu 2006-07-09 02:03 发表评论
]]>
_asm int 3 的一个应用:在程序运行后再进入调试器http://www.shnenglu.com/flyingxu/archive/2006/07/06/9493.htmlflyingxuflyingxuThu, 06 Jul 2006 09:35:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/07/06/9493.htmlhttp://www.shnenglu.com/flyingxu/comments/9493.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/07/06/9493.html#Feedback8http://www.shnenglu.com/flyingxu/comments/commentRss/9493.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/9493.html1Q启动调试器Q比如VC
2Q在VC中设断点
3Q操作程序,使得E序q行到断点,停下?br />但是现在我遇C个情况,希望调试的情景是q样的:双击某个文gQ我的程序启动后Q这个时候我想程序停下来Q让我在VC中调试它?br />但是Q双L件后启动的程序,是个独立的exeq行E序Q肯定不是在VC的运行控制下的,VC中设|的断点不v作用的。怎么办呢Q?br />q个时候可以在惌E序停下来的地方增加指o_asm int 3Qdebug下编译好。双L件后q行q个exeQ在exeq行到_asm int 3Ӟ׃中断Q而把当前的exeq行与一个新的调试器Q一个新的VCq程Q结合v来。接下来像一般的调试了?br />q时的调试步骤类gQ?br />1Q程序运?br />2Q遇到特定条件时Q_asm int 3把当前exe与一个新的调试器Q比如一个新的VCq程Q联pv?br />3Q在调试器中调试exe

Q)

flyingxu 2006-07-06 17:35 发表评论
]]>
ANSI版本保存的文Ӟ在UNICODE时是否依然能dQ?/title><link>http://www.shnenglu.com/flyingxu/archive/2006/06/13/8521.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Tue, 13 Jun 2006 15:53:00 GMT</pubDate><guid>http://www.shnenglu.com/flyingxu/archive/2006/06/13/8521.html</guid><wfw:comment>http://www.shnenglu.com/flyingxu/comments/8521.html</wfw:comment><comments>http://www.shnenglu.com/flyingxu/archive/2006/06/13/8521.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/flyingxu/comments/commentRss/8521.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/flyingxu/services/trackbacks/8521.html</trackback:ping><description><![CDATA[情况是这LQ一个程序从ansiULCunicodeQ见<a id="viewpost1_TitleUrl" href="/flyingxu/archive/2006/05/18/7356.html"><font color="#000080">把代码移植成UNICODE</font></a> Q?a href="/flyingxu/archive/2006/05/18/7356.html">http://www.shnenglu.com/flyingxu/archive/2006/05/18/7356.html</a>Q,之后产生了一个问题,之前文g保存的那些文Ӟunicode版本q能打开吗?q真是个大问题,如果不能Q就基本表示q个E序已经半死不活了?br /><br />文g的保存基本用的序列化Q比?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font face="Courier New"><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> CSDITestDoc::Serialize(CArchive</span><span style="COLOR: #000000">&</span></font><font face="Courier New"><span style="COLOR: #000000"> ar)<br />{<br />    </span><span style="COLOR: #0000ff">if</span></font><font face="Courier New"><span style="COLOR: #000000"> (ar.IsStoring())<br />    {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: add storing code here</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        ar </span><span style="COLOR: #000000"><<</span></font><font face="Courier New"><span style="COLOR: #000000"> m_strName;<br />    }<br />    </span><span style="COLOR: #0000ff">else</span></font><span style="COLOR: #000000"><br /><font face="Courier New">    {<br />        </font></span><font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: add loading code here</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        ar </span><span style="COLOR: #000000">>></span></font><span style="COLOR: #000000"><font face="Courier New"> m_strName;<br />    }<br />}</font></span></div><font face="Courier New">如果m_strName = _T("name");那么ansi情况下,保存的文件ؓ:<br />04 6E 61 6D 65Q一?个字节?br />然后用unicode版本保存Ӟ?br />FF FE FF 04 6E 00 61 00 6D 00 65 00,一?2个字节?br /><br />然后我发玎ͼansi版本的可以打开unicode版本的文Ӟunicode版本的也可以打开ansi版本的文件?br /><br />Z么?我觉得关键在于CStringQ我觉得CString功能比较强大?br />CString的序列化函数<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> CString serialization code<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> String format:<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      UNICODE strings are always prefixed by 0xff, 0xfffe<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      if < 0xff chars: len:BYTE, TCHAR chars<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      if >= 0xff characters: 0xff, len:WORD, TCHAR chars<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">      if >= 0xfffe characters: 0xff, 0xffff, len:DWORD, TCHARs</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><br />CArchive</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> AFXAPI </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">(CArchive</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> ar, </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> CString</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">)<br />{<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> special signature to recognize unicode strings</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">#ifdef _UNICODE<br />    ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #000000">0xff</span><span style="COLOR: #000000">;<br />    ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (WORD)</span><span style="COLOR: #000000">0xfffe</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000"><br /><br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-></span><span style="COLOR: #000000">nDataLength </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">)<br />    {<br />        ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-></span><span style="COLOR: #000000">nDataLength;<br />    }<br />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-></span><span style="COLOR: #000000">nDataLength </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0xfffe</span><span style="COLOR: #000000">)<br />    {<br />        ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #000000">0xff</span><span style="COLOR: #000000">;<br />        ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (WORD)</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-></span><span style="COLOR: #000000">nDataLength;<br />    }<br />    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br />    {<br />        ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (BYTE)</span><span style="COLOR: #000000">0xff</span><span style="COLOR: #000000">;<br />        ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (WORD)</span><span style="COLOR: #000000">0xffff</span><span style="COLOR: #000000">;<br />        ar </span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000"> (DWORD)</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-></span><span style="COLOR: #000000">nDataLength;<br />    }<br />    ar.Write(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.m_pchData, </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetData()</span><span style="COLOR: #000000">-></span><span style="COLOR: #000000">nDataLength</span><span style="COLOR: #000000">*</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000">(TCHAR));<br />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ar;<br />}<br /></span></div></font>它对unicode做了特别的支?br />特别是当它在d列化q程的时?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font face="Courier New"><span style="COLOR: #000000">CArchive</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> AFXAPI </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">(CArchive</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> ar, CString</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />{<br />#ifdef _UNICODE<br />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nConvert </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> if we get ANSI, convert</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">#else</font></span><span style="COLOR: #000000"><br /><font face="Courier New">    </font></span><font face="Courier New"><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nConvert </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> if we get UNICODE, convert</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">#endif</font></span><span style="COLOR: #000000"><br /><br /><font face="Courier New">    UINT nNewLen </font></span><span style="COLOR: #000000"><font face="Courier New">=</font></span><font face="Courier New"><span style="COLOR: #000000"> _AfxReadStringLength(ar);<br />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nNewLen </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> (UINT)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />    {<br />        nConvert </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span></font><font face="Courier New"><span style="COLOR: #000000"> nConvert;<br />        nNewLen </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> _AfxReadStringLength(ar);<br />        ASSERT(nNewLen </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    }<br /><br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> set length of string to new length</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    UINT nByteLen </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> nNewLen;<br />#ifdef _UNICODE<br />    </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetBufferSetLength((</span><span style="COLOR: #0000ff">int</span></font><font face="Courier New"><span style="COLOR: #000000">)nNewLen);<br />    nByteLen </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> nByteLen </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> nConvert);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> bytes to read</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #0000ff"><font face="Courier New">#else</font></span><span style="COLOR: #000000"><br /><font face="Courier New">    nByteLen </font></span><font face="Courier New"><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> nByteLen </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> nConvert;    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> bytes to read</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nNewLen </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />        </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetBufferSetLength(</span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">);<br />    </span><span style="COLOR: #0000ff">else</span></font><span style="COLOR: #000000"><br /><font face="Courier New">        </font></span><font face="Courier New"><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.GetBufferSetLength((</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">)nByteLen</span><span style="COLOR: #000000">+</span></font><font face="Courier New"><span style="COLOR: #000000">nConvert);<br /></span><span style="COLOR: #0000ff">#endif</span></font><span style="COLOR: #000000"><br /><br /><font face="Courier New">    </font></span><font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> read in the characters</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nNewLen </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />    {<br />        ASSERT(nByteLen </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">);<br /><br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> read new data</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (ar.Read(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.m_pchData, nByteLen) </span><span style="COLOR: #000000">!=</span></font><font face="Courier New"><span style="COLOR: #000000"> nByteLen)<br />            AfxThrowArchiveException(CArchiveException::endOfFile);<br /><br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> convert the data if as necessary</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (nConvert </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">)<br />        {<br />#ifdef _UNICODE<br />            CStringData</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pOldData </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.GetData();<br />            LPSTR lpsz </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (LPSTR)</span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.m_pchData;<br /></span><span style="COLOR: #0000ff">#else</span></font><span style="COLOR: #000000"><br /><font face="Courier New">            CStringData</font></span><font face="Courier New"><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pOldData </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.GetData();<br />            LPWSTR lpsz </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (LPWSTR)</span><span style="COLOR: #0000ff">string</span></font><font face="Courier New"><span style="COLOR: #000000">.m_pchData;<br /></span><span style="COLOR: #0000ff">#endif</span></font><span style="COLOR: #000000"><br /><font face="Courier New">            lpsz[nNewLen] </font></span><font face="Courier New"><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> must be NUL terminated</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.Init();   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> don't delete the old data</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> lpsz;   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> convert with operator=(LPWCSTR)</span></font><span style="COLOR: #008000"><br /></span><font face="Courier New"><span style="COLOR: #000000">            CString::FreeData(pOldData);<br />        }<br />    }<br />    </span><span style="COLOR: #0000ff">return</span></font><span style="COLOR: #000000"><font face="Courier New"> ar;<br />}<br /></font></span></div>也就是说Q不你保存的文件是不是unicodeQ都可以读进来,转换U当前unicode或者ansi版本<br /><br />不过回到文章的标题,q里只讲了用CString序列化的保存。如果是其他保存方式Q可以学着CString的做法,写函数把文gL能读q来?img src ="http://www.shnenglu.com/flyingxu/aggbug/8521.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/flyingxu/" target="_blank">flyingxu</a> 2006-06-13 23:53 <a href="http://www.shnenglu.com/flyingxu/archive/2006/06/13/8521.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFCE序中,自定义的字符串id范围是什么?http://www.shnenglu.com/flyingxu/archive/2006/06/13/8478.htmlflyingxuflyingxuMon, 12 Jun 2006 16:25:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/06/13/8478.htmlhttp://www.shnenglu.com/flyingxu/comments/8478.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/06/13/8478.html#Feedback0http://www.shnenglu.com/flyingxu/comments/commentRss/8478.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/8478.html今天同事问我?br />
我还真不知道Q但是我看了下AFXRES.RC 和AFXRES.H Q发现MFC用的ID都是0xE000以上的。所以,用户自己用的Q从0Q?gt;0xCFFFFQ不q不定。呵呵,查了一下,正确的可以见TN020:http://msdn2.microsoft.com/en-us/library/t2zechd4.aspx
By convention, the ID value of 0 is not used.

Windows implementation limitations restrict 
true resource IDs to be less than or equal to 0x7FFF.

MFC
's internal framework implementations reserve several ranges: 0xE000->0xEFFF and 0x7000->0x7FFF.

Several Windows system commands use the range of 
0xF000 -> 0xFFFF.

Control IDs of 
1->7 are reserved by IDOK, IDCANCEL, and so on.

The range of 
0x8000->0xFFFF for strings is reserved for menu prompts for commands.


但是在我的印象中Q重复的字符串id在编译的时候,׃出错的。但?a >http://support.microsoft.com/kb/q194299/上说Q实际上Q?strong>static link mfc才会在编译的时候发玎ͼ否则发现不了?br />
另外Q?a >http://www.vckbase.com/article/misc/0022.htm中说Q在一个rc文g中,可以同时有几U语a的资源,呵呵Q我发现我傻了,每次把不同语a的资源发在不同的rc中,搞得现在好几个rc文gQ每ơ拷贝切换烦的要?img src ="http://www.shnenglu.com/flyingxu/aggbug/8478.html" width = "1" height = "1" />

flyingxu 2006-06-13 00:25 发表评论
]]>
~译优化选项不匹配引L一个bughttp://www.shnenglu.com/flyingxu/archive/2006/06/02/8075.htmlflyingxuflyingxuFri, 02 Jun 2006 02:32:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/06/02/8075.htmlhttp://www.shnenglu.com/flyingxu/comments/8075.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/06/02/8075.html#Feedback0http://www.shnenglu.com/flyingxu/comments/commentRss/8075.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/8075.html今天遇到一个问题更奇?都是debug版本,但是exe和dll的optimizations讄不一?都会名的错误,出错行更搞笑,?br />m_ComboBox.AddString(_T("") )
怎么查也查不出问?把优化选项Ҏ(gu)一致问题就没有?搞不?img src ="http://www.shnenglu.com/flyingxu/aggbug/8075.html" width = "1" height = "1" />

flyingxu 2006-06-02 10:32 发表评论
]]>
错误提示"An unsupported operation was attempted"的原?/title><link>http://www.shnenglu.com/flyingxu/archive/2006/05/31/7963.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 31 May 2006 09:27:00 GMT</pubDate><guid>http://www.shnenglu.com/flyingxu/archive/2006/05/31/7963.html</guid><wfw:comment>http://www.shnenglu.com/flyingxu/comments/7963.html</wfw:comment><comments>http://www.shnenglu.com/flyingxu/archive/2006/05/31/7963.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/flyingxu/comments/commentRss/7963.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/flyingxu/services/trackbacks/7963.html</trackback:ping><description><![CDATA[~译好了,q行一个程?试图打开一个对话框?对话框出不来,反倒是出来一个错误提C?<br />"An unsupported operation was attempted"<br />搜了一?<a ><br />http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21023191.html</a>里面有回{?的确是那L,是resource id的问?<br /><br />错误原因:<br />开?l一个radio映射了一个变?<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"><font face="Courier New"> DDX_Radio(pDX, IDC_RADIO1, m_nFindType);</font></span></div>后来发现<u>IDC_RADIO1</u>q个id不好,改ؓ DDX_Radio(pDX, <u>IDC_RADIO_BIT,</u> m_nFindType);<br />~译当然不会出错,q行?出现异怺.如果在上面的代码上设个断?然后跟踪q去,看的非常清楚.<br /><br /><img src ="http://www.shnenglu.com/flyingxu/aggbug/7963.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-31 17:27 <a href="http://www.shnenglu.com/flyingxu/archive/2006/05/31/7963.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在OnPaint()使用两次CPaintDCQ关?:BeginPaint()/::EndPaint()http://www.shnenglu.com/flyingxu/archive/2006/05/22/7517.htmlflyingxuflyingxuMon, 22 May 2006 15:39:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/05/22/7517.htmlhttp://www.shnenglu.com/flyingxu/comments/7517.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/05/22/7517.html#Feedback3http://www.shnenglu.com/flyingxu/comments/commentRss/7517.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/7517.html默认的代码如下:
void CHideSplitterWnd::OnPaint() 
{
    CPaintDC dc(
this); //
 device context for painting
    
//
 TODO: Add your message handler code here
    
// Do not call CSplitterWnd::OnPaint() for painting messages

}
wizardd的代码居然有q样一行:// Do not call CSplitterWnd::OnPaint() for painting messagesQ后面有个猜?br />然后我l写我的函数Q?br />
void CHideSplitterWnd::OnPaint() 
{
    CPaintDC dc(
this); //
 device context for painting
    
    
// 调用基类Q先

    CSplitterWnd::OnPaint();
    
     //
利用dcM些别的东西,但是实际上,它们永远不会被画出来
   //除非不调用基cȝOnPaint()

    m_rectButton.DrawButton(&dc);
}
l果我添加的东西怎么也不会被d来,Z么会q样Q?br />

看了CSplitterWnd::OnPaint()的代码,发现它也用了一个CPaintDCQ而且也是个时变?br />
void CSplitterWnd::OnPaint()
{
    ASSERT_VALID(
this
);
    CPaintDC dc(
this);
而关键的地方在CPaintDC的ctor和dtor中了Q在CPaintDC的ctor中调用了
::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps)
而在CPaintDC的dtor中调用了
::EndPaint(m_hWnd, &m_ps);
而:BeginPaint是开始根据当前的cliprect来画QEndPaint则会清空当前的cliprect?br />

所以,前面调用基类的OnPaint的过E结束后Q当前的cliprect为NULLQ所以,W二个CPaintDC在视囄点什么时Qcliprect已经为NULLQ当然什么也M上去?Q)

如果我一定想再用CPaintDCȝ什么,怎么办?再次调用InvalidateRectQ得cliprect不ؓI?/font>
void CHideSplitterWnd::OnPaint() 
{
    //注意临时变量声明的顺序,因ؓBeginPaint/EndPaint是不支持嵌套?br />    //CPaintDC dc(
this); //
 device context for painting
    
    
// TODO: Add your message handler code here

    CSplitterWnd::OnPaint();
    
    //W二此调?br />    InvalidateRect(
&
m_rectButton,FALSE);
    CPaintDC dc(
this); // 在这里,device context for painting

    m_rectButton.DrawButton(&dc);
    
    
// Do not call CSplitterWnd::OnPaint() for painting messages

}
所以,我猜,所有用了CPaintDC的地方,MFC都会加一句:不要调用基类的函数啦?br />
呵呵Q不知道我讲清楚没有

flyingxu 2006-05-22 23:39 发表评论
]]>
把代码移植成UNICODEhttp://www.shnenglu.com/flyingxu/archive/2006/05/18/7356.htmlflyingxuflyingxuThu, 18 May 2006 08:09:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/05/18/7356.htmlhttp://www.shnenglu.com/flyingxu/comments/7356.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/05/18/7356.html#Feedback2http://www.shnenglu.com/flyingxu/comments/commentRss/7356.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/7356.html 动机 : 在没有装中文字体的机器上昄中文

如果不是unicode,某些中文字符会在不同?/span>codepage上出Cؕ?/span>;如果当前codepage为韩文时,某些中文字会变成韩文的样?/span>,奇?/span>.

Step1: define _UNICODE, undefine _MBCS

宏定?/span>UNICODE, _UNICODE定义两个也可?/span>,定义一个也可以,windows的头文g会保证两个都会被定义.

#ifdef _UNICODE
#ifndef UNICODE
#define  UNICODE  //  UNICODE is used by Windows headers

#endif
#endif

 
#ifdef UNICODE
#ifndef _UNICODE
#define  _UNICODE         //  _UNICODE is used by C-runtime/MFC headers
#endif
#endif

 

Step2: 更改变量cd

比如 char -> TCHAR

但是 ,q不是说所有的charcd都不能用?/span>.如果需要用,q且函数的参?/span>/q回g么的都不冲突,charcdq是可以用的.

Step3: 更改帔R字符串Ş?/span>

" abc " -> _T(" abc ")

因ؓ开始写E序时没有注?/span> ,造成q样的常量字W串形式非常?/span>,一个个改v来很?/span>,我写了个插?/span>,可以?/span> ?/span> abc ?/span> 选中后点一?/span> buttonp变成_T( ?/span> abc ?/span> ),有点?/span>,代码也非常的?/span>.

Step4: 替换某些函数

比如atoi -> _ttoi

在这里遇C个问?/span>,atof的替?/span>.

按照msdn, atof应该?/span>_ttof替换

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined

_tstof

atof

atof

_wtof

但是奇怪的?/span>,VC6里面不认?/span>_tstofq个函数,VC.net 2003可?/span>.

有两个解决的办法:

1)      因ؓatof只是替换为QҎ(gu),所以这里用WideCharToMultiByte转化一下之后再调用atof也是可行?/span>

2)      呵呵,?/span>strtod的替换函?/span>_tcstod,哈哈,当然参数要变一?我觉得这个方法不?不要被msdn限制M

Step5: 查一下调用其?/span> dll 的接口函?/span>

因ؓ目q用了另外一?/span>dll,其中有些接口需?/span>char*参数,q个时候就必须?/span>WideCharToMultiByte转换一下了.

VC里面的设|?
1) {把所有的~译error改完了之后一~译,除了个link错误,不过msdn有解?
If you are using Unicode and MFC, you will get an unresolved external on _WinMain@16 if you don’t create an entrypoint to wWinMainCRTStartup. Use the /ENTRY option or type this value in the Project Settings dialog box. (To find this option in the development environment, click Settings on the Project menu, then click the Link tab, and click Output in the Category box.)

2)l于~译成功?调试的时候却发现CString的g能在QuickWatchH口中显CZ
tools->option->
in the debug tab u can find a check box Labeled "Display unicode strings"
Check it.

问题 : 直接?/span> ANSI ?/span> dll 中的 CString

在?/span>dll的时?/span>,需要直接?/span>dll中的一个变?/span>,?/span>CStringcd,因ؓq个dllq没有改?/span>unicode,所以在直接使用其变量时有点问题,使得g?/span>.(是不是这个原因还没有完全验证,应该是的)

到这?/span> , 宣布ULp| !

/*补充Q?br />l果是失败,但是基本UL代码的所有步骤都有了。而且Q也指出了如果需要调用的dll不是unicodeQ每ơ调?传递参数时Q都要{换,很烦?br />后来我把dll的代码也UL了下Q现在运行的很好Q韩文、中文都可以昄Q不你当前语言是什么?br />*/

q有一讲UL步骤?更全?适合更复杂的情况:
Cheat Sheet:Unicode-enabling Microsoft C/C++ Source Code (http://www.i18nguy.com/unicode/c-unicode.html)

 



flyingxu 2006-05-18 16:09 发表评论
]]>
量用代码来替代资源中的属?/title><link>http://www.shnenglu.com/flyingxu/archive/2006/05/17/7299.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Wed, 17 May 2006 06:17:00 GMT</pubDate><guid>http://www.shnenglu.com/flyingxu/archive/2006/05/17/7299.html</guid><wfw:comment>http://www.shnenglu.com/flyingxu/comments/7299.html</wfw:comment><comments>http://www.shnenglu.com/flyingxu/archive/2006/05/17/7299.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/flyingxu/comments/commentRss/7299.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/flyingxu/services/trackbacks/7299.html</trackback:ping><description><![CDATA[资源中的属?是指写MFCE序时VC IDE的resource~辑器中可以讑֮的各U属?比如<font face="Courier New">WS_EX_TRANSPARENT</font>或?font face="Courier New">LVS_REPORT</font>.<br />而这些属?都是可以用代码在E序初始化后加上ȝ,比如?font face="Courier New">OnInitDialog()</font> 或?font face="Courier New">OnCreate()</font>函数?<br /><br />从方便性来?肯定是在资源中设|这些属性更加方?但是..<br />我遇CU情?在我的程序中,有两个rc文g,分别是中文和英文,q个时?发生了在英文资源中讄了属性修正了一个bug但是在中文版的资源中忘记讄,bug依然存在.而如果是在在代码中加上类似的代码:<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font face="Courier New"><span style="COLOR: #000000">m_CrossRefTab.ModifyStyleEx(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,WS_EX_TRANSPARENT);</span></font></div>资源文g不用改变,而且修正了所有的问题.<br /><br />所?我觉?应该量用几行代码来替代在资源中的设定属?img src ="http://www.shnenglu.com/flyingxu/aggbug/7299.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/flyingxu/" target="_blank">flyingxu</a> 2006-05-17 14:17 <a href="http://www.shnenglu.com/flyingxu/archive/2006/05/17/7299.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>写了个很的软gQ快速切换鼠标左?右键http://www.shnenglu.com/flyingxu/archive/2006/05/11/6975.htmlflyingxuflyingxuThu, 11 May 2006 14:33:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/05/11/6975.htmlhttp://www.shnenglu.com/flyingxu/comments/6975.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/05/11/6975.html#Feedback2http://www.shnenglu.com/flyingxu/comments/commentRss/6975.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/6975.html鼠标用久了,Ҏ(gu)肩膀|所以有时候要换到左边Q然后需要的时候,再换到右辏V每ơ到控制面板里改q蛮烦的?/p>

现在好了Q自己写了个E序Q快速切换:当前是右手习惯就换到左手习惯Q反之换到右手习?br />E序很小Q只?行代码:

int  APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     
int
       nCmdShow)
{
     
//  TODO: Place code here.

    BOOL bSwapped  =  ::GetSystemMetrics(SM_SWAPBUTTON);
    ::SwapMouseButton(
!
bSwapped);
    
    
return   0
;
}
参考了q篇blogQ?a >用C#实现鼠标左右键自动切?/a>

~译后的E序下蝲

flyingxu 2006-05-11 22:33 发表评论
]]>
对MFC8.1的白日梦http://www.shnenglu.com/flyingxu/archive/2006/04/09/5208.htmlflyingxuflyingxuSun, 09 Apr 2006 13:50:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/04/09/5208.htmlhttp://www.shnenglu.com/flyingxu/comments/5208.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/04/09/5208.html#Feedback2http://www.shnenglu.com/flyingxu/comments/commentRss/5208.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/5208.html那么mfc8.1中,能不能多些这Ll构吧?把当前比较流行的设计模式Q都做成现成的类Q放在mfc?br />
呵呵Q那个时候,我估计没有h再说mfc设计的很烂了吧?

不过很奇?开源社区那么多人在用java c#讨论设计模式,MFC领域的却很少,真是奇?img src ="http://www.shnenglu.com/flyingxu/aggbug/5208.html" width = "1" height = "1" />

flyingxu 2006-04-09 21:50 发表评论
]]>
Z - Order的初始顺?Q?草稿http://www.shnenglu.com/flyingxu/archive/2006/04/05/5049.htmlflyingxuflyingxuWed, 05 Apr 2006 14:13:00 GMThttp://www.shnenglu.com/flyingxu/archive/2006/04/05/5049.htmlhttp://www.shnenglu.com/flyingxu/comments/5049.htmlhttp://www.shnenglu.com/flyingxu/archive/2006/04/05/5049.html#Feedback0http://www.shnenglu.com/flyingxu/comments/commentRss/5049.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/5049.html
zQorder的初始顺序就是窗口创建的先后序

对于子窗口,z-order于tab 序的关p?img src ="http://www.shnenglu.com/flyingxu/aggbug/5049.html" width = "1" height = "1" />

flyingxu 2006-04-05 22:13 发表评论
]]>
CString的另一个问?关于GetBuffer/ReleaseBuffer的几个错误例?/title><link>http://www.shnenglu.com/flyingxu/archive/2006/03/21/4430.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Tue, 21 Mar 2006 09:51:00 GMT</pubDate><guid>http://www.shnenglu.com/flyingxu/archive/2006/03/21/4430.html</guid><wfw:comment>http://www.shnenglu.com/flyingxu/comments/4430.html</wfw:comment><comments>http://www.shnenglu.com/flyingxu/archive/2006/03/21/4430.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.shnenglu.com/flyingxu/comments/commentRss/4430.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/flyingxu/services/trackbacks/4430.html</trackback:ping><description><![CDATA[关于GetBuffer/ReleaseBuffer,|上比较行的一U说法是:如果你要直接修改CString的内部数?p调用GetBuffer/ReleaseBuffer.我也同意q样的表q?<br /><br />下面是几个例?主要是错误的例子,来加q?<br />1<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><font face="Courier New"><span style="COLOR: #000000">CString strTest </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">123</span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> p </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> strTest.GetBuffer(</span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">);<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span></font><span style="COLOR: #000000"><font face="Courier New"> atoi(p);<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />strTest.ReleaseBuffer();</font></span></div>q种用法当然没有?但是我认里的GetBuffer/ReleaseBuffer是没有必要的,Z么呢?因ؓ<br /><font face="Courier New">int __cdecl atoi(const char *)</font> 的参数是const char*,CString的内部数据肯定不会被修改?<br />所以上面的代码可以直接写成<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><font face="Courier New"><span style="COLOR: #000000">CString strTest </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">123</span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> atoi((LPCTSTR)strTest);</span></font></div>Z说一下GetBuffer的参数问?|上的例子中,很多都是GetBuffer(5) GetBuffer(10)q样的常?实际中的E序不可能是q么Ҏ(gu)事先知道?所以也有了strTest.GetBuffer(strTest.GetLength() )的写?其实,GetBuffer(0)可以了.可以由GetBuffer的源码得到验?<br /><br />2<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">   <font face="Courier New"> CString strTest </font></span><font face="Courier New"><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">123 45</span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">some other code</span></font><span style="COLOR: #008000"><br /><font face="Courier New"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></font></span><font face="Courier New"><span style="COLOR: #000000">    CString strTest2 </span><span style="COLOR: #000000">=</span></font><font face="Courier New"><span style="COLOR: #000000"> strTest;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> seps[] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pToken </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">char* pStr = strTest2.GetBuffer(0);</span></font><span style="COLOR: #008000"><br /><font face="Courier New"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></font></span><font face="Courier New"><span style="COLOR: #000000">    pToken </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> strtok((</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span></font><font face="Courier New"><span style="COLOR: #000000">)(LPCTSTR)strTest2, seps);<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><font face="Courier New"><span style="COLOR: #000000">    //pToken </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> strtok(pStr</span></font><font face="Courier New"><span style="COLOR: #000000">, seps);</span></font><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span></font><font face="Courier New"><span style="COLOR: #000000">(pToken)<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />        pToken </span><span style="COLOR: #000000">=</span></font><span style="COLOR: #000000"><font face="Courier New"> strtok(NULL, seps);<br /></font><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />        <font face="Courier New"> //strTest2.ReleaseBuffer(0);</font></span></div>q行上面的代?可以看到strTest的g变了,呵呵,q就是程序中一些关与CString的奇怪问题的h.如果用注释中的GetBuffer/ReleaseBufferҎ(gu),׃炚w题也没有?<br />同样,对于ReleaseBuffer的参?~省的是-1,但是我不.因ؓ-1表示使用当前?0l束W位|来定新的长度.而上面的例子?strtok是会重新讄00l束W的,所?安全的做?是把这个CString的长度设?,ReleaseBuffer(0),反正它的内容已经变了,也没有h要用?<br />说明一?GetBuffer/ReleaseBufferҎ(gu)只能保证strTest不变,strTest2q是会变?所?对于一个成员变?比如m_strTest2调用ReleaseBuffer要多一个心?局部变量就不用惌么多?<br />那么怎么从最开始就意识到程序写错了?上面代码?font face="Courier New">(<span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">)(LPCTSTR)是很危险?把constL?否则strtok是编译不q的,也从一个侧面说明了const的重要?</span></font><br /><img src ="http://www.shnenglu.com/flyingxu/aggbug/4430.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/flyingxu/" target="_blank">flyingxu</a> 2006-03-21 17:51 <a href="http://www.shnenglu.com/flyingxu/archive/2006/03/21/4430.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于CString的两个问?/title><link>http://www.shnenglu.com/flyingxu/archive/2006/03/02/3631.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Thu, 02 Mar 2006 01:29:00 GMT</pubDate><guid>http://www.shnenglu.com/flyingxu/archive/2006/03/02/3631.html</guid><wfw:comment>http://www.shnenglu.com/flyingxu/comments/3631.html</wfw:comment><comments>http://www.shnenglu.com/flyingxu/archive/2006/03/02/3631.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.shnenglu.com/flyingxu/comments/commentRss/3631.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/flyingxu/services/trackbacks/3631.html</trackback:ping><description><![CDATA[<P><STRONG>关于CString的两个问?BR></STRONG><FONT size=2>?/FONT><A class=postTitle2 id=viewpost1_TitleUrl ><FONT size=2>CString,string,char*的综合比?一)</FONT></A> <BR><BR>1 CString的基c?BR>在《比较》一文中Q写刎ͼ<BR>“CStringQtypedef CStringT<TCHAR, StrTraitMFC<TCHAR>> CStringQؓVisual C++中最常用的字W串c,l承自CSimpleStringTc,主要应用在MFC和ATL~程中,主要数据cd有char(应用于ANSI)Qwchar_t(unicode)QTCHAR(ANSI与unicode均可)Q?BR>我第一感觉是文章写错了,因ؓ我看qCString的源码的啊:<BR></P> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff"><STRONG>struct</STRONG></SPAN><STRONG><SPAN style="COLOR: #000000"> CStringData<BR><IMG id=Codehighlighter1_19_292_Open_Image onclick="this.style.display='none'; Codehighlighter1_19_292_Open_Text.style.display='none'; Codehighlighter1_19_292_Closed_Image.style.display='inline'; Codehighlighter1_19_292_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_19_292_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_19_292_Closed_Text.style.display='none'; Codehighlighter1_19_292_Open_Image.style.display='inline'; Codehighlighter1_19_292_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_19_292_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.shnenglu.com/images/dot.gif"></SPAN></STRONG><SPAN id=Codehighlighter1_19_292_Open_Text><STRONG><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">long</SPAN><SPAN style="COLOR: #000000"> nRefs;             </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> reference count</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> nDataLength;        </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> length of data (including terminator)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> nAllocLength;       </SPAN><SPAN style="COLOR: #008000">//</SPAN></STRONG><STRONG><SPAN style="COLOR: #008000"> length of allocation<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> TCHAR data[nAllocLength]</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><SPAN style="COLOR: #000000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    TCHAR</STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000"> data()           </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> TCHAR* to managed data</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG id=Codehighlighter1_263_290_Open_Image onclick="this.style.display='none'; Codehighlighter1_263_290_Open_Text.style.display='none'; Codehighlighter1_263_290_Closed_Image.style.display='inline'; Codehighlighter1_263_290_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_263_290_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_263_290_Closed_Text.style.display='none'; Codehighlighter1_263_290_Open_Image.style.display='inline'; Codehighlighter1_263_290_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">        </SPAN><SPAN id=Codehighlighter1_263_290_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.shnenglu.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_263_290_Open_Text><SPAN style="COLOR: #000000">{ </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> (TCHAR</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">)(</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">); }</SPAN></SPAN></STRONG><SPAN style="COLOR: #000000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</STRONG></SPAN></SPAN><STRONG><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">class</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000"> CString<BR><IMG id=Codehighlighter1_310_934_Open_Image onclick="this.style.display='none'; Codehighlighter1_310_934_Open_Text.style.display='none'; Codehighlighter1_310_934_Closed_Image.style.display='inline'; Codehighlighter1_310_934_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_310_934_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_310_934_Closed_Text.style.display='none'; Codehighlighter1_310_934_Open_Image.style.display='inline'; Codehighlighter1_310_934_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_310_934_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.shnenglu.com/images/dot.gif"></SPAN></STRONG><SPAN id=Codehighlighter1_310_934_Open_Text><STRONG><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">:<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></STRONG><STRONG><SPAN style="COLOR: #008000"> Constructors<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> constructs empty CString</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString();<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> copy constructor</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString(</SPAN><SPAN style="COLOR: #0000ff">const</SPAN><SPAN style="COLOR: #000000"> CString</SPAN><SPAN style="COLOR: #000000">&</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000"> stringSrc);<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> from a single character</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString(TCHAR ch, </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> nRepeat </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">1</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> from an ANSI string (converts to TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString(LPCSTR lpsz);<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> from a UNICODE string (converts to TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString(LPCWSTR lpsz);<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> subset of characters from an ANSI string (converts to TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString(LPCSTR lpch, </SPAN><SPAN style="COLOR: #0000ff">int</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000"> nLength);<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> subset of characters from a UNICODE string (converts to TCHAR)</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString(LPCWSTR lpch, </SPAN><SPAN style="COLOR: #0000ff">int</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000"> nLength);<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> from unsigned characters</SPAN></STRONG><SPAN style="COLOR: #008000"><BR><STRONG><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></STRONG></SPAN><STRONG><SPAN style="COLOR: #000000">    CString(</SPAN><SPAN style="COLOR: #0000ff">const</SPAN><SPAN style="COLOR: #000000"> unsigned </SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">*</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000"> psz);<BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> Attributes & Operations</SPAN></STRONG></DIV> <P></SPAN><STRONG>但是看文章的样子Q也不像是粗制滥造的Q心里很是疑惑?BR>后来再打开VC7的源码看Q果Ӟ<BR></STRONG></P> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><STRONG><SPAN style="COLOR: #000000">typedef ATL::CStringT</SPAN><SPAN style="COLOR: #000000"><</SPAN><SPAN style="COLOR: #000000"> TCHAR, StrTraitMFC</SPAN><SPAN style="COLOR: #000000"><</SPAN><SPAN style="COLOR: #000000"> TCHAR </SPAN><SPAN style="COLOR: #000000">></SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">></SPAN></STRONG><SPAN style="COLOR: #000000"><STRONG> CString;<BR></STRONG></SPAN></DIV> <P><STRONG>看来微Y在不知不觉中做了q么大的变化?BR><BR>2 <BR>“string是方便的Q可以从几乎所有的字符串构造而来Q包括CString和char*Q?nbsp;<BR> CStringơ之Q可以从基本的一些字W串变量构造而来Q包括char*{; ?BR>的确Q如下的代码是可以编译的Q?BR></STRONG></P> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><STRONG><SPAN style="COLOR: #000000">CString strTest </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">test</SPAN><SPAN style="COLOR: #000000">"</SPAN></STRONG><STRONG><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000"> sTest(strTest);</SPAN></STRONG></DIV> <P><STRONG>但是q是表明string比CString方便吗?<BR>实际上,在string sTest(strTest);中有一个函数被调用Q就是:<BR></STRONG></P> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><STRONG><SPAN style="COLOR: #000000">_AFX_INLINE CString::</SPAN><SPAN style="COLOR: #0000ff">operator</SPAN><SPAN style="COLOR: #000000"> LPCTSTR() </SPAN><SPAN style="COLOR: #0000ff">const</SPAN></STRONG><SPAN style="COLOR: #000000"><BR><STRONG>    { </STRONG></SPAN><STRONG><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> m_pchData; }</SPAN></STRONG></DIV> <P><STRONG>然后才是string构造生成,q能说是string比CString方便吗?应该说是CString比string方便才好?BR>虽然可以?BR></STRONG></P> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000"><STRONG>CString strTest(sTest.c_str() );</STRONG></SPAN></DIV> <P><STRONG>来初始化CStringQ但是CString没有参数为string的构造函敎ͼ也是一个小的遗憾Q毕竟string是c++标准库的一部分了?/STRONG></P><img src ="http://www.shnenglu.com/flyingxu/aggbug/3631.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/flyingxu/" target="_blank">flyingxu</a> 2006-03-02 09:29 <a href="http://www.shnenglu.com/flyingxu/archive/2006/03/02/3631.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC wizard出错: Parsing error : Expected "*/" 的原?/title><link>http://www.shnenglu.com/flyingxu/archive/2006/02/17/3306.html</link><dc:creator>flyingxu</dc:creator><author>flyingxu</author><pubDate>Fri, 17 Feb 2006 05:16:00 GMT</pubDate><guid>http://www.shnenglu.com/flyingxu/archive/2006/02/17/3306.html</guid><wfw:comment>http://www.shnenglu.com/flyingxu/comments/3306.html</wfw:comment><comments>http://www.shnenglu.com/flyingxu/archive/2006/02/17/3306.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/flyingxu/comments/commentRss/3306.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/flyingxu/services/trackbacks/3306.html</trackback:ping><description><![CDATA[当我在运行wizard,选到某一个类?遇到了这个错误提C?<BR>Parsing error : Expected "*/"<BR>出错的代码如?BR>  <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">BEGIN_EVENTSINK_MAP(CMonitorView, CFormView)<BR>    //{{AFX_EVENTSINK_MAP(CMonitorView)<BR>    ON_EVENT(CMonitorView, IDC_REGVALUE,       </SPAN><SPAN style="COLOR: #000000">72</SPAN><SPAN style="COLOR: #000000">    </SPAN><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000"> Leave Cell </SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000">,     OnLeaveCellRV, VTS_NONE)    <BR>    //}}AFX_EVENTSINK_MAP<BR>END_EVENTSINK_MAP()</SPAN></DIV>但是我看来看L有问?<BR><BR>后来扑ֈ最初的代码一Ҏ(gu),原来/* Leave<FONT style="BACKGROUND-COLOR: #ff1493" color=#000000> </FONT>Cell */中间有个I格, 是的wizard解析出错,LI格好??BR><img src ="http://www.shnenglu.com/flyingxu/aggbug/3306.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/flyingxu/" target="_blank">flyingxu</a> 2006-02-17 13:16 <a href="http://www.shnenglu.com/flyingxu/archive/2006/02/17/3306.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用CString作ؓKey使用CMaphttp://www.shnenglu.com/flyingxu/archive/2005/12/27/4274.htmlflyingxuflyingxuMon, 26 Dec 2005 23:17:00 GMThttp://www.shnenglu.com/flyingxu/archive/2005/12/27/4274.htmlhttp://www.shnenglu.com/flyingxu/comments/4274.htmlhttp://www.shnenglu.com/flyingxu/archive/2005/12/27/4274.html#Feedback5http://www.shnenglu.com/flyingxu/comments/commentRss/4274.htmlhttp://www.shnenglu.com/flyingxu/services/trackbacks/4274.html
文章来源:http://blog.csdn.net/flyingxu/archive/2005/12/26/562852.aspx

遇到好几个h说CMap在用CString做keycd时有问题Q说用int和DWORD可以,用CString׃行。因此很多h推荐使用MFC中的CMapStringToPtr之类?/p>

看下面的代码Q?br />//.h
    CMap<CString, LPCTSTR, int, int> typeMap;
//.cpp
    typeMap.SetAt(_T("ONE"),1);
    typeMap.SetAt(_T("TWO"),2);

    int nValue = 0;
    BOOL ret = typeMap.Lookup(_T("ONE"), nValue);
    ret = typeMap.Lookup(_T("THREE"), nValue);
    ret = typeMap.Lookup(_T("TWO"), nValue);
我的代码q行的很好,我觉得关键是ARG_KEY要选LPCTSTR



flyingxu 2005-12-27 07:17 发表评论
]]>
뾫ƷþѼ| 9999Ʒŷþþþþ| ޾Ʒþþþþ| ƷþþþĻձ| 91Ըߺþþþ| 99þþƷѿһ| Ʒ99þѹۿ| þëƬѿһ| ھƷþۺ88| 99þۺϹƷ| þþþAVרJN| þ߿ۿƷ㽶| ĻƷþþþ| þۺϾɫۺŷݺ| һһþaaۺϾƷ| þˬˬAVƬ| þþƷƵ| þþƷAV鶹վ| ij뾫Ʒþþò | ҹѸþӰԺ| þù޾ƷӰԺ| 91þþƷһ| ݺۺϾþۺ88| þˬ˾ƷƵ| 99þùۺϾƷˮ| ŷ޷avþò| ۺϾþһ | һһþaþۺϾƷ| ƷþþþþþþþĻ| þþƷþ˼˼| ӰȷŮAV³ɫԴþ| þþþþϸ| ľƷþþþùַ| Ʒþ| ձþ| Ʒһþ㽶߿| þþƷһ99| ŮƷþþ2020| þ99þ99Ʒӿ| Ʒþþþþ| þþƷˬӰ|