MFC Tips

//z 2014-04-25 11:47:44 L.250'43936 BG57IV3@BYH T1068848856.K.F253293061
//z 2014-04-25 13:14:40 L.250'38720 T594586945 .K[T301,L4278,R198,V5542]
strlen        wcslen        _tcslen 

strchr        wcschr        _tcschr 
strrchr       wcsrchr       _tcsrchr 
strcpy        wcscpy        _tcscpy 
strcat        wcscat        _tcscat 
strcmp        wcscmp        _tcscmp 
strncmp       wcsncmp       _tcsncmp 
stricmp       wcsicmp       _tcsicmp 
strnicmp      wcsnicmp      _tcsnicmp 
_strtime      _wstrtime     _tstrtime 
_strdate      _wstrtime     _tstrdate     

printf        wprintf       _tprintf 
scanf         wscanf        _tscanf 
fopen         _wfopen       _tfopen 
fprintf       fwprintf      _ftprintf 
fscanf        fwscanf       _ftscanf 
sprintf       swprintf      _stprintf 
sscanf        swscanf       _stscanf 
vprintf       vwprintf      _vtprintf 
vfprintf      vfwprintf     _vftprintf 
vsprintf      vswprintf     _vstprintf 
_snprintf     _snwprintf    _sntprintf 
vsprintf      vswprintf     _vstprintf 

atoi          _wtoi         _ttoi 
_itoa         _itow         _itot 
atol          _wtol         _ttol 
_ltot         _ltow         _ltot 
atof          _wtof         _ttof

//z 2014-04-18 10:36:13 BG57IV3@XCL T1923392918.K.F253293061 [T235,L2896,R146,V4562]
How to get rid of "Untitled - MyApp" in MFC
去除 mfc 窗口、window、view上的 无标题1. 在任何地方执行 (AfxGetMainWnd())->SetWindowText("MyApp");2.OnUpdateFrameTitle(BOOLNada)
  1. voidCMainFrame::OnUpdateFrameTitle(BOOLNada)
  2. {
  3. // get app name from string table resource
  4. //----------------------------------------
  5. CString csAppName;
  6. csAppName.Format(AFX_IDS_APP_TITLE);
  7.  
  8. // Set caption of main frame window
  9. //---------------------------------
  10. SetWindowText(csAppName);
  11. }

3. 在 CMainFrame 中设置
  1. BOOLCMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  2. {
  3. cs.style&=~(LONG) FWS_ADDTOTITLE;
  4. returnCFrameWnd::PreCreateWindow(cs);
  5. }


//z 2014-04-01 17:47:41 BG57IV3@XCL T264464888 .K.F253293061 [T121,L1504,R68,V2251]
1. MFC ASSERT 详解
在开发过程中我们可以假设只要程序运行正确,某一条件肯定成立。若不成立,那么我们可以断言程序肯定出错。在这种情况下我们可要利用ASSERT来设定断 言。ASSERT宏的参数是一个逻辑表达式,在程序运行过程中,若该逻辑表达式为真,则不会发生任何动作;若此表达式为假,则系统弹出一个对话框警告你, 并停止程序的执行。同时要求你作出选择:取消、忽略和重试。若你选择取消,则系统将停止程序的运行;若你选择忽略,则系统将忽略该错误,并继续执行程序; 若你选择重试,则系统将重新计算该表达式,并激活调试器。同TRACE宏一样,ASSERT宏只对Debug版本的工程产生作用,在Release 版本的工程中,ASSERT宏将被忽略。
     下面的示例显示如何使用ASSERT检查函数的返回值:
      int x = SomeFunc(y);
      ASSERT( x >= 0);   // 如果x为负,则断言失败。
     可将断言用于:
     (1)可以使用断言语句捕捉逻辑错误。可以在程序逻辑必须为真的条件上设置断言。除非发生逻辑错误,否则断言对程序无任何影响。
     (2)可以使用断言语句检查操作的结果。断言对于快速直观地检查不明显的操作结果最有价值。
     (3)可以使用断言在代码中已处理了错误的点处测试错误类型。

2. const+map引起error C2678的解决办法
 写了一个小程序,在一个const成员函数中访问了一个map成员,如下所示:

 void CPlayerScore::GetScore(GAMERESULT res, RBScore & rbscore)const 

{
      rbscore = m_scoreTable[res];
}

m_scoreTable是一个map成员,结果编译时报错。

error C2678: 二进制“[” : 没有找到接受“const std::map<_Kty,_Ty>”类型的左操作数的运算符(或没有可接受的转换)

解决办法有两个:

1、是去掉函数的const属性,但是这样就改变设计意义了

2、在声明m_scoreTable时加上mutable限定符,如下所示

mutable map<GAMERESULT, RBScore> m_scoreTable;

第2个办法是网友benbear告诉我的,又学到了一招,呵呵

3、不改变原来的声明

代码改为

     map<GAMERESULT, RBScore>:: const_ iterator it=m_score.find(res);

    assert(it !=m_score.end();

     rbscore = it->second;



@IS2120#CNBLOGS.T2169364049[T1,L65,R1,V259]:备忘
$ € ₤ ₭ ₪ ₩ ₮ ₦ ₱ ฿ ₡ ₫ ﷼ ¥ ﷼ ₫ ₡ ฿ ₱ ₦ ₮ ₩ ₪ ₭ ₤ € $
原文地址:https://www.cnblogs.com/IS2120/p/6745676.html