Programming Windows程式开发设计指南->第二章 例子程序
2007-06-01 00:53
330 查看
/*_############################################################################
_##
_## Programming Windows程式开发设计指南->第二章 例子程序
_## Author: xwlee
_## Time: 2007.06.01
_## Chang'an University
_## Development condition: win2003 Server+VC6.0
_##
_## 程序2-1 SCRNSIZE
_## SCRNSIZE.C 文件
_## 程序2-1所示的SCRNSIZE程序展示了如何实作MessageBoxPrintf函数,
_## 该函数有许多参数并能像printf那样编排它们的格式。
_##
_##
_##
_## SCRNSIZE.C -- Displays screen size in a message box
_## (c) Charles Petzold, 1998
_##
_##########################################################################*/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
// 这是一个可变参数的函数
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024] ;
va_list pArgList ;
// 关于va_list,va_start,va_end 主要是定义可变参数使用的宏
// The va_start macro (defined in STDARG.H) is usually equivalent to:
// pArgList = (char *) &szFormat + sizeof (szFormat) ;
va_start (pArgList, szFormat) ; // 定位在第一个可变参数的地址
// The last argument to wvsprintf points to the arguments
_vsntprintf ( szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList) ;
// The va_end macro just zeroes out pArgList for no good reason
va_end (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) ;
MessageBoxPrintf ( TEXT ("长安大学,呵呵"),
TEXT ("当前屏幕的大小是: %i 像素宽, %i 像素高。"),
cxScreen, cyScreen) ;
return 0 ;
}
_##
_## Programming Windows程式开发设计指南->第二章 例子程序
_## Author: xwlee
_## Time: 2007.06.01
_## Chang'an University
_## Development condition: win2003 Server+VC6.0
_##
_## 程序2-1 SCRNSIZE
_## SCRNSIZE.C 文件
_## 程序2-1所示的SCRNSIZE程序展示了如何实作MessageBoxPrintf函数,
_## 该函数有许多参数并能像printf那样编排它们的格式。
_##
_##
_##
_## SCRNSIZE.C -- Displays screen size in a message box
_## (c) Charles Petzold, 1998
_##
_##########################################################################*/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
// 这是一个可变参数的函数
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024] ;
va_list pArgList ;
// 关于va_list,va_start,va_end 主要是定义可变参数使用的宏
// The va_start macro (defined in STDARG.H) is usually equivalent to:
// pArgList = (char *) &szFormat + sizeof (szFormat) ;
va_start (pArgList, szFormat) ; // 定位在第一个可变参数的地址
// The last argument to wvsprintf points to the arguments
_vsntprintf ( szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList) ;
// The va_end macro just zeroes out pArgList for no good reason
va_end (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) ;
MessageBoxPrintf ( TEXT ("长安大学,呵呵"),
TEXT ("当前屏幕的大小是: %i 像素宽, %i 像素高。"),
cxScreen, cyScreen) ;
return 0 ;
}
相关文章推荐
- struts2入门-第一个例子==》第一个struts2实例——HelloWorld==》Struts2.0搭建和简单实例==>写一个Steuts2的经典入门案例,做了一个登陆程序作为入门例子
- Programming Windows程式开发设计指南->第六章 例子程序3
- Programming Windows程式开发设计指南->第五章 例子程序2
- Programming Windows程式开发设计指南->第五章 例子程序5
- Programming Windows程式开发设计指南->第六章 例子程序4
- Programming Windows程式开发设计指南->第八章 例子程序1
- WPF程序设计指南第二章例子CircleTheRainbow效果
- Programming Windows程式开发设计指南->第一章 例子程序
- Programming Windows程式开发设计指南->第五章 例子程序3
- Programming Windows程式开发设计指南->第五章 例子程序6
- Programming Windows程式开发设计指南->第八章 例子程序2
- 编写高效的C#图像处理程序(3) Rgb=>Lab,图像缺陷检测的例子
- 编写高效的C#图像处理程序(3) Rgb=>Lab,图像缺陷检测的例子
- Programming Windows程式开发设计指南->第五章 例子程序7
- Programming Windows程式开发设计指南->第六章 例子程序1
- Programming Windows程式开发设计指南->第七章 例子程序1
- Programming Windows程式开发设计指南->第三章 例子程序
- Programming Windows程式开发设计指南->第四章 例子程序
- Programming Windows程式开发设计指南->第五章 例子程序1
- Programming Windows程式开发设计指南->第七章 例子程序2