When you see the buttons displayed in windows, the background color is gray. When you see the default window background, it is white. What do you do when your boss needs you to create a button with a black background? In fact, in windows, use the API function createsolidbrush to create a paint brush, and then call the fillrect function to fill the background. In this way, no matter what background you need, do whatever you want. Now let's first understand the createsolidbrush function and then practice fillrect.
The createsolidbrush function declaration is as follows:
Wingdiapi hbrush winapi createsolidbrush (_ in colorref color );
ColorIs the paint brush color.
An example of calling this function is as follows:
#001 //
#002 // The output is displayed on the interface.
#003 //
#004 // Cai junsheng 2007/08/29 QQ: 9073204 Shenzhen
#005 //
#006 void ccaiwinmsg: ondraw (HDC)
#007 {
#008 //
#009 STD: wstring strshow (_ T ("Implementation of the C ++ window class, 2007-08-27 "));
#010
#011 // set the color of the output string.
#012 colorref crold = settextcolor (HDC, RGB (255, 0, 0 ));
#013
#014 rect rctext;
#015 rctext. Left = 10;
#016 rctext. Top = 30;
#017 rctext. Right = 300;
#018 rctext. Bottom = 80;
#019
#020 // create a black paint brush,
#021 hbrush = createsolidbrush (RGB (0, 0, 0 ));
#022
#023 // fill the Quadrilateral color with a black paint brush.
#024 fillrect (HDC, & rctext, hbrush );
#025
#026 // Delete the painter.
#027 deleteobject (hbrush );
#028
#029 // display the middle position of the string in the Quadrilateral.
#030 drawtext (HDC, strshow. c_str (), (INT) strshow. Length (), & rctext,
#031 dt_center | dt_vcenter | dt_singleline | dt_end_ellipsis );
#032
#033 // restore the original color.
#034 settextcolor (HDC, crold );
#035}
Row 3 creates a black image brush. It is as follows:
Download(64.55 KB)