Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / MFC
Article

CButtonSSL

Rate me:
Please Sign up or sign in to vote.
4.20/5 (8 votes)
4 Dec 2001CPOL32 min read 314.8K   6.9K   72   38
An owner-drawn, flat, menu button that correctly handles the default state

Image 1

Bug Fixes (05-Dec-2001)

CButtonSSL has now been used extensively in a real product and has such has been through the mill a fair bit on the testing side. Thankfully this has given me time to find and fix these problems, too.

This latest version includes fixes for a GDI resource leak (which I must thank Dieter Hammer for finding), several changes to fix button state drawing problems (which I must thank Eugene Pustovyt for pointing out some of the more obscure ones) and also fixes a major bug with release builds.

The problem was that in a release build that included a CButtonSSL checkbox whose state was altered using SetCheck the application would crash. After enormous amounts of mostly fruitless debugging I eventually found a way of reproducing the problem consistently, with the help of Alvaro Mendez. Once I'd got to this stage I beginning to despait , but thankfully Joe Newcomer came to my rescue and pointed out the error of my ways. The OnSetCheck handler didn't define both of the required parameters for an ON_COMMAND handler. So, two parameters pushed on the stack, only one popped off!

I'd like to thank everybody that has helped me out with this round of bug fixes, hopefully there won't be (m)any more.

Update (18-Sep-2001)

It seems that no matter how hard you try, you just can't get enough done in one day! Trying to juggle work, play and family isn't easy! However, at last I have got round to updating this article. So, what's new?

  • CButtonSSL now inherits from <a href="http://www.codeproject.com/buttonctrl/oddbutton.asp">COddButton</a>, though there are one or two changes I've made to it (see below).
  • The Radio Button problem has been fixed (check out the demo).
  • Several fixes have been implemented for drawing the button.
  • Most of the interface to the menu has been exposed, so there's a whole raft of new Menu Functions.

Because there's so much been added I haven't had chance to test it all extensively, especially with respect to the menu functions. If there any problems, please let me know (prefereably with a fix ;)).

Inheriting from COddButton

The change to inherit from COddButton has changed the handling of the standard button styles. The use of COddButton::PreSubclassWindow means that the control type is determined from the initial styles set in the dialog editor. So now you cannot set the Owner Draw style, otherwise it won't work properly.

The handling of the default style is also provided entirely by COddButton now, though as mentioned above, I have made one or two changes to handle radio buttons as well.

The first change was to the constructor to make m_bCanBeDefault TRUE initially. The second change was to the WM_GETDLGCODE handler,

COddButton::OnGetDlgCode 
  ()
. The function now handles the code for radio buttons as follows:

UINT COddButton::OnGetDlgCode() 
{
	UINT nCode = CButton::OnGetDlgCode();

	// tell the system if we want default state handling
	// (losing default state always allowed)
    UINT nType = GetControlType ();
	if (BS_RADIOBUTTON == (BS_RADIOBUTTON & nType) ||
		BS_AUTORADIOBUTTON == (BS_AUTORADIOBUTTON & nType)) {
		nCode |= DLGC_RADIOBUTTON;
	}
	else {
	    if (m_bCanBeDefault || m_bDefault)
		    nCode |= (m_bDefault ? DLGC_DEFPUSHBUTTON : DLGC_UNDEFPUSHBUTTON);
    }

	return nCode;
}

Introduction

It seems that Buttons are the flavour of the month at the moment and here's another. This button class is born out the need for a bitmap button with a menu drop-down on it, but as usual ended up being so much more!

I found Norm Almond's "Cool Push Menu Button" and Davide Calabro's CButtonST and wanted to combine the two. Along the way I came across the BS_OWNERDRAW problem and tried to find my own way around it. Fortunately Paolo Messina and Jerzy Kaczorowski solved it for me with their COddButton.

The class I have come up with draws mainly from these sources, but also some others and my thanks must go out to all those people who have helped me out in the Visual C++ forum. It has taken me so long to complete this and I have been a bit too relaxed with the documentation so if there is some code that you lay claim to and want it recognised then please let me know and I'll update it.

The full documentation for the class follows. I hope this is sufficient because it took me ages to write ;)

Overview | Class Members | Styles | Known Problems

CButtonSSL

Image 2

The CButtonSSL is a feature rich extension to the normal CButton. It adds flat appearance, a menu drop-down, bitmap or icon images, text and image alignment, control over the button colour, multiline tooltip, correct default button handling, control over the cursor and the ability to specifiy a URL to link to.

CButtonSSL provides owner-drawn functionality for check boxes, radio buttons and push buttons. A CButtonSSL object can be created for any of these.

A CButtonSSL object can have separate images for the button's up, over, down and disabled states. If an image is not specified for the disabled state a disabled images is created from the up image, which must always be specified. Additionally, the button colour and text colour can be different for the button's up, over and down states.

