Click here to Skip to main content
Licence 
First Posted 5 Nov 2002
Views 63,572
Downloads 1,272
Bookmarked 24 times

WTL Button Menu Class

By Rob Caldecott | 5 Nov 2002
Add a button that displays a menu when clicked to your WTL application

1
1 vote, 14.3%
2

3
1 vote, 14.3%
4
5 votes, 71.4%
5
4.46/5 - 13 votes
μ 4.46, σa 1.98 [?]

Sample Image - WTLButtonMenu.jpg

Introduction

A small CButton-derived class that will display a popup menu when clicked. Easy to use and very handy for dialog based application.

Using CButtonMenu

To use this class with a WTL dialog, first include the header file in the MainDlg.h file:

#include "buttonmenu.h"

Next, add a CButtonMenu object to the class:

CButtonMenu m_wndButtonMenu;

Next (and this is important), add a REFLECT_NOTIFICATIONS() call to your dialogs message map (else the button won't get the BN_CLICKED notification message):

BEGIN_MSG_MAP(CMainDlg)
    ...
    REFLECT_NOTIFICATIONS()
END_MSG_MAP()

Now subclass an existing button control and set the popup menu that you want displayed in your dialogs OnInitDialog function:

// Create button menu
m_wndButtonMenu.SubclassWindow(GetDlgItem(IDC_BUTTON1));
// Set the menu ID that the button displays
m_wndButtonMenu.SetMenu(IDR_POPUP);

Finally, add the necessary COMMAND_ID_HANDLERs for your popup menu commands.

That's it! The button will be displayed with an arrow (using the Marlett font if available), and will display a popup menu when clicked.

Notes

When designing a dialog-box that uses this class, instead of using a normal button control, use a checkbox control that has the "Push like" style-bit set. The advantage of using a checkbox is that the button will stay pushed whilst the popup menu is displayed (see the example project for more details)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Rob Caldecott

Architect

United Kingdom United Kingdom

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMarlett Arrow PinmemberArmen Hakobyan9:58 24 Mar '04  
GeneralRe: Marlett Arrow PinmemberRobert Edward Caldecott5:09 25 Mar '04  
GeneralRe: Very nice, what about the dialog look? PinmemberRobert Edward Caldecott23:05 17 Feb '03  
GeneralVC6.0 AtlInitCommonControls missing PinmemberMartin Holzherr7:18 6 Nov '02  
GeneralRe: VC6.0 AtlInitCommonControls missing PinmemberRobert Edward Caldecott7:38 6 Nov '02  
GeneralRe: VC6.0 AtlInitCommonControls missing PinmemberRobert Edward Caldecott7:39 6 Nov '02  
GeneralNice PinmemberAnatoly Ivasyuk5:32 6 Nov '02  
GeneralRe: Nice PinmemberRobert Edward Caldecott5:37 6 Nov '02  
GeneralRe: Nice PinsupporterPaul Selormey14:39 6 Nov '02  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120209.1 | Last Updated 6 Nov 2002
Article Copyright 2002 by Rob Caldecott
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid