Code
General VC controls are gray.ProgramWhen the interface is beautified, the use of general controls does not match the beautifying program interface. In VB, C #, you can easily change the background color of the control, but it is not possible in VC. We need to improve this function by ourselves. Here is a brief introduction. If you are interested, you can go to http: // Search and view related content in www.vbkbase.com (VC knowledge base.
Create a dialog box project in vc60 and add a new class. Select the corresponding base class based on the control you want to beautify. to beautify the static control, select cstatic as the base class, the new class is cstaticex.
Add two class member variables to the new class. One is the control background color and the other is the text color:
Private:
Colorref m_backcolor;
Colorref m_textcolor;
Initialize the two variables in the constructor. I initialize them to black and white characters.
M_backcolor=RGB (0,0,0);
M_textcolor=RGB (255,255,255);
Add the wm_paint message to cstaticex, and add the beautification control to the onpaint message processing function of wm_paint.Code
{
Cpaintdc DC (This);//Device context for painting
CDC memdc;
Cbrush m_brush,*M_oldbrush;
Cbitmap bitmap;
Crect rect;
Cstring strwindowtext;
IntX, Y;
Csize size;
//Obtain Region
Getclientrect (&Rect );
//Get Text
This->Getwindowtext (strwindowtext );
//Create compatible memory bitmap handle
Memdc. createcompatibledc (&DC );
Bitmap. createcompatiblebitmap (&DC, rect. Width (), rect. Height ());
Memdc. SelectObject (&Bitmap );
//Get Text Size
Size=Memdc. gettextextent (strwindowtext );
//Create a paint brush and draw a background color
M_brush.createsolidbrush (m_backcolor );
M_oldbrush=Memdc. SelectObject (&M_brush );
Memdc. fillrect (&Rect,&M_brush );
Memdc. SelectObject (m_oldbrush );
M_brush.deleteobject ();
//Text
Y=Rect. Top;
X=Rect. Right/2-Size. CX/2;
Memdc. setbkcolor (m_backcolor );
Memdc. settextcolor (m_textcolor );
Memdc. textout (X, Y, strwindowtext );
//Drawing
DC. bitblt (rect. Left, rect. Top, rect. Width (), rect. Height (),&Memdc, rect. Left, rect. Top, srccopy );
}
Add a static control named idc_statictest in the dialog box and add a member variable cstatic m_statictest to it;
Add the header file of the cstaticex class to the header file of the dialog box class;
Set cstatic m_statictest
Change to cstaticex m_statictest;
Compile and run the command to see the effect!
ArticleSource: http://Www.diybl.com/course/3_program/vc/vc_js/200878/132216.html