One of the realizations of chaos using Direct technology

xiaoxiao2021-03-06  90

Handling: This is a very beautiful article. In terms of strict sense, it is impossible to be a technical article. It can only be said to be a little experience in learning Direct programming, but it still contains a lot of Win32 programming and Direct. The basic knowledge of programming, I will take the ugly and hope to do a little for friends who are engaged in Direct programming. This article mainly tells the process of using Direct programming to implement a clipping process. The effect map is as follows: cut before cut : After cutting: Drawing white lines in the figure is the area after the cut is ^ _ ^. If your friends have found bugs inside, please tell me, if your friends have more good comments and advice, please tell me ^ _ ^. The first time: The programming of the initial spherous door "is a certain process, in fact, the start we must create a master, and this main function should be a big message loop, this main function is about the rough process as follows:

First we have to be a most basic thing is to create a form, and register, and then we can do more things based on this form, it is like a canvas first, then we can draw in the canvas. // ******************************************************** ************ // Function: WinMain () // Function: Windows program portfolio function. Create a main window, process message loop // ************************************************* ******************* INT PASCAL WINMAIN (Hinstance Hinstance, Hinstance HPREVINSTANCE, LPSTR LPCMDLINE, INT NCMDSHOW) {msg msg; // Message Structure InitWindow (Hinstance, ncmdshow); // Initialization form

While (1) // Message Cycle {IF (PEEKMESG, NULL, 0, 0, PM_Remove) {if (msg.Message == WM_QUIT) // Exit Message Cycle Break; TranslateMessage (& MSG); // Get Message Handling the callback function DispatchMessage (& msg);}} return msg.wparam;} Before talking about the message loop, I want to talk about the difference between the DOS and Windows driver mechanism:

The DOS program mainly uses sequential, process-driven programming methods. Order, process-driven procedures have a significant beginning, obvious process and a significant end, so the program can directly control the order of program events or processes. Although there are also many methods of processing anomalies in the procedure of the order of procedure, such exception handling is still sequential, process-driven structure.

The Windows drive mode is the event driver, which is not controlled by the order of the event, but is controlled by the incident, all events are disorder, and a programmer, when you write a program, you don't know Which button is first pressed first, and I don't know which news triggered first. Your task is to sort and manage messages that are developing applications or messages to receive. The event driver design is unfolded around the generation and processing of the message, and a message is a message about an event that occurs.

The prototype of the Winmain () function is as follows: int Pascal Winmain (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT NCMDSHOW) The first parameter hinstance is the handle identifies the application. But what is the handle? It is actually a pointer to the memory area occupied by the program, uniquely represents the app, Windows uses it to manage various objects in memory. The second parameter is HPREVINSTANCE, the previous instance handle of the application, don't worry it, for Win32, it is generally null. The third parameter is lpcmdline, which is a pointer to the application command line parameter string. For example, we run "Test Hello", the string of this parameter points to "Hello". The last parameter is ncmdshow, an integer used to specify the window display mode. It tells the application how to initialize the window, such as maximizing, minimizing state. About the other kind of window display mode will be described below. Then we want to initialize the form and register it, then we can use it.

// ******************************************************** *********** // Function: initwindow () // Function: Create window // ********************** ********************************************** Static Bool INITWINDOW (Hinstance Hinstance, INT NCMDSHOW) {WNDCLASS WC Wc.style = null; // window Class style wc.lpfnWndProc = (wndProc) WinProc; // Pointer wc.cbclsextra = 0 in the window process function; // Window classes Additional data wc.cbWndextra = 0; // window Class addition data wc.hinstance = hinstance; // has an instance handle of window classes wc.hicon = null; // Minimum window icon wc.hcursor = NULL; // Take the cursor wc.hbrbackground = null; // Brush wc.lpszMenuname = null; // pointing to the menu resource name, pointing the menu resource name; // pointing the pointer of the window class RegisterClass (& WC); // Register window hWnd = CreateWindow Menpa_rpg_demo "," Menpa_RPG_Demo ", WS_POPUP | WS_MAXIMIZE, 0, 0, GetSystemm etrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), NULL, NULL, hInstance, NULL); if (hwnd) return FALSE;! ShowWindow (hwnd, nCmdShow); // display window UpdateWindow (hwnd); // refresh the window return TRUE; } (1) The first parameter: member style control window style, some important features defined in Windows.h, and use these constants in the program. Other features can be combined. Other features :

(2) Second parameters: lpfnWndProc, the function name of the message processing function, if necessary, to convert it to the WndProc type when necessary. (3) Third, four parameters: The CBWndextra domain specifies the number of additional bytes allocated with all window structures established by this window class. When there are more than two windows belong to the same window class, if you want to correspond to each window, each window is desired. It is useful to use this domain. This is, as long as you set them to 0, don't take too much consideration. (4) Fifth parameters: Hinstance member, the value gives it a handle of the application corresponding to the window, indicating that the window is associated with this application. (5) Sixth parameters: Members HiCon is set to the handle of the icon used by the application, the icon is the icon that occurs in the task bar when the application is minimized, and it is used to indicate that the program still resides in memory. Windows provides some default icons, and we can also define your own icons, and the VC has a tool for making icons. (6) Seventh parameters: The HCursor domain defines the cursor shape generated by the window. LoadCursor returns a cursor handle that secures cursor handle or application definition. IDC_ARROW indicates an arrow cursor. (7) Eightyes: HBRBACKGROUND member is used to define the background color of the window. Here is NULL. (8) Ninth parameters: lpszMenuname is used to specify a menu name, and the menu is not defined in this program, so it is NULL. (9) Tenth parameters: lpszclassname Specifies the class name of this window. This program named "Menpa_RPG_DEMO". When you assign a value for the WNDCLASS domain, you can register the window class. Before you create a window, you must register the window class. The API function used by the registration window is registerclass. If you register, you will have a dialog. As shown by the program, the function registerclass returns 0 values, and can only return 0 values, because the registration is unsuccessful, the program can no longer be done again. After the registration is finished, it is created the form. Generally, we call this form of the creatwindows () function in the API function to complete the form of this form that is registered with HWND = CREATEWINDOW ("MENPAO_RPG_DEMO", // created by this form. Name "MENPAO_RPG_DEMO", // Window Title WS_POPUP | WS_MAXIMIZE, // Window style, all style See the table 0, // window position X coordinate 0, // window position Y coordinate getSystemMetrics (SM_CXSCREEN), // window height, here It is full screen GetSystemMetrics (SM_CYSCREEN), // window height, here is full screen null, // parent window handle null, // menu Hinstance, // application handle null); // The last parameter is additional data, generally 0 Parameters 1: The registered window class name, this class name has just been defined when we register the window. Parameter 2: Used to indicate the title of the window. Can be the same as the first parameter.

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

New Post(0)