次の方法で共有


AfxFormatString1

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

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

パラメーター

  • rString
    置換された後結果の文字列を含む CString のオブジェクトへの参照。

  • nIDS
    置換が実行されるテンプレート文字列のリソース id。

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

解説

新興の文字列は rStringに格納されます。たとえば、文字列テーブルの文字列が "Search" %1 場合、ファイル B " lpsz1 15 と同じです: \MYFILE.TXT は"、rString 文字列 "ファイルの C:\MYFILE.TXT が見つかりません: " 含まれています検索。この関数は、メッセージ ボックスなどのウィンドウに送信される文字列を書式設定するのに便利です。

ファイル形式文字 "%1 "が文字列で何度も表示される場合は、複数の置換されます。

使用例

void DisplayFileNotFoundMessage(LPCTSTR pszFileName)
{
   CString strMessage;

   // The IDS_FILENOTFOUND string resource contains "Error: File %1 not found"
   AfxFormatString1(strMessage, IDS_FILENOTFOUND, pszFileName);
   // In the previous call, substitute the actual file name for the
   // %1 placeholder
   AfxMessageBox(strMessage);  // Display the error message
}

必要条件

ヘッダー: afxwin.h

参照

関連項目

AfxFormatString2

概念

MFC マクロとグローバル