The first chapter begins first, and give the content of this book to introduce the contents of this book - of course is a method of writing a program under Windows. Second, the program is written in C language and uses the API. After understanding what the goal is made, then three prerequisites have been proposed for readers who use this book. 1. Familiar with Windows from the perspective of the user. 2. Understand the C language. 3. Install 32-bit C language compiler and development environment for Windows programming. (The book mentioned is Microsoft Visual C 6.0) 1.1 Windows Environment Windows 98 and Windows NT are 32-bit preemptive multitasking and multi-threaded graphics operating systems.
Windows use Windows functions in Windows is the same as in the way using the C library function. The difference between the C libs function of the C library function is in the code of the program, and the code of the Windows function is located in the DLL other than the program. 1.2 Windows Programming Options "Classic" Windows Programming Method: C Language Windows API. 1.3 Write the first Windows program #include
Int WinApi Winmain (Hinstance Hinstance, Pstr Szcmdline, ICMDSHOW) {MessageBox (Null, Text ("Hello, Windows 98!"), Text ("Hellomsg"), 0);
Return 0;}
You can see: #include
The entry point of the Windows program is WinMain. int WINAPI WinMain (HINSTANCE Hinstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) it is declared in the WINBASE.H: IntWINAPIWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow); the third parameter is defined for the WINBASE.H LPSTR, change it to PSTR. Both data types are defined in Winnt.h, as a pointer to string. The LP prefix represents "long pointers", this is a 16-bit Windows creation. SZ represents "string ended with zero". The WinMain function declares to return an int value. The WinAPI identifier is defined in WINDEF.H, the statement is as follows: #define WinAPI _stdcall This statement specifies a call agreement, including how to generate machine code to place the parameters of the function call in the stack. Many windows function calls declare to WinAPI. The first parameter of WinMain is called "instance handle". Handle: Application is used to identify the numbers of certain things. WinMain's second parameter is always null (defined as 0). The third parameter of WinMain is the command line for running the program. Some Windows applications use this parameter to load files to memory when the program starts. The fourth parameter of WinMain indicates the way the program is initially displayed.
The MessageBox function is used to display short messages. It is considered a dialog. The first parameter of MessageBox is usually a handle of a window; the second parameter is a string displayed in the message frame body, and the third parameter is a string appearing on the message box title bar. The fourth parameter of MessageBox can be a combination of a constant that is starting in the previous in Winuser.h. The following constants to indicate hope buttons displayed in the dialog box: #define MB_OK 0x00000000L # define MB_OKCANCEL 0x00000001L # define MB_ABORTRETRYIGNORE 0x00000002L # define MB_YESNOCANCEL 0x00000003L # define MB_YESNO 0x00000004L # define MB_RETRYCANCEL 0x00000005L use C language "or" (|) operator to a constant representing the default button shown above constant composition: #define MB_DEFBUTTON1 0x00000000L # define MB_DEFBUTTON2 0x00000100L # define MB_DEFBUTTON3 0x00000200L # define MB_DEFBUTTON4 0x00000300L also be noted that using a constant message box icon appearance: #define MB_ICONHAND 0x00000010L #define MB_ICONQUESTION 0x00000020L #define MB_ICONEXCLAMATION 0x00000030L #define MB_ICONASTERISK 0x00000040L icon has some place name: #define MB_ICONWARNING MB_ICONEXCLAMATION #define MB_ICONERROG MB_ICONHAND #define MB_ICONINFORMATION MB_ICONASTERISK #define MB_ICONSTOP MB_ICONHAND in the above procedure, the MessageBox returns the value 1, but strictly speaking, it returns IDOK, IDOK is defined in Winuser.h, equal to 1. The MessageBox function can also return other values depending on the other buttons displayed in the message box.