Analysis of a primary problem with Windows programming

xiaoxiao2021-03-06  51

#include // includes all basic Windows API functions, writing Win32 applications must contain LRESULT CALLBACK WNDPROC (HWnd HmainWnd, Uint Message, WPARAM WPARAM, LPARAM LRESULT is the type of function, Callback declaration The order of calling of function parameters. See here for details. {Switch // Establish a message loop. Please see here about the news. {CASE WM_DESTROY: // If it is a WM_DESTROY message, enter this process {postquitMessage (0); // exiting return 0;} default: BREAK;} // The following function is to call the default message processing function Return DefWindowProc (hmainwnd, Message, wparam, lparam;} // Here to pay attention, here is the entry point of the program, equivalent to the main () function in the DOS, but the parameters are all.

INT Callback Winmain (this parameter is an instance handle Hinstance HPREVINSTANCE, / / ​​Previous instance handle lpstr lpszcmdparam, // command line string int ncmdshow) {msg message; // Define message data structure WNDCLASS MYWC; // Define window style hand handwnd; // Form handle char SZAPPTITLE [] = "API created program"; // application title string char SZAppName [] = "winapidemo"; // Apply name if (! Hprevinstance) { // the following definitions are myWC.style on the window parameter = CS_HREDRAW | CS_VREDRAW; myWC.lpfnWndProc = WndProc; myWC.cbClsExtra = 0; myWC.cbWndExtra = 0; myWC.hInstance = hInstance; myWC.hIcon = LoadIcon (NULL, IDI_INFORMATION); myWC.hCursor = LoadCursor (NULL, IDC_HELP); myWC.hbrBackground = GetStockObject (WHITE_BRUSH); myWC.lpszClassName = szAppName; myWC.lpszMenuName = NULL; RegisterClass (& myWC); // registration form} hMainWnd = CreateWindow ( Szappname, // Create Forms SzappTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, HIN Stance, null; showwindow (hmainwnd, sw_showmaximized); // Display Form UpdateWindow (HmainWnd); // Update Form WHILE (GetMessage (& Message, Null, 0) // Create Message Cycles {TranslateMessage (& Message) DispatchMessage (& Message);} Return (True);} This is the most unclear thing that is the data type. When you have finished learning the standard C, you look at this program, just like watching the book, a lot of things you understand the grammar, but you can't understand. So, first, let me talk about the data type in Windows programming. The following data is taken from the "Windef.h" file under the VC6 Include directory.

#define CALLBACK PASCAL # define WINAPI CDECL # define WINAPIV CDECL # define APIENTRY WINAPI # define APIPRIVATE CDECL # define PASCAL __pascal # define CALLBACK __stdcall # define WINAPI __stdcall # define WINAPIV __cdecl # define APIENTRY WINAPI # define APIPRIVATE __stdcall # define PASCAL __stdcalltypedef unsigned long DWORD; typedef int BOOL; typedef unsigned char BYTE; typedef unsigned short WORD; typedef float fLOAT; typedef int iNT; typedef unsigned int UINT; typedef UINT WPARAM; typedef LONG LPARAM; typedef LONG LRESULT; you can see, there are a lot The essence of the definition is the same, just for reading. In fact, there is only one type of data in the Win32 environment, which is 32BIT shaping, and others come from here. Moreover, most of the data types are directly 32 bit. In this way, what you have to do is familiar with these names, see "Win32 Data Type Getting Started". Int Callback Winmain (). This function is the entrance of the Win32 program, just like the main () under DOS (), the parameters of the main function are optional, the parameters of the WinMain function are must be. The same is that Main and WinMain are not called for programmers, but there is system call. In C, Main is not returned, we see that WinMain is returned, it is modified with Int callback. Callback illustrates the order of WinMain function parameters call. INT is a return value for the function. For the meaning of Callback, please refer to "WIN32 Function Storage Order". The WINMAIN function's modifier is not unique. You can have a lot of ways to write. For example: int Pascal WinMain (), int __stdcall winmain (). These writes are the same, just for different styles. Below, the statement has a lot of books, I will not tell us, if you are not familiar, please see "Getting Started with Win32 Data Type". When you write all the procedures, you will save as a C file, here I saved for miniwin.c. When you double-click this file, you will open it with VC6. At this time, you must first look at it, your program has a syntax error, VC can help you complete this work. Select Build - >> Compile Winiwin.c. According to my experience, many people who have entered this procedure for the first time, there will be a variety of errors, which is relatively simple, generally spelling errors. It is possible to control the above program. When you click on the menu, you have a message box, prompting you to have a related project, you directly choose Yes, the VC will automatically help you create (see if you save MINIWIN.C directory, is it more A lot of files). If you spell your program, you will see: miniwin.obj - 0 Error (s), 0 Warning (s).

转载请注明原文地址:https://www.9cbs.com/read-117909.html

New Post(0)