VC + + Htcontrol Chtbutton Button control class usage instance parsing _c language

Source: Internet
Author: User

This article takes the example form to explain the VC + + Htcontrol control class's Chtbutton button control class usage, believed to everybody better understanding VC + + has certain help. The specific contents are as follows:

General knowledge of VC + + friends know, VC + + button control Chtbutton subordinate Htcontrol control group, directly by the WIN32 API implementation, you can use it in sdk,mfc,wxwidget environment. Support to generate various types of buttons, such as: normal button, PNG transparent button, check box button, radio button, etc. Note that the form must be dynamically created with the following code snippet:

M_htbtnclose.create (758, 0, m_hwnd, ichildid++);
M_htbtnclose.setallbitmap (M_hbmpbtnclosenormal, m_hbmpbtnclosedown,m_hbmpbtnclosehover);
M_HTBTNCLOSE.SETPARENTBGMEMDC (M_HDCMEMBUF);

The CHTButton.h control core code and comments are described below:

/*****************************************************************
| Copyright (c), ******************************************************************/#if!defined (__CHTBUTTON_H_
_) #define __CHTBUTTON_H__ #include "CHTTip.h" class Cmybutton;
 Class Afx_class_export Chtbutton {Public:chtbutton ();

~chtbutton (); /****************************************************************************
| function function: Create button | | Input Parameters: | | X: Form position x coordinates (relative to parent form) | | Y: Form position y-coordinate (relative to parent form) | | Iwidth: Form Width | | Iheight: Form High | | Hparent: Parent Window Handle | | Hbtnid: Form ID | | Szlabel: Form Title | |      Dwstyle: Button Behavior Identification | |      Bs_checkbox: check box button | |      Bs_radiobutton: radio Button | |     Bs_notify: Send To get (Bn_setfocus) Lose (Bn_killfocus) The focus of the notice | | Bs_notify << 2: Send the press notice (Bn_killfocus + 2) | | Output parameters: none | | Return Value: Success: Window handle failed: NULL | |
Description: | /HWND Create (int x, int y, int iwidth,

int iheight, HWND hparent, int ibtnid, tchar* Szlabel = null, DWORD dwstyle = null); /****************************************************************************
| function function: Change window position Size | | Input Parameters: | | Iwidth: Form width -1 means width invariant | | Iheight: Form high-1 means high unchanged | | X: Form position x Coordinates | | Y: Form position y-coordinate | | Brepaint: Whether to redraw the window after the change | | Output parameters: none | | return value: none | |
Note: If you change the window size, you need to reset various bitmaps before MoveWindow | /void MoveWindow (iNT x, int y, int iwidth =-1, int iheight =-1, BOOL brepaint = TRUE); /****************************************************************************
| function function: Set hint window class pointer | | Input Parameters: | | PCLTIP: Hint window class pointer | | Output parameters: none | | return value: none | |
Description: |

/void SetToolTip (chttip* pcltip); /****************************************************************************
| function function: Set the hint window text | | Input Parameters: | | Sztiptext: Hint Text | | Output parameters: none | | return value: none | |
Description: |

/void SetTipText (tchar* sztiptext); /****************************************************************************
| function function: Get the handle of the window | | Input parameters: none | | Output parameters: none | | Return value: Form Handle | |
Description: |

/HWND gethandle (); /****************************************************************************
| function function: Get the handle of the parent window | | Input parameters: none | | Output parameters: none | | Return value: Parent form Handle | |
Description: |

/HWND getparent (); /****************************************************************************
| function function: Set Font | | Input Parameters: | | Hfont: Font | | Output parameters: none | |                            return value: None   |
|
Description: |

/void SetFont (Hfont hfont); /****************************************************************************
| function function: Set the color of the text | | Input Parameters: | | Crtext: color Value | | Output parameters: none | | return value: none | |
Description: | /void Setbtntextcolor (COLORREF

Crtext); /****************************************************************************
| function function: Set font (when the mouse stays on the form) | | Input Parameters: | | Hfont: Font | | Output parameters: none | | return value: none | |
Description: If not set the font with SetFont settings | ********************************************************************/void Sethoverfont (Hfont hfont); /****************************************************************************
| function function: Set the color of the text (when the mouse stays on the form) | | Input Parameters: | | Crtext: color Value | | Output parameters: none | | return value: none | |
Note: If not set then use Setbtntextcolor set Color | /void Sethoverbtntextcolor (COLORREF

Crtext); /****************************************************************************
| function function: Make window invalid and draw window | | Input parameters: none | | Output parameters: none | | return value: none | |
Description: |

/void Disable (); /****************************************************************************
|                  function function: Make window valid and draw window as normal |
| Input parameters: none | | Output parameters: none | | return value: none | |
Description: |

/void Enable (); /****************************************************************************
| function function: Set button to display text | | Input Parameters: | | Szlabel: Text of the button | | Point: Text start coordinate, default center | | Btextmove: Press the text to move (move one pixel to the lower right corner) Output parameters: none | | return value: none | |
Description: | /void SetLabel (tchar* Szlabel, point*

Point = NULL, BOOL btextmove = TRUE); /****************************************************************************
| function function: Get text on button | | Input Parameters: | | SZlabel: Text of the button | | Output parameters: none | | Return value: Text pointer | |
Description: |

/tchar* Getlabel (); /****************************************************************************
| function function: Get button Status | | Input parameters: none | | Output parameters: none | | Return value: Button state 0: Normal 1: Press 2: Long press 3: Invalid | |
Description: |

/int GetState (); /****************************************************************************
| function function: Set long by effective time | | Input Parameters: | | 
Wlongpresstime: Long Press Effective time (long press notification code Bn_killfocus + 3) |         | 0 means do not open long press function | | Output parameters: none | | return value: none | |   Description                             | /void Setlongpresstime (WORD

Wlongpresstime); /****************************************************************************
| function function: Set the status of Check and radio button Input Parameters: | | Bcheck:false (bst_unchecked) or True (bst_checked) | | Output parameters: none | | return value: none | |
Description: |

/void SetCheck (BOOL bcheck); /****************************************************************************
| function function: Get the status of check and radio button | | Input parameters: none | | Output parameters: none | | return value: FALSE (bst_unchecked) or True (bst_checked) | |
Description: | /BOOL GetchEck (); /****************************************************************************
| function function: Set button normal Bitmap | | Input Parameters: | | Hbitmap: Bitmap | | Inormalleftlen: The length of the non-extruded portion of the left bitmap | | Inormalrightlen: The length of the non-stretched portion of the bitmap right | | Output parameters: none | | return value: none | |
Description: | /void Setnormalbitmap (HBITMAP

hbitmap, int inormalleftlen = 0, int inormalrightlen = 0); /****************************************************************************
| function function: Set button pressed Bitmap | | Input Parameters: | | Hbitmap: Bitmap | | Output parameters: none | | return value: none | |
Description: | *********************************************************************/void Setlbtndownbitmap (Hbitmap hbitmap); /****************************************************************************
| function function: Set the mouse button on the button when the bitmap | | Input Parameters: | | Hbitmap: Bitmap | | Output parameters: none | | return value: none | |
Description: | /void Sethoverbitmap (Hbitmap hbitmap

); /****************************************************************************
| function function: Bitmap When setting button is invalid | | Input Parameters: | | Hbitmap: Bitmap | | Output parameters: none | | return value: none | |
Description: | /void Setdisablebitmap (HBITMAP

 HBITMAP); void Setallbitmap (Hbitmap hbitmapnormal, Hbitmap hbitMaplbtndown, hbitmap hbitmaphover, int inormalleftlen = 0, int inormalrightlen = 0); /****************************************************************************
| function function: Set the bitmap of the icon on the button | | Input Parameters: | | Hbitmap: Bitmap | | Piconrect: The rectangle occupied by the icon | | Output parameters: none | | return value: none | |
Description: | /void SetIcon (Hbitmap hbitmap, rect*

Piconrect); /****************************************************************************
| function function: Set the opacity of the form | | Input Parameters: | | Itransparency: Percentage of opacity | | Output parameters: none | | return value: none | |
Description: | *************************************************************************/void settransparency (int itransparency); /****************************************************************************
| function function: Set parent form background Memory Canvas | | Input Parameters: | | HPARENTBGMEMDC: Parent form background Memory Canvas | | Output parameters: none | | return value: none | |      Description: When the background of the parent form changes and the form itself is transparent (including the bitmap used by the form | |
Has transparency or the form does not have a background bitmap), you need to call this interface | /void Setparentbgmemdc (HDC
 
HPARENTBGMEMDC, int x = 0, int y = 0); /****************************************************************************
| function function: Set the background bitmap used by the parent form | | Input Parameters: | | Hparentbgbitmap: The background bitmap used by the parent form | | x, y bitmap painting starting point coordinates | | Output parameters: none | | return value: none | |      Description: When the parent form background uses a static bitmap and the form itself is transparent (including form use | |
Bitmap has transparency or the form does not have a background bitmap), you need to call this interface | ***********/void Setparentbgbitmap (Hbitmap hparentbgbitmap
 
, int x = 0, int y = 0); /****************************************************************************
| function function: Set parent form background Color | | Input Parameters: | | CRPARENTBG: Parent form background Color | | Output parameters: none | | return value: none | |      Description: When the parent form background uses a fixed color and the form itself is transparent (including form use | |
Bitmap has transparency or the form does not have a background bitmap), you need to call this interface | /void Setparentbgcolor (COLORREF

CRPARENTBG = RGB (236, 233, 216)); /****************************************************************************
| function function: Draw the window to the target device content Input Parameters: | | Hdcdest: Target device Content | | X, Y: Drawing start Coordinates | | Output parameters: none | | return value: none | |   Description                             | /void Drawwindow (HDC hdcdest, int x = 0,

 int y = 0);

cmybutton* Getcmybutton ();
private:cmybutton* m_pclbtn;
};

 #endif//!__chtbutton_h__

This class supports forms with arbitrary transparency and is simple to use with the following interface:

void settransparency (int itransparency);

The Chtbutton class also implements the PNG transparency button, which interested readers can test for themselves.

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.