×××××××××××××××××××××××××××××××××××××××××××××
// ******************************************************** *******************
// Project: Easywin
// File: easywin.cpp
// Content: A basic Win32 program
// ******************************************************** *******************
#include
/ / # include
// Function declaration
Bool Initwindow (Hinstance Hinstance, INT NCMDSHOW);
LResult Callback WinProc (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM);
// ******************************************************** *******************
// Function: WinMain ()
// Function: Win32 application portfolio function. Create a main window, process the message loop
// ******************************************************** *******************
INT PASCAL WINMAIN (Hinstance Hinstance, // Current instance handle Hinstance Hprevinstance, // Previous instance handle lpstr lpcmdline, // command line character int ncmdshow) // window display method {msg msg; // Create a main window if (! initwindow (Hinstance, NCMDSHOW) RETURN FALSE; // Enter the message loop: // Take a message from the application's message queue, send it to the message processing process, // When checking the WM_QUIT message, exit the message loop. While (GetMessage (& MSG, NULL, 0, 0)) {TranslateMessage (& MSG); DispatchMessage (& MSG);} // End Return msg.wparam;}
// ******************************************************** ******************
// Function: initwindow ()
// Features: Create a window.
// ******************************************************** ******************
Static Bool Initwindow (Hinstance Hinstance, Int Ncmdshow)
{HWND HWND; // Window Handle WNDCLASS WC; // Window Class Structure // Pack Window Class WC.Style = CS_VREDRAW | CS_HREDRAW; wc.lpfnWndProc = (WndProc) WinProc; wc.cbclsextra = 0; wc.cbwndextra = 0 ; wc.hInstance = hInstance; wc.hIcon = LoadIcon (hInstance, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); //wc.hbrBackground = GetStockObject (WHITE_BRUSH ); Wc.lpszMenuname = null; wc.lpszclassname = "easywin"; // Register window class registerclass (& wc); // Create a main window HWND = CREATEWINDOW ("easywin", // window name "A basic Win32 program ", // Window Title WS_OVERLAPPEDWINDOW, / / window style, defined as the X coordinate 100, // window location of the ordinary type 100, // window location Y coordinate 400, // window of the width 300, // window of the window NULL , // Parent window handle NULL, // menu handle hinstance, // application instance handle null); // window Create a data pointer if (! HWnd) return false; // Display and update window showWindow (hwnd, ncmdshow); UpdateWindow (HWND); Return True;} // ************************************************ ***********************************
// Function: WinProc ()
// Function: Handle the main window message
// ******************************************************** ******************
Lresult Callback WinProc (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM)
{Switch {CASE WM_KEYDOWN: // Key Message Switch (wparam) {CASE VK_ESCAPE: MessageBox (hwnd, "ESC button is pressing!", "Keyboard", MB_OK; Break;} Break; Case WM_RButtondown: // Mouse message {MessageBox (hwnd, "right click!", "Mouse", mb_ok); break;} case wm_paint: // window redraum message {char Hello [] = "Hello, I am easywin ! "; HDC HDC; PAINTSTRUCT PS; HDC = Beginpaint (HWND, & PS); // Acquired device Environment Handle SetTextColor (HDC, RGB (0, 0, 0, 255)); // Set text color Textout (HDC, 20, 10, Hello Strlen (Hello); // Output text endpaint (hwnd, & ps); // Release Resource Break;} Case WM_DESTROY: // Exit Message PostquitMessage (0); // Call exit function Break;} // call default Message Process Return DefWindowProc (Hwnd, Message, WParam, Lparam);} ××××××××××××××××××××××××××××××××××× ×××××××××××××××
#include
// Function prototype
Int WinApi Winmain (Hinstance, Hinstance, LPSTR, INT);
LResult WinAPI WndProc (HWND, UINT, WPARAM, LPARAM);
BOOL INITAPPLICATION (Hinstance);
Bool InitInstance (Hinstance, Int);
// WinMain function
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {if if (InitApplication (hInstance)!) return FALSE (hPrevInstance!); if return FALSE (InitInstance (hInstance, SW_SHOW)!); MSG msg; / / Window message // Start message loop while (GetMessage (& MSG, NULL, 0)) {TranslateMessage (& MSG); DispatchMessage (& MSG);} return msg.wparam;}
// WndProc main window process
LRESULT WINAPI WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {HDC hdc; RECT rc; HPEN hPen, hPenOld; HBRUSH hBrush, hBrushOld; switch (msg) {case WM_PAINT: hdc = GetDC (hWnd); GetClientRect ( HWND, & RC); HPEN = Createpen (PS_SOLID, 0, RGB (0,0,0)); Hbrush = CreateHatchbrush (HS_Diagcross, RGB (0, 0, 0)); HPENOLD = (HPEN) SelectObject (HDC, HPEN) Hbrushold = (Hbrush) SelectObject (HDC, Hbrush); Ellipse (HDC, RC.LEFT, RC.TOP, RC.Right, Rc.Bottom); SelectObject (HDC, HPENOLD); SelectObject (HDC, Hbrushold); ReleaseDC HWnd, HDC); Break; Case WM_DESTROY: PostquitMessage (0); Break; Default: Break;} Return DEFWINDOWPROC (HWND, MSG, WPARAM, LPARAM);} BOOL INITAPPLICATION (Hinstance Hinstance)
{WNDCLASS WC; // Window // Plug window class information wc.style = cs_hredraw | cs_vredraw; wc.lpfnwndproc = WndProc; wc.cbclsextra = 0; wc.cbwndextra = 0; wc.hinstance = Hinstance; wc.hicon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "SdkDemo2"; // return registration window class RegisterClass (& WC);
Bool InitInstance (Hinstance Hinstance, Int ncmdshow)