Creation of CButtonSSL object is the same as for a CButton object. They may be created from a dialog template or directly in your code. If they are created from a dialog template it is not necessary to call SubclassDlgItem if the DDX_Control entry exists for the variable in the DoDataExchange function of your dialog. However the button is created it must not have the BS_OWNERDRAW style set.

Following construction the button object's appearance should be initialised. The button's image(s) and the image alignment can be set using the Image Functions. The button text font and alignment can be altered using the Text Functions. The button's colours can be set using one of the Colour Functions and the button cursor, tooltip or URL can be set using one of the Miscellaneous Functions. If the button object is a checkbox then the button's check state can be set or retrieved using the Check Box Functions.

Windows notification messages are sent by the button control to the parent for CButtonSSL objects in the same manner as for CButton objects.

If you create a CButtonSSL object from a dialog resource, the CButtonSSL object is automatically destroyed when the user closes the dialog box.

#include "ButtonSSL.h"

Overview | Class Members | Styles | Known Problems

Class Members

Construction

<A href="#CButtonSSL">CButtonSSL</A>Constructs a CButtonSSL object.

Initialisation

<A href="#ButtonStyles">SetSSLButtonStyle</A>Changes the style of a buton.
<A href="#GetSSLButtonStyle">GetSSLButtonStyle</A>Retrieves information about the button control style.

Image Functions

<A href="#SetSSLButtonBitmap">SetSSLButtonBitmap</A>Specifies a single bitmap as the image for all button states.
<A href="#SetSSLButtonBitmaps">SetSSLButtonBitmaps</A>Specifies different bitmaps for different button states.
<A href="#SetSSLButtonIcon">SetSSLButtonIcon</A>Specifies a single icon as the image for all button states.
<A href="#SetSSLButtonIcons">SetSSLButtonIcons</A>Specifies different icons for different button states.
<A href="#SetSSLImageAlign">SetSSLImageAlign</A>Sets the alignment of the button image.
<A href="#SetSSLImageAlign">GetSSLImageAlign</A>Retrieves the image alignment for the button image.

Text Functions

<A href="#SetSSLTextAlign">SetSSLTextAlign</A>Sets the alignment for the button text.
<A href="#GetSSLTextAlign">GetSSLTextAlign</A>Retrieves the alignment of the button text.
<A href="#SetSSLButtonFont">SetSSLButtonFont</A>Specifies font characteristics for the button text

Colour Functions

<A href="#SetSSLDefaultColors">SetSSLDefaultColors</A>Sets the button and text colours to the default system defined colours.
<A href="#SetSSLDefaultColors">SetSSLColor</A>Specifies the colour to use for the button face or text for a particular button state.
<A href="#SetSSLColor">GetSSLColor</A>Retrieves the colour for the button face or text for a particular button state previously set with SetSSLColor.

Check Box Functions

<A href="#SetSSLCheck">SetSSLCheck</A>Sets the check state of a check box style button.
<A href="#SetSSLCheck">GetSSLCheck</A>Retrieves the check state of a check box style button.

Menu Functions

<A href="#SetSSLButtonMenu">SetSSLButtonMenu</A> Specifies the menu resource to use for a menu button.
<A href="#CheckSSLMenuItem">CheckSSLMenuItem</A> Places a check mark next to or removes a check mark from a menu item in the pop-up menu.
<A href="#CheckSSLMenuRadioItem">CheckSSLMenuRadioItem</A> Places a radio button next to a menu item and removes the radio button from all of the other menu items in the group.
<A href="#EnableSSLMenuItem">EnableSSLMenuItem</A> Enables, disables, or dims (grays) a menu item.
<A href="#GetSSLMenuItemCount">GetSSLMenuItemCount</A> Determines the number of items in a pop-up or top-level menu.
<A href="#GetSSLMenuItemID">GetSSLMenuItemID</A> Obtains the menu-item identifier for a menu item located at the specified position.
<A href="#GetSSLMenuState">GetSSLMenuState</A> Returns the status of the specified menu item or the number of items in a pop-up menu.
<A href="#GetSSLMenuString">GetSSLMenuString</A> Retrieves the label of the specified menu item.
<A href="#GetSSLMenuItemInfo">GetSSLMenuItemInfo</A> Retrieves information about a menu item.
<A href="#ModifySSLMenu">ModifySSLMenu</A> Changes an existing menu item at the specified position.
<A href="#RemoveSSLMenu">RemoveSSLMenu</A> Deletes a menu item with an associated pop-up menu from the specified menu.
<A href="#SetSSLMenuItemBitmaps">SetSSLMenuItemBitmaps</A> Associates the specified check-mark bitmaps with a menu item.

Miscellaneous Functions

