Programming Windows程式開發設計指南->第二章 例子程式

來源:互聯網
上載者:User

/*_############################################################################
  _##
  _##  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 ;

}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.