The Windows graphical interface provides us with endless convenience and visual pleasure, which gives us endless delusions by shallow and deep colors. There are a variety of methods, and many data describes how to use the palette method, the process and complexity, requires us to have a certain graphic programming, below, I will introduce you to a relatively simple Method, even if you don't understand the concept of graphic programming and palette.
Step 1: New Single document project, all parameters take default.
Step 2: Define variables in ShadowView.h as follows:
PRIVATE: INT Colorr; Int Colorg;
Step 3: The initialized variable in the constructor of ShadowView.cpp is as follows:
CshadowView :: cshadowview () {// Todo: add construction code here colorR = 255; color = 255;}
Step 4: Add the following implementation code in OnDraw ():
void CShadowView :: OnDraw (CDC * pDC) {CShadowDoc * pDoc = GetDocument (); ASSERT_VALID (pDoc); // TODO: add draw code for native data here CRect m_rcClient; file: // get filled rectangle of the client area GetClientRect ( & m_rcclient); int nwidth = m_rcclient.width (); int nHeiGHT = m_rcclient.Height (); cRect Rectangle; file: // Split customer area into small rectangles, fill For (int i = 0; i
Now compilation, run the program, we can find that the background of the single document interface has been filled with yellow gradation. Next, we implemented the left mouse button on the interface to realize the change in background color.
Step 5: Add the message processing mapping function of the left mouse button in ClassWizard and add the following code:
Void cshadowview :: ONLBUTTONDOWN (UINT NFLAGS, CPOINT) {file: // Generates less than 255 random number, assigns Int nrand = rand (); float fmap = (float) 255 / rand_max; colorR = (uint) (FLOAT) NRAND * FMAP 0.5F; nrand = rand (); FMAP = (float) 255 / rand_max; colorg = (uint) (float) nrand * fMap 0.5F; file: // update interface invalidate () ; CView :: ONLBUTTONDOWN (NFLAGS, POINT);
Ok, all the features are implemented, click the left mouse button on the interface, we can find that the background is filled with different gradation