3 回答
TA贡献1886条经验 获得超2个赞
自己写一个格式化MessageBox嘛:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int CDECL MessageBoxPrintf(TCHAR * szCaption, TCHAR * szFormat, ...)
{
va_list pArgList;
va_start(pArgList, szFormat);
TCHAR szBuffer[1024];
_vsntprintf_s(szBuffer, sizeof szBuffer / sizeof TCHAR, szFormat, pArgList);
va_end(pArgList);
return MessageBox(NULL, szBuffer, szCaption, MB_OK);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iShowCmd)
{
int year = 2007;
const TCHAR* greeting = "Hello!";
MessageBoxPrintf(TEXT("Message"), TEXT("%s This is year %d"), greeting, year);
}
或者使用wsprintf:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
TCHAR buffer[1024];
int year = 2007;
const TCHAR* month = TEXT("Apr.");
int day = 11;
wsprintf(buffer, TEXT("Today is: %d %s %d"), day, month, year);
MessageBox(NULL, buffer, TEXT("Data Report"), MB_OK | MB_ICONASTERISK);
}
- 3 回答
- 0 关注
- 392 浏览
添加回答
举报