第二章(Unicode)之---格式化的消息框

来源:互联网 发布:中学生当街打母 知乎 编辑:程序博客网 时间:2024/04/28 07:22

下面例题取自2.3.5 格式化的消息框:(一下代码均自己实现过)

如何实现MessageBoxPrintf函数,该函数能够接收各种大量的参数并对他们进行格式化

#include <Windows.h>#include <tchar.h>#include <stdio.h>int CDECL MessageBoxPrintf(TCHAR * szCaption,TCHAR * szFormat,...){TCHAR szBuffer[1024];va_list pArgList;va_start(pArgList,szFormat);_vsntprintf(szBuffer,sizeof(szBuffer)/sizeof(TCHAR),szFormat,pArgList);va_end(pArgList);return MessageBox(NULL,szBuffer,szCaption,0);}int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow){//MessageBox(NULL,TEXT("heoll litong"),TEXT("hello message"),0);int cxScreen,cyScreen;cxScreen=GetSystemMetrics(SM_CXSCREEN);cyScreen=GetSystemMetrics(SM_CXSCREEN);MessageBoxPrintf(TEXT("ScrnSize"),TEXT("the scereen is %i pixels wide by %i pixels high"),cxScreen,cyScreen);return 0;}

这个程序以像素为单位显示刷屏显示器的宽度和高度,像素信息是从GetSystemMetrics函数获得


原创粉丝点击