<A href="#SetSSLButtonCursor">SetSSLButtonCursor</A>Specifies the cursor to display when the mouse is over the button.
<A href="#SetSSLButtonTooltip">SetSSLButtonToolTip</A>Specifies the tooltip to display when the mouse is hovered over the button.
<A href="#SetSSLButtonURL">SetSSLButtonURL</A>Specifies the URL to be launched when the button is clicked.

Overview | Class Members | Styles | Known Problems

CButtonSSL::CButtonSSL

CButtonSSL ();

Remarks

Constructs a CButtonSSL object. The button style is initially set to SSL_BS_FLAT, the image is initially aligned using SSL_IMAGE_TOP and SSL_IMAGE_LEFT and the text is initially aligned using SSL_TEXT_CENTER and SSL_TEXT_VCENTER.

Overview | Class Members | Styles | Known Problems

CButtonSSL::SetSSLButtonStyle

void SetSSLButtonStyle (UINT nStyle);

Parameters

nStyle
Specifies the button style.

Remarks

Changes the style of a button.

Use the GetSSLButtonStyle member function to retrieve the button style.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::GetSSLButtonStyle

CButtonSSL::GetSSLButtonStyle

UINT GetSSLButtonStyle ();

Return Value

Returns the button styles for this button object.

Remarks

Returns only the SSL_BS_ style values, not any of the window styles.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLButtonStyle

CButtonSSL::SetSSLButtonBitmap

BOOL SetSSLButtonBitmap (UINT nResourceID, COLORREF crMask = 
SSL_MASK);

Return Value

Nonzero if successful; otherwise 0.

Parameters

nResourceID
The resource ID for the bitmap to be added.

crMask
The colour to be used in the bitmap as a transparency mask. This is <A href="#SSL_MASK">SSL_MASK</A> by default.

Remarks

This function specifies a single bitmap to use for all states. The bitmap is copied into an image list and then treated as an icon thereafter. When the button is in the disabled state a disabled image is created from the specified bitmap.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLButtonBitmaps, CButtonSSL::SetSSLButtonIcon, CButtonSSL::SetSSLButtonIcons

CButtonSSL::SetSSLButtonBitmaps

BOOL SetSSLButtonBitmaps (UINT nUpID, COLORREF crUpMask, UINT nOverID = 
0, COLORREF crOverMask = SSL_MASK, UINT nDownID =         0, COLORREF crDownMask = 
SSL_MASK, UINT nDisabledID = 0, COLORREF crDisabledMask = SSL_MASK);

Return Value

Nonzero if successful; otherwise 0.

Parameters

nUpID
The resource ID for the bitmap to be used for the up state.

crUpMask
The colour to be used in the up bitmap as a transparency mask. This is <A href="#SSL_MASK">SSL_MASK</A> by default.

nOverID
The resource ID for the bitmap to be used for the over state. This is zero by default.

crOverMask
The colour to be used in the over bitmap as a transparency mask. This is <A href="#SSL_MASK">SSL_MASK</A> by default.

nDownID
The resource ID for the bitmap to be used for the down state. This is zero by default.

crDownMask
The colour to be used in the down bitmap as a transparency mask. This is <A href="#SSL_MASK">SSL_MASK</A> by default.

nDisabledID
The resource ID for the bitmap to be used for the disabled state. This is zero by default.

crDisabledMask
The colour to be used in the disabled bitmap as a transparency mask. This is <A href="#SSL_MASK">SSL_MASK</A> by default.

Remarks

The up bitmap must be defined, however, a resource ID of zero may be defined for any state image that is not required. If no bitmap is specified for the over state then the up image is used instead. If no bitmap is specified for the down state then the over image is used instead (if this was not specified then the up image will be used).

If a bitmap is specified for the disabled state then this will be used in full colour. If it is not then the up image will be used to create a normal disabled image.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLButtonBitmap, CButtonSSL::SetSSLButtonIcon, CButtonSSL::SetSSLButtonIcons

CButtonSSL::SetSSLButtonIcon

BOOL SetSSLButtonIcon (UINT nResourceID);

Return Value

Nonzero if successful; otherwise 0.

Parameters

nResourceID
The resource ID for the icon to be added.

Remarks

This function specifies a single icon to use for all states. The icon is copied into an image list. When the button is in the disabled state a disabled image is created from the specified icon.

The transparency defined in the source icon is preserved.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLButtonBitmap, CButtonSSL::SetSSLButtonBitmaps, CButtonSSL::SetSSLButtonIcons

CButtonSSL::SetSSLButtonIcons

BOOL SetSSLButtonIcons (UINT nUpID, UINT nOverID = 0, UINT nDownID = 0, 
UINT nDisabledID = 0);

Return Value

Nonzero if successful; otherwise 0.

Parameters

nUpID
The resource ID for the icon to be used for the up state.

nOverID
The resource ID for the icon to be used for the over state. This is zero by default.

