编写你的第一个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的文档,虽然里面比较乱,呵呵,好像以前听说过微软的人的不能理清里面的结构,大家还是慢慢看吧

 

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