共用方式為


AfxFormatString1

Loads the specified string resource and substitutes the characters "%1" for the string pointed to by lpsz1.

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

Parameters

  • rString
    A reference to a CString object that will contain the resultant string after the substitution is performed.

  • nIDS
    The resource ID of the template string on which the substitution will be performed.

  • lpsz1
    A string that will replace the format characters "%1" in the template string.

Remarks

The newly formed string is stored in rString. For example, if the string in the string table is "File %1 not found", and lpsz1 is equal to "C:\MYFILE.TXT", then rString will contain the string "File C:\MYFILE.TXT not found". This function is useful for formatting strings sent to message boxes and other windows.

If the format characters "%1" appear in the string more than once, multiple substitutions will be made.

Example

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
}

Requirements

Header: afxwin.h

See Also

Concepts

MFC Macros and Globals

AfxFormatString2