nDownID
The resource ID for the icon to be used for the down state. This is zero by default.

nDisabledID
The resource ID for the icon to be used for the disabled state. This is zero by default.

Remarks

The up icon must be defined, however, a resource ID of zero may be defined for any state image that is not required. If no icon is specified for the over state then the up image is used instead. If no icon is specified for the down state then the over image is used instead (if this was not specified then the up image will be used).

If an icon is specified for the disabled state then this will be used in full colour. If it is not then the up image will be used to create a normal disabled image.

The transparency of the source icon is preserved.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLButtonBitmap, CButtonSSL::SetSSLButtonBitmaps, CButtonSSL::SetSSLButtonIcon

CButtonSSL::SetSSLImageAlign

void SetSSLImageAlign (UINT nImageAlign);

Parameters

nImageAlign
Specifies the image alignment style.

Remarks

A single horizontal and vertical alignment style may be specified, though there are no checks within the function to ensure that this is the case.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::GetSSLImageAlign

CButtonSSL::GetSSLImageAlign

UINT GetSSLImageAlign ();

Return Value

The button image alignment style.

Remarks

This function returns only the <A href="#AlignmentSTyles">SSL_IMAGE_</A> style values.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLImageAlign

CButtonSSL::SetSSLTextAlign

void SetSSLTexteAlign (UINT nTextAlign);

Parameters

nTextAlign
Specifies the text alignment style.

Remarks

A single horizontal and vertical alignment style may be specified, though there are no checks within the function to ensure that this is the case.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::GetSSLTextAlign

CButtonSSL::GetSSLTextAlign

UINT GetSSLTextAlign ();

Return Value

The button text alignment style.

Remarks

This function returns only the <A href="#AlignmentSTyles">SSL_TEXT_</A> style values.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLTextAlign

CButtonSSL::SetSSLButtonFont

BOOL SetSSLButtonFont (LPCTSTR lpszFaceName, int nSizePoints = 8, BOOL 
bUnderline = FALSE, BOOL bBold = FALSE, BOOL bStrikeOut = FALSE, BOOL bItalic = 
FALSE);

BOOL SetSSLButtonFont (CFont& font);

Return Value

Nonzero if successful; otherwise 0.

Parameters

lpszFaceName
The font face name.

nSizePoints
The font size in points. The default value is 8.

bUnderline
Specifies whether the font is to be underlined. A nonzero value sets the font to be underlined. A 0 value sets the font not to be underlined. The font is not underlined by default.

bBold
Specifies whether the font weight is to be bold or not. A nonzero value sets the font to be bold. A 0 value sets the font weight to be normal. The font weight is normal by default.

bStrikeOut
Specifies whether the font is to be struck out or not. A nonzero value sets the font to be struck out. A 0 value sets the font not to be struck out. The font is not struck out by default.

bItalic
Specifies whether the font style is to be italic or not. A nonzero value sets the font style to be italic. A 0 value sets the font style to be normal. The font style is normal by default.

font
A CFont object allowing full control over the appearance of the font.

Remarks

The first version of this function provides simple control over the main aspects of the button text font. If required the second version can be used to provide full control over the appearance of the button text font.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLTextAlign, CButtonSSL::GetSSLTextAlign

CButtonSSL::SetSSLDefaultColors

void SetSSLDefaultColors (BOOL bRedraw = TRUE);

Parameters

bRedraw
Specifies whether the button is to be redrawn. A nonzero value redraws the button. A 0 value does not redraw the button. The button is redrawn by default.

Remarks

Use this function to reset the button colours to their default values. The default values are the system colours COLOR_BTNFACE and COLOR_BTNTEXT.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLColor, CButtonSSL::GetSSLColor

CButtonSSL::SetSSLColor

BOOL SetSSLColor (BYTE byColorIndex, COLORREF crColor, BOOL bRedraw = 
TRUE);

Return Value

Nonzero if successful; otherwise 0.

Parameters

byColorIndex
Specifies the colour to be set. This is one of the colour values defined in the colour enumeration, except SSL_MAX_COLORS.

crColor
A COLORREF value specifying the colour to set.

bRedraw
Specifies whether the button is to be redrawn. A nonzero value redraws the button. A 0 value does not redraw the button. The button is redrawn by default.

Remarks

Use this function to set the button face or text colour for a particular button state.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::GetSSLColor, CButtonSSL::SetSSLDefaultColors

CButtonSSL::GetSSLColor

BOOL GetSSLColor (BYTE byColorIndex, COLORREF* pcrColor);

Return Value

Nonzero if byColorIndex is less than <A href="#ColourEnumeration">SSL_MAX_COLORS</A>; otherwise 0.

Parameters

byColorIndex
Specifies the colour to be retrieved. This is one of the colour values defined in the colour enumeration, except SSL_MAX_COLORS.

