C + + WINAPI process for creating windows and processing messages

Source: Internet
Author: User

1. Entry point function:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633559 (v=vs.85). aspx

Entry point function int WINAPI WinMain (hinstance hinstance,//Application Current instance hinstance hpreinstance,//Application Previous instance LPSTR lpcmdline,//command Row parameter int ncmdshow//window display status)

2. Design Window class
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 (v=vs.85). aspx

Create window class Wndclass Wc;wc.style = Cs_hredraw | cs_vredraw;//window Style wc.lpfnwndproc = windowproc;//window procedure handler function Wc.cbclsextra = 0;//class additional parameter Wc.cbwndextra = 0;// Window Additional Parameters wc.hinstance = hinstance;//Application Instance Wc.hicon = LoadIcon (null, idi_application);//Icon wc.hcursor = LoadCursor (null, Idc_arrow);//Cursor Wc.hbrbackground = (hbrush) getstockobject (Dkgray_brush);//window background wc.lpszclassname = "Metrox";// Window class name Wc.lpszmenuname = null;//Window menu


3. Registration window class
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633586 (v=vs.85). aspx

RegisterClass (&WC);

4. Create a window
https://msdn.microsoft.com/en-us/library/windows/desktop/ms632679 (v=vs.85). aspx

HWND hwnd;

hwnd = CreateWindow ("Metrox", "Metrox MFC windown", Ws_overlappedwindow, 0, 0, +, NULL, NULL, HINSTANCE, NULL);


5. Display window
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633548 (v=vs.85). aspx

ShowWindow (hwnd, SW_SHOWNORMAL);

6. Update window (send WM_PAINT message redraw window)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145167 (v=vs.85). aspx

UpdateWindow (HWND);

7. Message loop, Call window procedure function Processing window message
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644928 (v=vs.85). Aspx#creating_loop

MSG msg;//into the message loop while (GetMessage (&msg, NULL, 0, 0)) {translatemessage (&msg);//Convert Message DispatchMessage (&MSG) ;//Send Message to window procedure}


8. Converting messages
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644955 (v=vs.85). aspx

TranslateMessage (&msg);//Conversion message

9. Sending a message to a window procedure
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644934 (v=vs.85). aspx

DispatchMessage (&msg);//Send a message to a window procedure

10. Window procedure Function Processing window message
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633573 (v=vs.85). aspx

11. Handling other messages that the application does not process
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633572 (v=vs.85). aspx

C + + WINAPI process for creating windows and processing messages

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.