Windows Programming: Hello, World is displayed in the middle of the window.

Source: Internet
Author: User

1 # include <windows. h> 2 3 lresult callback MyWndProc (HWND hwnd, // handle to window 4 UINT uMsg, // message identifier 5 WPARAM wParam, // first message parameter 6 LPARAM lParam // second message parameter 7); 8 9 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) 10 {11 WNDCLASS wnd; 12 HWND hwnd; 13 MSG msg; 14 wnd. style = CS_HREDRAW | CS_VREDRAW ;// The horizontal or vertical change windows are repainted and associated with the WM_PAINT message of MyWndProc 15 wnd. lpfnWndProc = MyWndProc; 16 wnd. cbClsExtra = 0; 17 wnd. cbWndExtra = 0; 18 wnd. hIcon = LoadIcon (NULL, IDI_APPLICATION); 19 wnd. hCursor = LoadCursor (NULL, IDC_ARROW); 20 wnd. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); 21 wnd. lpszMenuName = NULL; 22 wnd. lpszClassName = "HelloClass"; // window class ID, used in the first parameter 23 wnd of CreateWindow. hInstance = hInstance; 24 if (! RegisterClass (& wnd) 25 {26 MessageBox (NULL, TEXT ("cannot create window"), TEXT ("ERROR"), MB_ OK | MB_ICONERROR); 27 return 0; 28} 29 30 hwnd = CreateWindow ("HelloClass", TEXT ("Hello"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); // The second parameter is window Title 31 ShowWindow (hwnd, nShowCmd); 32 while (GetMessage (& msg, NULL, 0, 0) 33 {34 TranslateMessage (& msg ); 35 DispatchMe Ssage (& msg); 36} 37 return 0; 38} 39 40 lresult callback MyWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 41 {42 HDC hdc; // define the device environment handle 43 PAINTSTRUCT ps; // draw structure 44 RECT rect; // rectangular structure 45 switch (uMsg) 46 {47 case WM_PAINT: 48 {49 hdc = BeginPaint (hwnd, & ps); 50 GetClientRect (hwnd, & rect); 51 DrawText (hdc, TEXT ("Hello, World! "),-1, & rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); 52 EndPaint (hwnd, & ps); 53} 54 break; 55 case WM_DESTROY: 56 PostQuitMessage (0 ); 57 return 0; 58} 59 60 return DefWindowProc (hwnd, uMsg, wParam, lParam); 61}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.