pcrColor
A pointer to a COLORREF value to be receive the requested colour value.

Remarks

Use this function to retrieve the current button face or text colour for a particular button state.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLColor, CButtonSSL::SetSSLDefaultColors

CButtonSSL::SetSSLCheck

void SetSSLCheck (int nCheck, BOOL bRedraw = TRUE);

Parameters

nCheck
Specifies the check state. This parameter can be either 0 (unchecked) or 1 (checked).

bRedraw
Specifies whether the button is to be redrawn. A nonzero value redraws the button. A 0 value does not redraw the button. The button is redrawn by default.

Remarks

Sets or resets the check state of a check box. This member function has no effect on a push button.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::GetSSLCheck

CButtonSSL::GetSSLCheck

int GetSSLCheck ();

Return Value

The return value is either 0 (unchecked) or 1 (checked).

Remarks

Retrieves the check state of a radio button or check box.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLCheck

CButtonSSL::SetSSLButtonMenu

BOOL SetSSLButtonMenu (UINT nResourceID);

BOOL SetSSLButtonMenu (LPCTSTR lpszResourceName);

Return Value

Nonzero if successful; otherwise 0.

Parameters

nResourceID
Specifies the menu ID of the menu resource to load.

lpszResourceName
Points to a null-terminated string that contains the name of the menu resource to load.

Remarks

Both of these functions use the first submenu in the supplied menu, assuming that it is a popup menu. For example, create a menu resource in the resource editor. Set the first menu item to be pop-up. Add subitems below this to be shown on the menu button.

The Windows message handling for the menu item selections must be handled by the parent, there is no mechanism for CButtonSSL to handle them.

Overview | Class Members | Styles | Known Problems

CButtonSSL::CheckSSLMenuItem

UINT CheckSSLMenuItem (UINT nIDCheckItem, UINT nCheck = MF_CHECKED);

Return Value

The previous state of the item: MF_CHECKED or MF_UNCHECKED, or 0xFFFFFFFF (MF_DOES_NOT_EXIST) if the menu item did not exist.

Parameters

nIDCheckItem
Specifies the menu item to be checked, as determined by nCheck.

nCheck
Specifies how to check the menu item and how to determine the item’s position in the menu. The nCheck parameter can be a combination of MF_CHECKED or MF_UNCHECKED with MF_BYPOSITION or MF_BYCOMMAND flags. These flags can be combined by using the bitwise OR operator. They have the following meanings:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.
  • MF_CHECKED Acts as a toggle with MF_UNCHECKED to place the default check mark next to the item.
  • MF_UNCHECKED Acts as a toggle with MF_CHECKED to remove a check mark next to the item.

Remarks

Adds check marks to or removes check marks from menu items in the pop-up menu. The nIDCheckItem parameter specifies the item to be modified.

The nIDCheckItem parameter may identify a pop-up menu item as well as a menu item. No special steps are required to check a pop-up menu item. Top-level menu items cannot be checked. A pop-up menu item must be checked by position since it does not have a menu-item identifier associated with it.

Overview | Class Members | Styles | Known Problems

CButtonSSL::CheckSSLMenuRadioItem

BOOL CheckSSLMenuRadioItem (UINT nIDFirst, UINT nIDLast, UINT nIDItem, 
  UINT nFlags);

Return Value

Nonzero if successful; otherwise 0.

Parameters

nIDFirst
Specifies (as an ID or offset, depending on the value of nFlags) the first menu item in the radio button group.

nIDLast
Specifies (as an ID or offset, depending on the value of nFlags) the last menu item in the radio button group.

nIDItem
Specifies (as an ID or offset, depending on the value of nFlags) the item in the group which will be checked with a radio button.

nFlags
Specifies interpretation of nIDFirst, nIDLast, and nIDItem in the following way:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

Remarks

Adds check marks to or removes check marks from menu items in the pop-up menu. The nIDCheckItem parameter specifies the item to be modified.

The nIDCheckItem parameter may identify a pop-up menu item as well as a menu item. No special steps are required to check a pop-up menu item. Top-level menu items cannot be checked. A pop-up menu item must be checked by position since it does not have a menu-item identifier associated with it.

Overview | Class Members | Styles | Known Problems

CButtonSSL::EnableSSLMenuItem

UINT EnableSSLMenuItem (UINT nIDEnableItem, UINT nEnable);

Return Value

Previous state (MF_DISABLED, MF_ENABLED, or MF_GRAYED), –1 if not valid or MF_DOES_NOT_EXIST if menu not initialised.

Parameters

nIDEnableItem
Specifies the menu item to be enabled, as determined by nEnable. This parameter can specify pop-up menu items as well as standard menu items.

