Windows Forms that change colors

Source: Internet
Author: User

# Include <windows. h> <br/> lresult callback wndproc (hwnd, uint, wparam, lparam); <br/> int winapi winmain (<br/> hinstance, <br/> hinstance hprevinstance, <br/> lpstr lpcmdline, <br/> int ncmdshow) <br/>{< br/> hwnd; <br/> wndclass; <br/> static tchar szappname [] = text ("hello"); <br/> MSG; <br/> bool Bret; </P> <p> wndclass. style = cs_hredraw | cs_vredraw; <br/> wndclass. lpfnwndpr OC = (wndproc) wndproc; <br/> wndclass. cbclsextra = 0; <br/> wndclass. cbwndextra = 0; <br/> wndclass. hinstance = hinstance; <br/> wndclass. hicon = loadicon (null, idi_application); <br/> wndclass. hcursor = loadcursor (null, idc_arrow); <br/> wndclass. hbrbackground = (hbrush) getstockobject (white_brush); <br/> wndclass. lpszmenuname = NULL; <br/> wndclass. lpszclassname = szappname; </P> <p> If (! Registerclass (& wndclass) <br/> return 0; </P> <p> hwnd = createwindow (szappname, <br/> text ("hello "), <br/> ws_overlappedwindow, <br/> 0, <br/> 0, <br/> 800, <br/> 600, <br/> null, <br/> null, <br/> hinstance, <br/> null); </P> <p> If (! Hwnd) <br/> return 0; </P> <p> showwindow (hwnd, ncmdshow); <br/> updatewindow (hwnd ); </P> <p> Bret = true; <br/> while (BRET) <br/> {<br/> Bret = getmessage (& MSG, null, 0, 0); <br/> If (Bret =-1) <br/> return 0; // error <br/> If (BRET) <br/>{< br/> translatemessage (& MSG); <br/> dispatchmessage (& MSG ); <br/>}< br/> return MSG. wparam; <br/>}< br/> lresult callback wndproc (hwnd, uint MSG, wparam, lparam) <br/>{< br/> paintstruct pS; <br/> HDC; <br/> rectrect; <br/> static hbrush; <br/> static byte red, green, blue; <br/> static DWORD color; </P> <p> switch (MSG) <br/> {<br/> case wm_create: <br/> color = 0; <br/> settimer (hwnd, 1, 10, null); <br/> break; <br/> case wm_timer: <br/> color = color + 1; <br/> If (color> 0x00ffffff) <br/> color = 0; <br/> invalidaterect (hwnd, null, false); <br/> break; <br/> case wm_paint: <br/> HDC = beginpaint (hwnd, & PS); <br/> getclientrect (hwnd, & rect ); <br/> hbrush = createsolidbrush (color); <br/> fillrect (HDC, & rect, hbrush); <br/> endpaint (hwnd, & PS ); <br/> deleteobject (hbrush); <br/> break; <br/> case wm_close: <br/> destroywindow (hwnd); <br/> break; <br/> case wm_destroy: <br/> killtimer (hwnd, 1); <br/> postquitmessage (0); <br/> break; <br/> default: <br/> return defwindowproc (hwnd, MSG, wparam, lparam); <br/>}< br/> return 0; <br/>}< br/>

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.