MFCこまごました知識点


一、文字列及びデータ型
文字タイプの比較:
  • CString:動的TCHAR配列、カプセル化されたクラス;
  • LPCTSTR:定数TCHARポインタ、typedef const TCHAR*LPCTSTRとして定義され、Cはconst、Pはポインタ、Tは_Tマクロ
  • LPTSTR:TCHARポインタ、typedef TCHAR*LPTSTR
  • と定義
  • TCHAR:マクロ、wchar_t(Unitcode)またはchar
  • WHAR:マクロ、wchar_t
  • wchar_t:unicode符号化データ型
  • char:ASCII符号化文字
  • string:C++の文字列変数で、ヘッダファイルincludeを含む、一般的な方法は
  • である.
  • a)=,assign()/新しい値bを付与)swap()/2文字列の内容c)+=,append(),push_back(//末尾に文字dを追加)insert(//挿入文字e)erase(//削除文字f)clear(//すべての文字gを削除)replace(//置換文字h)+//直列文字i)=,!=,<,<=,>,>=,compare()/比較文字列j)size()、length()/戻り文字数k)max_size()/戻り文字の可能性最大個数l)empty()/文字列が空であるか否かを判断するcapacity()/戻り再割り当て前の文字容量n)reserve()/一定量のメモリを保持して一定数の文字oを収容する[],at(//アクセス単一文字p)>,getline()/streamから値qを読み出す)

  • CString回転TCHAR*
    1.強制型変換
    CString theString( "This is a test" );
    LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString; 

    2.cpy
    CString theString( "This is a test" );
    LPTSTR lpsz = new TCHAR[theString.GetLength()+1];
    _tcscpy(lpsz, theString); 

    3.GetBuffer
    CString s(_T("This is a test "));
    LPTSTR p = s.GetBuffer();
    //        p   
    if(p != NULL) *p = _T('\0');
    s.ReleaseBuffer(); 

    CStringとchar*変換
    1.wcstombs()の使用
    CString str("string");
    char pChar[100];
    wcstombs(pChar,str,100);

    2.wcstombs_を使用s()
    TCHAR*転送CString
    TCHAR szTchar[18] = L"TCHAR";   
    CString  str;   
    str.Format(_T("%s"),szTchar);  

    CStringはLPCTSTRと等価:
    CString str("cstring");
    LPCTSTR pcStr = str;

    WHAR*(wchar_t*)の変換
    1.wcscpy()の使用
    CString str("string");
    WCHAR pWchar[100];
    wcscpy(pWchar,str);
    2.wcspy_の使用s,前の関数のセキュリティバージョン
    CString str("string");
    WCHAR pWchar[100];
    wcscpy(pWchar,100,str);
    3.使用_tcspy()
    CString str("string");
    WCHAR pStr[100];
    _tcscpy(pStr,str);

    4.使用_tcspy_s
    CString str("string");
    WCHAR pStr[100];
    _tcscpy_s(pStr,100,str);

    strcpy処理ANSI符号化
    wcscpy処理Unicode
    _tcspy()はマクロです
    wcstombs()マルチバイトとシングルバイト変換を実現するために設計された
    CString回転int
    <span style="font-size:12px;">CString str = _T("123");
    int i = _ttoi(str);</span>

    int転送CString
    int i = 123;
    CString str ;
    str.Format(_T("%d"), i);

    DWORDとintの違い
    DWORDダブルワード符号なし
    int長さは機器関連
    int i=10; DWORD d=DWORD(i);

    その他:
    文字列_s関数
    例:strcpy_sはstrcpyとほぼ一致するが、自動的に境界検査を行う(0判定で終了).
    char*回転std::string
    const char *s="hello"; //*s        
    std::string str(s);
    char* data = ...;
    int size = ...;
    std::string myString(data,size);  //    ,    strlen

    std::string回転char*
    std::string my_string("testing!");
    const char* data = my_string.c_str(); //     my_string
    std::string my_string("testing!");
    char *cstr = new char[my_string.length() + 1];
    strcpy(cstr,my_string.c_str());
    //do stuff
    delete[] cstr;

    二、ニュース
  • SC_CLOSEクローズ
  • SC_MAXIMIZE最大化
  • SC_MINIMIZE

  • 三、指針
    1.関数を定義するとき、変数はコントロールで、ポインタを使用します.コントロールのメンバー関数を呼び出し、->を使用します.パラメータを渡して、アドレスを取ります&.
    // combobox  
    CString CSerialTestDlg::GetComboboxValue(CComboBox* cob){
    	CString result(_T(""));
    	int curSel;
    	curSel=cob->GetCurSel();
    	if(curSel>-1){
    		 cob->GetLBText(curSel,result);
    		 return result;
    	}
    	return _T("");
    }
    void*は、任意の他のタイプのポインタに強制的に変換できます.