nEnable
Specifies the action to take. It can be a combination of MF_DISABLED, MF_ENABLED, or MF_GRAYED, with MF_BYCOMMAND or MF_BYPOSITION. These values can be combined by using the bitwise OR operator. These values have the following meanings:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.
  • MF_DISABLED Disables the menu item so that it cannot be selected but does not dim it.
  • MF_ENABLED Enables the menu item so that it can be selected and restores it from its dimmed state.
  • MF_GRAYED Disables the menu item so that it cannot be selected and dims it.

Remarks

Enables, disables, or dims a menu item.

Using the MF_BYPOSITION value requires an application to use the correct CMenu. If the CMenu of the menu bar is used, a top-level menu item (an item in the menu bar) is affected. To set the state of an item in a pop-up or nested pop-up menu by position, an application must specify the CMenu of the pop-up menu.

When an application specifies the MF_BYCOMMAND flag, Windows checks all pop-up menu items that are subordinate to the CMenu; therefore, unless duplicate menu items are present, using the CMenu of the menu bar is sufficient.

Overview | Class Members | Styles | Known Problems

CButtonSSL::GetSSLMenuItemCount

UINT GetSSLMenuItemCount () const;

Return Value

The number of items in the menu if the function is successful; otherwise –1. MF_DOES_NOT_EXIST will be returned if the menu is not initialised.

Remarks

Determines the number of items in a pop-up or top-level menu.

Overview | Class Members | Styles | Known Problems

CButtonSSL::GetSSLMenuItemID

UINT GetSSLMenuItemID (int nPos) const;

Return Value

The item ID for the specified item in a pop-up menu if the function is successful. If the specified item is a pop-up menu (as opposed to an item within the pop-up menu), the return value is –1. If nPos corresponds to a SEPARATOR menu item, the return value is 0. If the menu is not yet initialised the value MF_DOES_NOT_EXIST will be returned.

Parameters

nPos
Specifies the position (zero-based) of the menu item whose ID is being retrieved.

Remarks

Obtains the menu-item identifier for a menu item located at the position defined by nPos.

Overview | Class Members | Styles | Known Problems

CButtonSSL::GetSSLMenuState

UINT GetSSLMenuState (UINT nID, UINT nFlags);

Return Value

The value MF_DOES_NOT_EXIST if the specified item does not exist or the menu is uninitialised. If nId identifies a pop-up menu, the high-order byte contains the number of items in the pop-up menu and the low-order byte contains the menu flags associated with the pop-up menu. Otherwise the return value is a mask (Boolean OR) of the values from the following list (this mask describes the status of the menu item that nId identifies):

  • MF_CHECKED Acts as a toggle with MF_UNCHECKED to place the default check mark next to the item. When the application supplies check-mark bitmaps (see the SetMenuItemBitmaps member function), the “check mark on” bitmap is displayed.
  • MF_DISABLED Disables the menu item so that it cannot be selected but does not dim it.
  • MF_ENABLED Enables the menu item so that it can be selected and restores it from its dimmed state. Note that the value of this constant is 0; an application should not test against 0 for failure when using this value.
  • MF_GRAYED Disables the menu item so that it cannot be selected and dims it.
  • MF_MENUBARBREAK Places the item on a new line in static menus or in a new column in pop-up menus. The new pop-up menu column will be separated from the old column by a vertical dividing line.
  • MF_MENUBREAK Places the item on a new line in static menus or in a new column in pop-up menus. No dividing line is placed between the columns.
  • MF_SEPARATOR Draws a horizontal dividing line. Can only be used in a pop-up menu. This line cannot be dimmed, disabled, or highlighted. Other parameters are ignored.
  • MF_UNCHECKED Acts as a toggle with MF_CHECKED to remove a check mark next to the item. When the application supplies check-mark bitmaps (see the SetMenuItemBitmaps member function), the “check mark off” bitmap is displayed. Note that the value of this constant is 0; an application should not test against 0 for failure when using this value.

Parameters

nID
Specifies the menu item ID, as determined by nFlags.

nID
Specifies the nature of nID. It can be one of the following values:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

Remarks

Returns the status of the specified menu item or the number of items in a pop-up menu.

Overview | Class Members | Styles | Known Problems

CButtonSSL::GetSSLMenuString

int GetSSLMenuString (UINT nIDItem, LPTSTR lpString, int nMaxCount, UINT nFlags);

int GetSSLMenuString (UINT nIDItem, CString& rString, UINT nFlags);

Return Value

Specifies the actual number of bytes copied to the buffer, not including the null terminator.

Parameters

nIDItem
Specifies the integer identifier of the menu item or the offset of the menu item in the menu, depending on the value of nFlags.

lpString
Points to the buffer that is to receive the label.

rString
A reference to a CString object that is to receive the copied menu string.

nMaxCount
Specifies the maximum length (in bytes) of the label to be copied. If the label is longer than the maximum specified in nMaxCount, the extra characters are truncated.

