原文章网址: http://www.codeproject.com/Tips/120013/Formatted-MessageBox-AfxMessageBox
void AfxMessageBoxFormatted(LPCTSTR pFormatString, ...)
{
va_list vl;
va_start(vl, pFormatString);
CString strFormat;
strFormat.FormatV(pFormatString, vl);
AfxMessageBox(strFormat);
}
void MessageBoxFormatted(HWND hWnd, LPCTSTR pCaption, LPCTSTR pFormatString, ...)
{
va_list vl;
va_start(vl, pFormatString);
TCHAR strFormat[1024];
_vstprintf(strFormat, pFormatString, vl);
::MessageBox(hWnd, strFormat, pCaption,MB_ICONINFORMATION);
}
使用示例:
int i = 100;
MessageBoxFormatted(NULL, TEXT(“Hello Kitty”), TEXT(“%d”), i);