24 hours study DX first hour - Win32 form

xiaoxiao2021-03-06  56

#include

// Function declares BOOL INITWINDOW (Hinstance Hinstance, Int ncmdshow); LRESULT CALLBACK WinProc (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM);

// Variable Description HWND HWND; // Window Handle // ****************************************************** ********************** / / 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) {if (! INITWINDOW (Hinstance, ncmdshow) Return False; / / Creating the main window // Returns false if you create unsuccessful, return the program MSG msg; // Enter the message loop: for (;;) {? IF (PeekMessage (& MSG, NULL, 0, 0, PM_REMOVE)? { ?? IF (msg.Message == wm_quit) Break; ?? TranslateMessage (& MSG); ?? DispatchMessage (& MSG) ;?}} return msg.wparam;}

// ******************************************************** *********** // Function: initwindow () // Function: Create window // ********************** **********************************************

Static Bool INITWINDOW (Hinstance Hinstance, Int Ncmdshow) {? // Define Window Style: • WNDCLASS WC;? wc.style = CS_VREDRAW | CS_HREDRAW; / / Form Class Class WinPfnWndProc = (WinProc) WinProc; // The pointer of the window message processing function? Wc.cbclsextra = 0; // Assign an additional byte number after the window structure? Wc.cbwndextra = 0; // All byte number of additional bytes after assigning the window instance? Wc.hinstance = Hinstance; // The application of the application corresponding to the application handle? wc.hicon = null; // window icon? wc.hcursor = null; // Window mouse? wc.hbrbackground = Createsolidbrush (RGB (0, 0, 0 )))); // Black background? Wc.lpszMenuname = null; // window menu resource name? Wc.lpszclassname = "my_test"; // Name of the window class? RegisterClass (& WC); // Register window

??? // Create a window according to the parameters ???? hWnd = CREATEWINDOW ("my_test", // Create the name of the window class used by the window ?? "24 hours learning DX_ 1 hour", // window Title ?? WS_POPUP | WS_CAPTION, // Window style, defined as the X, Y coordinate of 0, 0, // window position X, Y coordinate, the width, height ?? null, // parent window Handle ?? NULL, // menu handle ?? hinstance, // application handle ?? NULL) ;? IF (! Hwnd) Return False;? Showwindow (hwnd, ncmdshow); // Display window? UpdateWindow (hwnd); // Refresh the window? Return true;} // ************************************************** ******************** / / Function: WinProc () // Function: Process Window Message // ************ ******************************************************

LRESULT CALLBACK WinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {switch (message) {case WM_KEYDOWN: // keystroke message switch (wParam) {case VK_ESCAPE: PostMessage (hWnd, WM_CLOSE, 0, 0); / / Send a WM_Close message in the window Break;} return 0; // After processing a message, return 0

?? Case WM_Close: // Prepare to exit ?? destroyWindow (hwnd); // Release window ?? Return 0;

Case WM_RBUTTONDOWN: RETURN 0;

Case WM_DESTROY: // If the window is released ...? PostquitMessage (0); // Send a wm_quit message to the window? Return 0;} // Call the default message processing Return DefWindowProc (HWND, Message, WPARAM, LPARAM); }

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

New Post(0)