Windows Programming--Drawing

Source: Internet
Author: User

Source

1#include <Windows.h>2#include <tchar.h>3#include <stdio.h>4 #defineNUM 10005 6 LRESULT CALLBACK Windproc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM);7 8 intWinMain (hinstance hInst, hinstance tmp, LPSTR szcmd,intnshow)9 {Ten wndclass wndclass; Onetchar* ClassName = TEXT ("MyClass"); A HWND hwnd; - msg msg; - Hbrush Hbrush; the  -Hbrush = CreateSolidBrush (RGB (0x20,0x85,0x41)); -Wndclass.cbclsextra =0; -Wndclass.cbwndextra =0; +Wndclass.hbrbackground =Hbrush; -Wndclass.hcursor =loadcursor (NULL, idc_arrow); +Wndclass.hicon =LoadIcon (NULL, idi_application); AWndclass.hinstance =HInst; atWndclass.lpfnwndproc =Windproc; -Wndclass.lpszclassname =ClassName; -Wndclass.lpszmenuname =NULL; -Wndclass.style = Cs_vredraw |Cs_hredraw; -  -     if(! RegisterClass (&wndclass)) in     { -MessageBox (NULL, TEXT ("gegister Class fail!!"), TEXT ("Error"), MB_OK); to         return 0; +     } -  the     //ws_vscroll window scroll bar *hwnd = CreateWindow (ClassName, TEXT ("Hello"), Ws_overlappedwindow | Ws_vscroll,0,0, +, -, NULL, NULL, HINST, NULL); $     if(hwnd = =NULL)Panax Notoginseng     { -MessageBox (NULL, TEXT ("Create Window fail!!"), TEXT ("Error"), MB_OK); the         return 0; +     } A ShowWindow (hwnd, nshow); the UpdateWindow (HWND); +  -      while(GetMessage (&msg, NULL,0,0)) $     { $TranslateMessage (&msg); -DispatchMessage (&msg); -     } the  -     return 0;Wuyi } the  - LRESULT CALLBACK Windproc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) Wu { - HDC hdc; About     StaticHpen Hpen1,hpen2; $     StaticHbrush Hbrush; - paintstruct pt; - textmetric ts; -TCHAR buf[1024x768]; A     intI//Number of rows +     Static intCychar;//Font Size the     Static intCy//Customer Area Height -     StaticSCROLLINFO si; $     Static intPosition =0; the     Switch(message) the     { the      Casewm_create: theHDC =GetDC (HWND); -Hbrush = CreateSolidBrush (RGB (249,98,241)); inHPen1 = CreatePen (Ps_solid, -, RGB (0,0,255)); theGetTextMetrics (HDC, &ts); the ReleaseDC (hwnd, HDC); AboutCychar =Ts.tmheight; theSi.cbsize =sizeof(SI); the         return 0; the      Casewm_size: +         //Window Height -cy =HiWord (lParam); theSi.fmask =Sif_all;BayiSi.nmax = NUM-1; theSi.nmin =0; theSi.npage = CY/Cychar; -Si.npos =position; -Si.ntrackpos =0; theSetscrollinfo (hwnd, Sb_vert, &si, TRUE); the      CaseWm_vscroll: the         //you can omit the Iparam parameter when the scrollbar is part of a window the         Switch(LoWord (wParam)) -         { the          CaseSb_bottom: theSi.npos =Si.nmax; the              Break;94          CaseSb_linedown: thesi.npos++; the              Break; the          CaseSb_lineup:98si.npos--; About              Break; -          CaseSb_pagedown:101Si.npos = Si.npos + cy/Cychar;102              Break;103          CaseSb_pageup:104Si.npos = si.npos-cy/Cychar; the              Break;106          Casesb_thumbposition:107Si.npos =HiWord (wParam);108              Break;109         default: the              Break;111         } theSi.fmask =Sif_pos;113Setscrollinfo (hwnd, Sb_vert, &si, TRUE); theGetScrollBarInfo (hwnd, Sb_vert, &si); thePosition =Si.npos; the         //UpdateWindow (HWND);//The window must have an invalid area, otherwise the refresh is also a white brush. Replace with InvalidateRect forced flush117         //invalidaterect function generates WM_PAINT message118 InvalidateRect (hwnd, NULL, FALSE);119         return 0; -      CaseWM_PAINT:121GetScrollBarInfo (hwnd, Sb_vert, &si);122         //after calling BeginPaint, the entire client goes to work. ValidateRect makes any rectangular area of the client area effective123HDC = BeginPaint (hwnd, &PT);124Hpen2=(Hpen) SelectObject (hdc, HPEN1); the SelectObject (hdc, hbrush);126Movetoex (HDC, -, -, NULL);127LineTo (HDC, -, -); -Rectangle (HDC, -, -, $, $);129 SelectObject (hdc, HPEN2); the 131          for(i =0; i < NUM; i++) the         {133_stprintf (buf, TEXT ("---------------%d--------------"), Si.npos +i);134TextOut (HDC,0ICychar, buf, _tcslen (BUF));135         }136EndPaint (hwnd, &PT);137         return 0;138      CaseWm_destroy:139PostQuitMessage (0);//Send Wm_quit message $         return 0;141     default:142          Break;143     }144 145     returnDefWindowProc (hwnd, message, WParam, lParam);146}
View Code

Windows Programming--Drawing

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.