#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024] ;
va_list pArgList ;
// The va_start macro (defined in STDARG.H) is usually equivalent to:
// pArgList = (char *) &szFormat + sizeof (szFormat) ;
va_start (pArgList, szFormat) ;//pArgList指向第一个可变参数的前一个固定参数
// The last argument to wvsprintf points to the arguments
_vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList) ;//联想sprintf,将pArgList指向的参数赋值到szFormat中,然后一起保存在szBuffer
// The va_end macro just zeroes out pArgList for no good reason
va_end (pArgList) ;//清空pArgList
return MessageBox (NULL, szBuffer, szCaption, 0) ;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int cxScreen, cyScreen ;
cxScreen = GetSystemMetrics (SM_CXSCREEN) ;
cyScreen = GetSystemMetrics (SM_CYSCREEN) ;
MessageBoxPrintf (TEXT ("ScrnSize"),
TEXT ("The screen is %i pixels wide by %i pixels high."),
cxScreen, cyScreen) ;
return 0 ;
}可变参数(va_list)
最新推荐文章于 2025-01-15 19:58:43 发布
本文介绍了一个使用C语言在Windows环境下获取并显示屏幕尺寸的方法。通过调用GetSystemMetrics函数获得屏幕宽度和高度,并利用MessageBox显示这些信息。文章还展示了如何使用可变参数列表来格式化输出。
310

被折叠的 条评论
为什么被折叠?



