One-day Windows API training (34) getsyscolor Function

Source: Internet
Author: User
When you need to display a button that is different, you need to use the following method to create it. Of course, this is also a comprehensive exercise based on the previous knowledge. Demonstrate how to use many API functions. Here you can also use the getsyscolor function to obtain the system color.
Winuserapi
DWORD
Winapi
Getsyscolor (
_ In int nindex );
NindexIs the color index value defined by the system.

An example of calling this function is as follows:
#001 //
#002 // The output is displayed on the interface.
#003 //
#004 // Cai junsheng 2007/09/12 QQ: 9073204 Shenzhen
#005 //
#006 void ccaiwinmsg: ondraw (HDC)
#007 {
#008 // display a button.
#009 // set the button background color.
#010 rect rctext;
#011 rctext. Left = 10;
#012 rctext. Top = 10;
#013 rctext. Right = 100;
#014 rctext. Bottom = 100;
#015
#016 hbrush = createsolidbrush (getsyscolor (color_3dface ));
#017 // fill the Quadrilateral color with a black paint brush.
#018 fillrect (HDC, & rctext, hbrush );
#019 deleteobject (hbrush );
#020
#021 //
#022 Hpen hlight = createpen (ps_solid, 1,
#023 getsyscolor (color_3dhighlight ));
#024 Hpen hshdaow = createpen (ps_solid, 1,
#025 getsyscolor (color_3ddkshadow ));
#026
#027 //
#028 // move to the specified position.
#029 point ptlefttop;
#030 ptlefttop. x = 20;
#031 ptlefttop. Y = 20;
#032 movetoex (HDC, ptlefttop. X, ptlefttop. Y, null );
#033
#034 // display white lines.
#035 hgdiobj holdpen = SelectObject (HDC, hlight );
#036 ptlefttop. x = 20;
#037 ptlefttop. Y = 90;
#038 lineto (HDC, ptlefttop. X, ptlefttop. y );
#039
#040 ptlefttop. x = 20;
#041 ptlefttop. Y = 20;
#042 movetoex (HDC, ptlefttop. X, ptlefttop. Y, null );
#043 ptlefttop. x = 90;
#044 ptlefttop. Y = 20;
#045 lineto (HDC, ptlefttop. X, ptlefttop. y );
#046
#047 // black lines are displayed.
#048 SelectObject (HDC, hshdaow );
#049 ptlefttop. x = 90;
#050 ptlefttop. Y = 90;
#051 lineto (HDC, ptlefttop. X, ptlefttop. y );
#052
#053 ptlefttop. x = 20;
#054 ptlefttop. Y = 90;
#055 lineto (HDC, ptlefttop. X, ptlefttop. y );
#056
#057 //
#058 SelectObject (HDC, holdpen );
#059 deleteobject (hlight );
#060 deleteobject (hshdaow );
#061
#062 int noldmode = setbkmode (HDC, transparent );
#063 // output text.
#064 STD: wstring strshow (_ T ("button "));
#065 drawtext (HDC, strshow. c_str (), (INT) strshow. Length (), & rctext,
#066 dt_center | dt_vcenter | dt_singleline | dt_end_ellipsis );
#067
#068 //
#069 setbkmode (HDC, noldmode );
#070}

This is a combination of the previously learned API functions to draw a button, if you do not know anything, please look at the previously learned API functions.

Related Article

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.