您的位置:首页 > 其它

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 ;

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  windows winapi list server null c
相关文章推荐