119.win32 window principle

Source: Internet
Author: User

1#include <Windows.h>2 3 //callback function for handling messages4 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);5 6 intWINAPI WinMain (hinstance hinstance, hinstance hpreinstance, PSTR szCmdLine,inticmdshow)7 {8     //set the name of the window9     StaticTCHAR szappname[ -] = TEXT ("Mywindow");Ten      One     //window class A wndclass wndclass; -     //style -Wndclass.style = Cs_hredraw |Cs_vredraw; theWndclass.lpszclassname = Szappname;//Set name -Wndclass.lpszmenuname =NULL; -Wndclass.hbrbackground = (hbrush) getstockobject (White_brush);//Set Background -Wndclass.lpfnwndproc = WndProc;//Setting the Callback Function processing window +Wndclass.cbclsextra = Wndclass.cbwndextra =0;//Expand -Wndclass.hinstance = hinstance;//window Handle +Wndclass.hicon = LoadIcon (NULL, idi_application);//load Icon AWndclass.hcursor = LoadCursor (NULL, Idc_arrow);//Load Mouse Style at  -     //by name, register window -     if(! RegisterClass (&wndclass)) -     { -MessageBoxA (0,"Window registration failed","Tips",0); -         return 0; in     } -      to     //Create a window by name +HWND hwnd = CreateWindow (Szappname,//window name -TEXT ("window"),//Window Title theWs_overlappedwindow,//window Style *Cw_usedefault,//default display position x $Cw_usedefault,//default display position yPanax NotoginsengCw_usedefault,//Default Width -Cw_usedefault,//Default Height theNull//child window +Null//Sub-menu AHINSTANCE,//window Handle the NULL); +  - ShowWindow (hwnd, sw_show); $UpdateWindow (HWND);//Display and update $MSG msg;//message -     //message loop (GetMessage Create event TranslateMessage dispatchmessage response event) -      while(GetMessage (&msg,null,0,0)) the     { -TranslateMessage (&msg);Wuyi         //Call callback function theDispatchMessage (&msg); -     } Wu  -     returnMsg.wparam; About } $  - LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) - { -     //Equipment Environment A HDC hdc; + paintstruct PS; the rect rect; -     Switch(message) $     { the      CaseWm_lbuttondown: theMessageBoxA (0,"press the left mouse button","Tips",0); the          Break; the      CaseWm_rbuttondown: -MessageBoxA (0,"press the left mouse button","Tips",0); in          Break; the      CaseWm_close: the         if(MessageBoxA (0,"whether to close the window","Tips",1) ==1) About         { the             //Close window, send Wm_destroy message the DestroyWindow (HWND); the         } +         Else -         { the             return 0;Bayi         } the          Break; the      CaseWm_destroy: -MessageBoxA (0,"was successfully closed","Tips",0); -Exit0); the          Break; the     default: the          Break; the     } -     returnDefWindowProc (hwnd, message, wparam, lparam); the}

119.win32 window principle

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.