Simple Program: optimize text color
Let's first look at the program running effect:
After being restored, it becomes the following:
File | new | Win32 application | project "zookeeper color change" | an empty project | complete | confirm,
File | new | C ++ source file | file "Main", and then generate the following code to main. in the CPP file, click optimize again | create "adjust colors to change colors.
The following is the replacement:
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////////
/// // Main. CPP /////////////////////////////////////
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////
# Include <windows. h>
// Used as the window class name to be deleted
Lpctstr lpszappname = text ("MyApp ");
// Window criteria
Lpctstr lpsztitle = text ("My application ");
// Number of window handling functions
Lresult callback wndproc (hwnd, uint, wparam, lparam );
// Main function, program entry
Int apientry winmain (hinstance, hinstance hprevinstance, lptstr lpcmdline, int ncmdshow)
{
// Message structure description
MSG;
// Window handle
Hwnd;
// Window class fill
Wndclass WC;
WC. Style = cs_hredraw | cs_vredraw;
WC. lpfnwndproc = (wndproc) wndproc;
WC. cbclsextra = 0;
WC. cbwndextra = 0;
WC. hinstance = hinstance;
WC. hicon = loadicon (null, idi_application );
WC. hcursor = loadcursor (null, idc_arrow );
WC. hbrbackground = (hbrush) (color_window + 1 );
WC. lpszmenuname = lpszappname;
WC. lpszclassname = lpszappname;
// Window-type Encryption
If (! Registerclass (& WC ))
Return (false );
// Create a window named "my application" based on window WC values
Hwnd = createwindow (lpszappname, lpsztitle, ws_overlappedwindow,
Cw_usedefault, 0, cw_usedefault, 0, null,
Null, hinstance, null );
If (! Hwnd)
Return (false );
// Display this window
Showwindow (hwnd, ncmdshow );
// Update this window
Updatewindow (hwnd );
// Enter message tracking
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return (msg. wparam );
}
// Number of window handling functions
Lresult callback wndproc (hwnd, uint umsg, wparam, lparam)
{
// Rectangular structure
Rect;
// Display the volume handle
HDC;
Paintstruct pS;
// Three-color variation
Static int ured = 0, ugreen = 0, ublue = 0;
// Message Processing
Switch (umsg)
{
// Window deduplication
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
Getclientrect (hwnd, & rect );
Settextcolor (HDC, RGB (ured, ugreen, ublue ));
Drawtext (HDC, text ("Hello! "),-1, & rect,
Dt_singleline | dt_center | dt_vcenter );
Endpaint (hwnd, & PS );
Break;
// If there is a merge Press
Case wm_keydown:
// Colors
Ured = rand () %255;
Ugreen = rand () %255;
Ublue = rand () %255;
// Weight conversion
Invalidaterect (hwnd, null, true );
Break;
// Window renewal history
Case wm_destroy:
Postquitmessage (0 );
Break;
// MMO Message Handling
Default:
Return defwindowproc (hwnd, umsg, wparam, lparam );
}
Return (0 );
}
//////////////////////////////////////// //// // EOF /////////////////////////// ////////////////////////////////////////