SDK Source Code Analysis 10

Source: Internet
Author: User
Tags 04x textout

1#include <windows.h>2 3 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);4 5 //define struct One is an int one is a string6 struct7 {8     intIstyle;9TCHAR *Sztext;Ten } OneButton[] = A { -Bs_pushbutton, TEXT ("pushbutton"), -Bs_defpushbutton, TEXT ("Defpushbutton"), theBs_checkbox, TEXT ("CHECKBOX"), -Bs_autocheckbox,text ("Autocheckbox"), -Bs_radiobutton,text ("RADIOBUTTON"), -Bs_3state,text ("3STATE"), +Bs_auto3state,text ("auto3state"), -Bs_groupbox,text ("GROUPBOX"), +Bs_autoradiobutton,text ("Autoradtobutton"), ABs_ownerdraw,text ("OwnerDraw") at }; - #defineNUM (sizeof button/sizeof button[0])//How many of them are there? - intWINAPI WinMain (hinstance hinstance, hinstance hprevinstance, PSTR szCmdLine,intncmdshow) - { - wndclass wndclass; - HWND hwnd; in msg msg; -TCHAR szclassname[] = TEXT ("MyClass"), szwindowsname[] = TEXT ("mywindows"); to  +Wndclass.cbclsextra =0; -Wndclass.cbwndextra =0; theWndclass.hbrbackground =(Hbrush) getstockobject (White_brush); *Wndclass.hcursor =loadcursor (NULL, idc_arrow); $Wndclass.hicon =LoadIcon (NULL, idi_application);Panax NotoginsengWndclass.hinstance =hinstance; -Wndclass.lpfnwndproc =WndProc; theWndclass.lpszclassname =Szclassname; +Wndclass.lpszmenuname =NULL; AWndclass.style = Cs_vredraw |Cs_hredraw; the  +     if(! RegisterClass (&wndclass)) -     { $MessageBox (HWnd, TEXT ("The application on Windows nt!"), TEXT ("error~"), MB_OK); $     } -  -HWnd =CreateWindow (Szclassname, the Szwindowsname, - Ws_overlappedwindow,Wuyi Cw_usedefault, the Cw_usedefault, - Cw_usedefault, Wu Cw_usedefault, - null, NULL, HINSTANCE, NULL); About ShowWindow (hWnd, ncmdshow); $ UpdateWindow (hWnd); -  -      while(GetMessage (&msg, NULL, NULL, NULL)) -     { ATranslateMessage (&msg); +DispatchMessage (&msg); the     } -     returnMsg.wparam; $ } the  the LRESULT CALLBACK WndProc (HWND hwnd, UINT MSG, WPARAM WPARAM, LPARAM LPARAM) the { the     StaticHWND Hwndbutton[num]; -     Staticrect rect; in     StaticTCHAR sztop[] = TEXT ("message WParam LParam"), theSzund[] = TEXT ("_______         ______    ______"), theSzformat[] = TEXT ("%-16s%04x-%04x%04x-%04x"), szbuffer[ -]; About     Static intCxchar, Cychar; the     inti; the paintstruct PS; the HDC hdc; +  -     Switch(msg) the     {Bayi      Casewm_create: theCxchar = LoWord (Getdialogbaseunits ());//Get character width theCychar = HiWord (Getdialogbaseunits ());//Get character height These two are the API for dialog boxes -  -          for(i =0; i < NUM; i++) the         { theHwndbutton[i] = CreateWindow (TEXT ("Button"), Button[i].sztext, Ws_child | ws_visible |Button[i].istyle, theCxchar, cychar* (1+2* i), -* Cxchar,7* Cychar/4, HWnd, (HMENU) I, the((lpcreatestruct) LParam)hinstance, NULL); -                 //generate child window handle saved in Hwndbutton the                 //lparam can actually be converted into a struct. the         } the         return 0;94      Casewm_size: theRect.left = -*Cxchar; theRect.top =2*Cychar; theRect.right =LoWord (lParam);98Rect.bottom =HiWord (lParam); About         //set the display text area -         return 0;101      CaseWM_PAINT:102HDC = BeginPaint (hWnd, &PS);103 104SelectObject (hdc, Getstockobject (System_fixed_font));//set the equal width font theSetBkMode (hdc, TRANSPARENT);//Set Transparent mode106TextOut (HDC, -*Cxchar, Cychar, Sztop, Lstrlen (sztop));107TextOut (HDC, -*Cxchar, Cychar, Szund, Lstrlen (Szund));108 109EndPaint (HWnd, &PS); the         return 0;111      CaseWm_drawitem: the      CaseWm_command:113ScrollWindow (HWnd,0,-cychar, &rect, &rect);//scroll up when you receive the command theHDC =GetDC (hWnd); the  the SelectObject (hdc, Getstockobject (System_fixed_font));117TextOut (HDC, -* Cxchar, cychar* (Rect.bottom/cychar-1), Szbuffer,118 wsprintf (Szbuffer, Szformat,119msg = = Wm_drawitem? TEXT ("Wm_drawitem"): TEXT ("Wm_command"), - HiWord (WParam), LoWord (WParam),121 HiWord (LParam), LoWord (LParam));122                 123                 //output information. 124 ReleaseDC (HWND, HDC); theValidateRect (HWnd, &rect);//make the window effectively delete the WM_PAINT message from the message queue126          Break;127      CaseWm_destroy: -PostQuitMessage (0);129         return 0; the     }131  the     returnDefWindowProc (hWnd, MSG, WParam, lParam);133}

SDK Source Code Analysis 10

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.