顯示具有 MFC 標籤的文章。 顯示所有文章
顯示具有 MFC 標籤的文章。 顯示所有文章

2013年2月22日 星期五

如何解除VC的 C4996 warning

Visual studio 6 版以後的Compler 對於一些C 函式庫做安全改良(security enhancements),

如:
strcpy()  改良成 strcpy_s()

當你使用 strcyp(), 會產生下列 warning... (很煩...)

warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

消除的方法是:
  1.  加入define 
 
#define _CRT_SECURE_NO_WARNINGS

  若放在程式碼中,要注意放的位置,要放在所有include header之前。
 
  最簡單的方式是放置在preprocessor中( solution exploer右鍵/properies/ C/C++ / preprocessor )
  或是放在 stdafx.h中(if you have)。

2. 加入 編譯指令
 
#pragma warning( disable:4996 )
 
把上述指令放在 .C/.CPP 檔中,呼叫函示之前即可


Apendix:
微軟對於 eliminate deprecation warnings for the older, less secure functions 說明:
http://msdn.microsoft.com/zh-tw/library/8ef0s5kh.aspx

相關secure enhance function 說明:
http://msdn.microsoft.com/en-us/library/wd3wzwts(VS.80).aspx

2013年1月31日 星期四

MFC List Control 的使用

Using  MS. VS2010
This artical will show you step by step who to make a 2x2 list view on you MFC application.
The result like following fig:

Step1. From toolbox. select "List control" icon.
 

Step2.  Modify the property of List control
  in "Properties" page, Set "view" = Report
you will see below:
Step3. Add list control variable: Right click on control.
 
Step4. Write you own code for application


// Column Name index
#define COLUMN_NAME      (0)
#define COLUMN_VALUE     (1)

// Row index
#define ITEM_NetxFlag    (0)
#define ITEM_HostFlag    (1)
#define ITEM_HostCOSFlag (2)
#define ITEM_DevCOSFlag  (3)
#define MAX_ROW_INDEX    (4)

// Row Name array
const char ROW_NAME[MAX_ROW_INDEX][16] =
{
  "NetxFlag",
  "HostFlag",
  "HostCOSFlag",
  "DevCOSFlag"
};

// Initial list table.
this->m_infoList.InsertColumn( COLUMN_NAME,  "Name",  0, 80, 50 );
this->m_infoList.InsertColumn( COLUMN_VALUE, "Value", 0, 80, 50 );

for( int i = 0; i < MAX_ROW_INDEX; i++ )
{
  this->m_infoList.InsertItem(  i, ROW_NAME[i]   );     // Set List name.
  this->m_infoList.SetItemText( i, COLUMN_VALUE, "0" );  // Set List value.
}