Opening window: simple program-changing the font color (1)

Source: Internet
Author: User

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 /////////////////////////// ////////////////////////////////////////

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.