nFlags
Specifies the interpretation of the nIDItem parameter. It can be one of the following values:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

Remarks

Copies the label of the specified menu item to the specified buffer.

The nMaxCount parameter should be one larger than the number of characters in the label to accommodate the null character that terminates a string.

Overview | Class Members | Styles | Known Problems

CButtonSSL::GetSSLMenuItemInfo

BOOL GetSSLMenuItemInfo (UINT nIDItem, LPMENUITEMINFO lpMenuItemInfo, BOOL ByPos = FALSE);

Return Value

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, use the Win32 function GetLastError, as described in the Platform SDK.

Parameters

nIDItem
Identifier or position of the menu item to get information about. The meaning of this parameter depends on the value of ByPos.

lpMenuItemInfo
A pointer to a MENUITEMINFO, as described in the Platform SDK, that contains information about the menu.

rString
A reference to a CString object that is to receive the copied menu string.

ByPos
Value specifying the meaning of nIDItem. By default, ByPos is FALSE, which indicates that nIDItem is a menu item identifier. If ByPos is not set to FALSE, it indicates a menu item position.

Remarks

This member function implements the behavior of the of the Win32 function GetMenuItemInfo, as described in the Platform SDK.

Note that in the MFC implementation of GetMenuItemInfo, you do not use a handle to a menu.

Overview | Class Members | Styles | Known Problems

CButtonSSL::ModifySSLMenu

BOOL ModifySSLMenu (UINT nPosition, UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL);

BOOL ModifySSLMenu (UINT nPosition, UINT nFlags, UINT nIDNewItem, const CBitmap* pBmp);

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

nPosition
Specifies the menu item to be changed. The nFlags parameter can be used to interpret nPosition in the following ways:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

nFlags
Specifies how nPosition is interpreted and gives information about the changes to be made to the menu item.

nIDNewItem
Specifies either the command ID of the modified menu item or, if nFlags is set to MF_POPUP, the menu handle (HMENU) of a pop-up menu. The nIDNewItem parameter is ignored (not needed) if nFlags is set to MF_SEPARATOR.

lpszNewItem
Specifies the content of the new menu item. The nFlags parameter can be used to interpret lpszNewItem in the following ways:

  • MF_OWNERDRAW Contains an application-supplied 32-bit value that the application can use to maintain additional data associated with the menu item. This 32-bit value is available to the application when it processes MF_MEASUREITEM and MF_DRAWITEM.
  • MF_STRING Contains a long pointer to a null-terminated string or to a CString.
  • MF_SEPARATOR The lpszNewItem parameter is ignored (not needed).

pBmp
Points to a CBitmap object that will be used as the menu item.

Remarks

Changes an existing menu item at the position specified by nPosition. The application specifies the new state of the menu item by setting values in nFlags. If this function replaces a pop-up menu associated with the menu item, it destroys the old pop-up menu and frees the memory used by the pop-up menu.

When nIDNewItem specifies a pop-up menu, it becomes part of the menu in which it is inserted. If that menu is destroyed, the inserted menu will also be destroyed. An inserted menu should be detached from a CMenu object to avoid conflict.

Overview | Class Members | Styles | Known Problems

CButtonSSL::RemoveSSLMenu

BOOL RemoveSSLMenu (UINT nPosition, UINT nFlags);

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

nPosition
Specifies the menu item to be changed. The nFlags parameter can be used to interpret nPosition in the following ways:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

nFlags
Specifies how nPosition is interpreted.

Remarks

Deletes a menu item with an associated pop-up menu from the menu. It does not destroy the handle for a pop-up menu, so the menu can be reused.

Overview | Class Members | Styles | Known Problems

CButtonSSL::SetSSLMenuItemBitmaps

BOOL SetSSLMenuItemBitmaps (UINT nPosition, UINT nFlags, const CBitmap* pBmpUnchecked,
                                const CBitmap* pBmpChecked);

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

nPosition
Specifies the menu item to be changed. The nFlags parameter can be used to interpret nPosition in the following ways:

  • MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set.
  • MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

nFlags
Specifies how nPosition is interpreted.

pBmpUnchecked
Specifies the bitmap to use for menu items that are not checked.

pBmpChecked
Specifies the bitmap to use for menu items that are checked.

Remarks

Associates the specified bitmaps with a menu item. Whether the menu item is checked or unchecked, Windows displays the appropriate bitmap next to the menu item.

If either pBmpUnchecked or pBmpChecked is NULL, then Windows displays nothing next to the menu item for the corresponding attribute. If both parameters are NULL, Windows uses the default check mark when the item is checked and removes the check mark when the item is unchecked.

When the menu is destroyed, these bitmaps are not destroyed; the application must destroy them.

The Windows GetMenuCheckMarkDimensions function retrieves the dimensions of the default check mark used for menu items. The application uses these values to determine the appropriate size for the bitmaps supplied with this function. Get the size, create your bitmaps, then set them.

