Windows API one-day training (25) createsolidbrush Function

Source: Internet
Author: User
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)

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.