編寫你的第一個Windows程序

今天來教大家編寫第一個Windows程序:

進入VC++6.0界面,選擇File-àNewàProjectsàWin32 Application,再設置

工程的目錄,點擊確定,建立一個空的工程,進入工程,然後

FileàNewàFilesàC++ Source file ,建立C++源文件

程序的代碼:

#include <windows.h>

 

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)

{   

      MessageBox(NULL,TEXT("Hello World"),TEXT("HellWorldMessageBox"),0);

      return 0;

}

 

//WINAPI呼叫WindowsAPI函數

//WinMain函數是系統呼叫的用於初始化Win32應用程序的

//WinMain函數的參數說明

 

/*

原型:

int WINAPI WinMain(

  HINSTANCE hInstance,  // handle to current instance

  HINSTANCE hPrevInstance,  // handle to previous instance

  LPSTR lpCmdLine,      // pointer to command line

  int nCmdShow          // show state of window

);

參數說明:

hInstance       指向當前應用程序實例的句柄

hPrevInstance      指向已經存在的運行的實例,對於Win32程序來說永遠是空的,就不要考慮了

lpCmdLine          用於命令行執行的程序

mCmdShow        決定程序界面顯示的大小

                      SW_HIDE,SW_MINIMIZE,SW_RESTORE,SW_SHOW等這些參數,具體可以查看MSDN的文檔              

 

*/

 

//MessageBox函數的說明

/*

原型:

int MessageBox(

  HWND hWnd,          // handle of owner window

  LPCTSTR lpText,     // address of text in message box

  LPCTSTR lpCaption,  // address of title of message box

  UINT uType          // style of message box

);

 

*/

 

//TEXT

/*

Generic-Text Data Type Mappings

 

Generic-Text Data Type Name SBCS (_UNICODE, _MBCS Not Defined)

_MBCS    Defined

_UNICODE Defined

_TCHAR       char          char          wchar_t

_TINT      int             int             wint_t

_TSCHAR           signed       char          signed char wchar_t

_TUCHAR          unsigned   char          unsigned char wchar_t

_TXCHAR          char          unsigned   char wchar_t

_T or _TEXT                 No effect (removed by preprocessor) No effect (removed by preprocessor) L (converts following character or string to its Unicode counterpart)

*/

 

Windows要看MSDN的文檔,雖然裏面比較亂,呵呵,好像以前聽說過微軟的人的不能理清裏面的結構,大家還是慢慢看吧

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章