The second time: Step steps are getting bigger, really like the school leader is so busy, but after a few days of inexplicably, I don't know how it is in these days! It seems that this experience is the same from the earth. Wu Yisen's "Memory Drama". Book is positive! It can not be exaggerated, the core of the Windows programming core is the callback function. As long as Li Wei's "VCL architecture" and Houjie's "deep-in-depth MFC" people should understand that Windows is a big news cycle. Program, when there is an external other command, this big loop will be suspended, and the event of the external command, and the function of the external command is the callback function (WinProc ()), he is through the handle (hwnd) Determine the form that this command triggers. Similarly to the prototype of the callback function first. In this function, different messages will be assigned to different handles by the Switch statement. The prototype of Windows message processing function is defined: LRESULT CALLBACK WINDOWPROC (HWND HWND, // Receive Message Window Handle UINT UMSG, // Main Message Value WPARAM WPARAM, // Sub-Message Value 1LPARAM LPARAM // Subsome Value 2 );
The message processing function must be defined in this style of the above, and of course the function name can be taken casually. Just use this cut as an example, our callback function is written like this: LRESULT CALLBACK WinProc (HWnd Hwnd, Uint Message, WParam WParam, LParam Lparam) {Switch (Message) {Case WM_SETCURSOR: SetCursor (null); Return 0; Case WM_KEYDOWN: Switch (wparam) {case vk_escape: // Press the ESC key triggering the keyboard for MessageBox (hwnd, "quit!", "keyboard", mb_ok); postquitMessage (0); break; case vk_space: // Events triggering the space button of the keyboard
Drawp.x1 = x; Drawp.y1 = Y; DRAWP.X2 = x3; DRAWP.Y2 = Y3; Enable = 1; return 0;} return 0; case wm_lbuttondown: // Press the left button triggering the mouse X = (int) loword (lparam); y = (int) HiWord (LPARAM); Break; Case WM_LBUTTONUP: // Release the Right-click Triggering Event X3 = (int) loword (lparam); Y3 = (int) HiWord (lParam); Drawp.Rectanglep (x, y, x3, y3); Break; Case WM_MOUSEMOVE: // Mouse mobile triggering event enable = 2; Break; Case WM_DESTROY: PostquitMessage (0); return 0;} Return DefWindowProc HWND, Message, WParam, LParam;} It looks so simple, but this has a lot of wisdom of wisdom! pay tribute! ! The third time: Both the profession is the foundation of Windows programming, not so complicated, if there is anything unclear, it is highly recommended to see the two books recommended above (it seems to give Li Wei teacher and the teacher of the teacher Working J), but this is far less enough, Microsoft also gave us a lot of API functions, they all packaged him, we can use it, Direct programming also contains a lot of such functions, If you want to write a game or complete other graphic processing, Direct programming is essential, let's talk about the foundation. First we have to join the two Direct library files, this is Microsoft to us, just like the teacher tells us if you want to make an operation when writing C language, you must start plus #inculde
Then, in the header file, it is necessary to invoke the library function (#include
ddsd.dwSize = sizeof (ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; // this is the off-screen page ddsd.dwHeight = 480; // high ddsd.dwWidth = 640; / / Wide LPDD-> CreateSurface (& DDSD, & LPDDSMAP, NULL); // Create a page DDSD.DWHEIGHT = 26; ddsd.dwwidth = 32; LPDD-> CreateSurface (& DDSD, & LPDDSMOUS, NULL); // Create page ddsd.ddsCaps.dwCaps mouse = DDSCAPS_OFFSCREENPLAIN; // // clear screen display each page DDBLTFX ddBltFx; ddBltFx.dwSize = sizeof (DDBLTFX); ddBltFx.dwFillColor = 0; lpDDSPrimary -> Blt (NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, & ddBltFx); lpDDSBuffer-> Blt (NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, & ddBltFx); lpDDSMap-> Blt (NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, & ddBltFx); lpDDSMouse-> Blt (NULL, NULL , NULL, DDBLT_WAIT | DDBLT_COLORFILL, & ddBltFx); // set transparent color and texture DDReLoadBitmap (lpDDSMap, "inn.BMP"); DDReLoadBitmap (lpDDSMouse, "mouse.BMP"); MakeRect (0,0,640,480); lpDDSPrimary-> BltFast (0, 0, LPDDSMAP, & R, NOKEY); DDSETCOLORKEY (LPDDSMAP, RGB (0,255,0)); DDSETCOLORKEY (LPDDSMOUSE, RGB (0,255,0));} Old rules, or to each function Specific description: Create a Direct object, his prototype is HRESULT WINAPI DirectDrawcreateex (Guid Far * LPGUID, LPVOID * LPLPDD, REFIID IID, IUNKNOWN FAR * PUNKOUTER);
The first parameter is LPGUID: points to the global unique marker (Global Unique Identify) of the DirectDRAW interface. Here, we give it null, indicating that we will use the current DirectDRAW interface. The second parameter is LPLPDD: This parameter is the address used to accept the initial DirectDRAW object. Here, we give it to convert to a VOID ** type & lpdd with a mandatory type. This function can change the pointer to the pointer. The third parameter is IID: here IID_IDIRECTDRAW7, indicating that we have to create IDirectDraw7 objects. If it is D8, the D9 is written to 8, 9. The fourth parameter is PUNKOUTER: There is a COM concentration feature takes into account future compatibility. Currently, NULL is currently. The return value of all DirectDraw functions is the HRESULT type, which is a 32-bit value. From the initialization we can know that after the object creation is completed, it will set the control level of the D7 object. Its prototype is: HRESULT SETCOOPERATIVELEVEL (HWND HWND, DWORD DWFLAGS) The first parameter is the window handle, we give it hwnd. The second parameter is the control level flag. His parameters see the table below: OK, then set the function of the display mode, its prototype is: HRESULT SETDISPLAYMODE (DWORD DWPPP, DWORD DWHEIGHT, DWORD DWBPP, DWORD DWRESHRATE, DWORD DWFLAGS); DWPIDTH AND DWHEIGHT is used to set the display mode Width and height. DWBPP is used to set the number of color bits of the display mode. DWREFRESHRATE Sets the refresh rate of the screen, 0 is used by default. DWFlags now the only valid value is DDSDM_Standardvgamode. Create a page, first empty, apply the space (similar to the destructor in C) MEMSET (& DDSD, 0, SIZEOF (DDSurfaceDesc2)); // Start Creating the main page, first empty page description ddsd.dwsize = sizeof (ddsd); // fill the page description ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; // back buffer has ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; // a back buffer lpDD-> CreateSurface (& ddsd, & lpDDSPrimary, NULL); // Creating the main page Creating the main page is: HRESULT CREATESURFACE (LPDDSurfaceDesc2 LPDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR * LPLPDDSURFACE, IUNKNOWN FAR * PUNKOUTER);
The first parameter is the address of the DDSurfaceDesc2 structure that is filled with page information. Here is & DDSD; the second parameter is the address of the receiving the home page pointer, here is & lpddsprimary; the third parameter must now be null, for this function Reserved.