次の方法で共有


AfxFormatString2

lpsz1 が指す文字 "%1 "のすべてのインスタンスの文字列、文字 " nIDSによって識別されるテンプレート文字列リソースの" %2 のすべてのインスタンスの lpsz2 によって指される文字列を使用します。

void AfxFormatString2(
   CString& rString,
   UINT nIDS,
   LPCTSTR lpsz1,
   LPCTSTR lpsz2 
); 

パラメーター

  • rString
    置換された後結果の文字列を含む CString への参照。

  • nIDS
    置換が実行されるテンプレート文字列の文字列テーブルの ID。

  • lpsz1
    文字 "テンプレート ファイル形式の文字列の" %1 を置き換える文字列。

  • lpsz2
    文字 "テンプレート ファイル形式の文字列の" %2 を置き換える文字列。

解説

新興の文字列は rStringに格納されます。たとえば、文字列テーブルの文字列が "%2 "ディレクトリにあるファイルの場合、MYFILE.TXT %1 "" に lpsz1 点、および "C への lpsz2 点: \MYDIR は"、ディレクトリの C で、を rString 検索文字列 "MYFILE.TXT ファイルが含まれています: \MYDIR"

ファイル形式文字 "%1 "または "%2 "が文字列で何度も表示される場合は、複数の置換されます。これらは数順である必要があります。

使用例

void DisplayFileNotFoundMessage(LPCTSTR pszFileName, LPCTSTR pszDirectory)
{
   CString strMessage;

   // The IDS_FILENOTFOUND string resource contains "Error: File %1 not 
   // found in directory %2"
   AfxFormatString2(strMessage, IDS_FILENOTFOUND2, pszFileName, pszDirectory);
   // In the previous call, substitute the actual file and directory 
   // names into the message string
   AfxMessageBox(strMessage);  // Display the error message
}

必要条件

ヘッダー: afxwin.h

参照

関連項目

AfxFormatString1

概念

MFC マクロとグローバル