Overview | Class Members | Styles | Known Problems

CButtonSSL::SetSSLButtonCursor

BOOL SetSSLButtonCursor (UINT nResourceID);

Return Value

Nonzero if successful; otherwise 0.

Parameters

nResourceID
Specifies the cursor ID of the cursor resource to load.

Remarks

The cursor specified will be shown when the mouse is over any part of the button, including the drop-down arrow. The cursor will revert to it's previous state when the drop-arrow is clicked for navigation of the menu.

Overview | Class Members | Styles | Known Problems

CButtonSSL::SetSSLButtonTooltip

void SetSSLButtonToolTip (LPCTSTR lpszTipText, BOOL bActivate = 
TRUE);

void SetSSLButtonToolTip (UINT nResourceID, BOOL bActivate = 
TRUE);

Parameters

lpszTipText
Points to a null-terminated string containing the text to be displayed on the tooltip.

nResourceID
Specifies the resource ID of a string in the string table to be dispalyed on the tooltip.

bActivate
Specifies whether the tool tip is to be activated or deactivated. The tool tip is activated by default.

Remarks

When the tool tip is active (bActivate = TRUE), the tool tip information appears when the cursor hovered over the button; when it is inactive (bActivate = FALSE), the tool tip information does not appear, even when the cursor is hovered over the button.

Overview | Class Members | Styles | Known Problems

CButtonSSL::SetSSLButtonURL

void SetSSLButtonURL (LPCTSTR lpszURL);

Parameters

lpszURL
Points to a null-terminated string containing the URL to be opened when the button is clicked.

Remarks

Call this function to define a URL to be opened when the button is clicked. If a cursor has not already been defined for the button using SetSSLButtonCursor then this function attempts to load the hand cursor from WinHlp32.exe. This approach was detailed in Paul DiLascia's Jan 1998 MSJ article. If the runtime environment does not have WinHlp32.exe in the Windows directory then one can be defined and set using SetSSLButtonCursor.

Overview | Class Members | Styles | Known Problems

See Also CButtonSSL::SetSSLButtonCursor

Button Styles

  • SSL_BS_FLAT Creates a button with a flat appearance. When the mouse is over the button it will be raised, but not to the extent of a normal 3D control. The default style.
  • SSL_BS_MENU_BTN Creates a button with a drop-arrow at the right side of the button. A menu may be assigned to the object to be displayed when the drop part is clicked.
  • SSL_BS_AUTOSIZE Creates a button that automatically sizes to fit it's contents. This style will not prevent the button image and the button text from overlapping.

Alignment Styles

  • SSL_TEXT_TOP Aligns the text vertically to the top of the button.
  • SSL_TEXT_LEFT Aligns the text horizontally to the left of the button.
  • SSL_TEXT_CENTER Aligns the text horizontally to the centre of the button. The default style.
  • SSL_TEXT_RIGHT Aligns the text horizontally to the right of the button.
  • SSL_TEXT_VCENTER Aligns the text vertically to the centre of the button. The default style.
  • SSL_TEXT_BOTTOM Aligns the text vertically to the bottom of the button.

Only one horizontal and one vertical style should be set for the text alignment.

  • SSL_IMAGE_TOP Aligns the button image vertically to the top of the button. The default style.
  • SSL_IMAGE_LEFT Aligns the button image horizontally to the left of the button. The default style.
  • SSL_IMAGE_CENTER Aligns the button image horizontally to the centre of the button.
  • SSL_IMAGE_RIGHT Aligns the button image horizontally to the right of the button.
  • SSL_IMAGE_VCENTER Aligns the button image vertically to the centre of the button.
  • SSL_IMAGE_BOTTOM Aligns the button image vertically to the bottom of the button.

Only one horizontal and one vertical style should be set for the button image alignment.

Colour Enumeration

  • SSL_UP_BK_COLOR The button colour to use when the button is in the up state.
  • SSL_UP_TEXT_COLOR The text colour to use when the button is in the up state.
  • SSL_OVER_BK_COLOR The button colour to use when the button is in the over state.
  • SSL_OVER_TEXT_COLOR The text colour to use when the button is in the overstate.
  • SSL_DOWN_BK_COLOR The button colour to use when the button is in the down state.
  • SSL_DOWN_TEXT_COLOR The text colour to use when the button is in the down state.
  • SSL_MAX_COLORS Defines the maximum number of colours that can be defined.

Constants

  • SSL_MASK Defined as
    RGB (<span class=cpp-literal 
      >255, <span class=cpp-literal 
      >0, <span class=cpp-literal 
      >255)

Known Problems

As far as I know there aren't any. If you find any let me know.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSSLButton intercepts focus Pin
aaandrei23-Apr-04 4:02
aaandrei23-Apr-04 4:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.