The time I wrote that the time is not long, but I'm don't worry, so now I am going to identify a persistence, even if I am afraid of resigning, I am willing to start with us. The classification of the game, I won't say a lot, I will write down in my thoughts, some are someone else, I have to send it to this, some are my own results, huh, I am. The use of VC.NET will not go to buy this book first. If you have VC6.0 experience, it is not a problem, I think it is very small, just in the mechanism. The following is the code that creates a game window, I have very clear, if you have any questions to check MSDN. Copy and run, the result of the program execution is the full screen red background, click the right mouse button to pop up the message window, press the ESC button to exit. This is my running environment, not a shake, so that some people can learn more better after they can learn. Speaking of this maybe someone will ask this not all the same code? Where did you copy it? Yes, the establishment of writing windows is like this, there is nothing difference, and then said Microsoft gives you a custom, how much can you create a lot? It can only be different in algorithms. But studying is to learn from the idea of others and complete your own ideals. Once again, I will write some code from the submissions of those seniors. In this explanation, many beginner procedures are unfamiliar, the class says that a program is a algorithm. You write any procedure is an algorithm, or you can't feel, such as a loop read database record. Algorithm, just like all things, the procedures are all algorithms. I am talking about my understanding, I have forgotten something on the courses, I don't help me, there is an opinion, I have said that this is to help me progress, huh, huh. // ******************************************************** ******************************** * Description: // Development environment: .NET 7.1.3091 // Operating system: WindowsXP SP2 / / S D K: Microsoft DirectX 9.0 SDK // Computer: // CPU :: Inter 2.6C // Memory: 1G DDR400 // Video Card: FX5900 128MB // Hard Disk: 120g * 2 8MB 7200 //Marboard: Inter865PE / / * *********************************************************** ************************* # include
Create a main window, process message loop / / Date: 2005.1.3 22: 34 // Edize: Zhang Xiaobin // *********************************** ***************************************************** INT PASCAL WINMAIN (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT NCMDSHOW) // Hinstance: The handle of the application // hprevinstance: In order to maintain compatibility with 16-bit Windows applications // lpcmdline: Pointer to command line parameter strings // NCMDSHOW: Specifies the integer {if (! INITWINDOW (Hinstance, ncmdshow) of the application window display mode; // Create a main window, return false if creating unsuccessful, return the program MSG msg; // Enter Message loop for (;;) {IF (PEEKMESSAG, NULL, 0, 0, PM_Remove) {if (msg.MESSAGE == WM_QUIT) Break; TranslateMessage (& MSG); DispatchMessage (& MSG);}}}}}} Return MSG. WPARAM;} // **************************************************************** ********************** // Function: initwindow () // Function: Create window // Date: 2005.1.3 22: 43 // Edize: Zhang Xiaobin // ***************************************************** *************************** Static Bool InitWindow (Hinstance Hinstance, Int Ncmdshow) {// Define Window Style: Wndclass Wc; Wc.Style = NULL; // Window Style wc.lpfnwndproc = (wndProc) WinProc; // Window message processing function pointer wc.cbclsextra = 0; // Assign an additional byte number wc.cbWndextra = 0 after the window class structure; // After assigning a window instance Additional bytes wc.hins Tance = Hinstance; // The application of the application corresponding to the application handle wc.hicon = null; // window icon wc.hbrbackground = createSolidbrush (RGB (100, 0, 0)); // Dark red background wc.lpszMenuname = null ; // Window menu resource name wc.lpszclassname = "my_test"; // Name of the window class RegisterClass (& WC); // Register window // Create a window hWnd = CREATEWINDOW ("my_test", "My Firstow Program ", // Window Title WS_POPUP | WS_MAXIMIZE, 0, 0, GetSystemMetrics (SM_CXSCREEN), // This function returns the screen width getSystemMetrics (SM_CYSCREEN), // This function returns the screen height NULL, NULL, HINSTANCE, NULL); if ( ! hWnd) Return False; showwindow (hwnd, ncmdshow); // Display window updateWindow (hwnd); // Refresh window Return True;
} // ***************************************************************** ******************** // Function: WinProc () // Function: Processing Window Message / / Date: 2005.1.3 22: 56 // Edize: Zhang Xiaobin // ******************************************************** ******************* LRESULT CALLBACK WINPROC (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM) {Switch (Message) {CASE WM_KEYDOWN: // Key Message Switch (wParam) {case vk_escape: MessageBox (hwnd, "ESC button Press! OK to launch!", "keyboard", mb_ok); PostMessage (hwnd, wm_close, 0, 0); // Send a WM_Close message for the window Break } Return 0; // After processing one message, return 0Case WM_Close: // Prepare to exit DestroyWindow (HWND); // Release Window Return 0;
Case WM_RBUTTONDOWN: MessageBox (hwnd, "right click!", "mouse", mb_ok); return 0;
Case WM_DESTROY: // If the window is released ... postquitMessage (0); // Send a WM_QUIT message RETURN 0 to the window;} // Call the default message processing Return DefWindowProc (HWND, Message, WParam, LParam);