mfc_1--uses Windows API functions to generate a window display Helloword

Source: Internet
Author: User
Tags message queue

Use Windows API functions to generate a window display Helloword: #include <windows.h> LRESULT CALLBACK mywndproc (HWND Hwindow, UINT msg, Wpara   M WParam, LPARAM LPARAM); Enter WinMain function int WINAPI WinMain (hinstance hinstance, hinstance hprevinstance, PSTR szcmdline, int icmdshow) {Co NST static TCHAR appname[] = TEXT ("Hello World");      Initialize wndclassex, call registerclassex Function Register window class Wndclassex Mywin;      mywin.cbsize = sizeof (Mywin); Mywin.style = Cs_hredraw |      Cs_vredraw;      Mywin.lpfnwndproc = Mywndproc;      Mywin.cbclsextra = 0;      Mywin.cbwndextra = 0;      Mywin.hinstance = hinstance;      Mywin.hicon = 0;      MYWIN.HICONSM = 0;      mywin.hcursor = 0;      Mywin.hbrbackground = (hbrush) (Color_window + 1);      Mywin.lpszmenuname = 0;      Mywin.lpszclassname = AppName; Register, call the RegisterClassEx Function Registration window class if (!      RegisterClassEx (&mywin)) return 0; Const HWND Hwindow = CreateWindow (AppName, AppName, Ws_overlappedwindow, Cw_usedefault, Cw_usede   FAULT,   Cw_usedefault, Cw_usedefault, 0, 0, hinstance, 0); Call the ShowWindow and UpdateWindow functions to display and update the window/* into the message loop. About message loops Simply put, a Windows application is message-driven, a system or user sends a message when the application does something or completes a task, enters the program's message queue, and then the message loop takes the message out of the message queue and hands it to the corresponding window process. The window procedure function of this program is the Mywndproc function, which completes an operation or task when the window procedure function finishes processing the message. In this example, to display the "Hello World" string, the UpdateWindow function sends a WM_PAINT message, but the message is sent directly to the window procedure processing without a message queue, and the "Hello World" string is eventually drawn in the window procedure function.      */showwindow (hwindow,icmdshow);      UpdateWindow (Hwindow);      {msg msg;      while (GetMessage (&msg,0,0,0)) {translatemessage (&msg);      DispatchMessage (&AMP;MSG);      } return (int) Msg.wparam; }} LRESULT CALLBACK Mywndproc (HWND Hwindow, UINT msg, WPARAM WPARAM, LPARAM LPARAM) {if (Msg==wm_pai      NT) {paintstruct ps;      Const HDC HDC = BeginPaint (HWINDOW,&AMP;PS);      Rect rect;      GetClientRect (Hwindow,&rect); DrawText (Hdc,text ("HELLO World"), -1,&rect, Dt_singleline | Dt_center |      Dt_vcenter);     EndPaint (HWINDOW,&AMP;PS); return 0;      } else if (Msg==wm_destroy) {postquitmessage (0);      return 0;      } return DefWindowProc (Hwindow,msg,wparam,lparam);   }

  

mfc_1--uses Windows API functions to generate a window display Helloword

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.