Click here to Skip to main content
Licence 
First Posted 11 Sep 2000
Views 42,816
Bookmarked 21 times

WTL - Button Menu 2

By | 17 Mar 2001 | Article
Use of a Push button with a drop down menu

Updated 18 march 2001. Now with keyboard and focus cues (only for W2k/Me)

  • Download source files - 4 Kb
  • Download demo project - 16.5 Kb
  • Sample Image - MenuBtn.gif

    Introduction

    This code was based on articles written by Norm Almond and David Peterson.

    Why a new one? I needed a menu button that acts exactly like a pushbutton. I believe I have done it.

    Nevertheless, my button is not as cool as Norm Almond's is. I mean, there is no code for displaying a bitmap. Feel free to add it yourself or borrow it from Norm Almond's article.

    Implementation

    I have developed two classes: CMenuButton and CAutoMenuButton. CAutoMenuButtonM is the same button as CMenuButton, but adds its caption as the first and default menu item. Useful behavior, isn't it?

    How To Use

    First of all, make your parent class support reflection of notification messages:

    BEGIN_MSG_MAP(CMainDlg)
       MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
       COMMAND_ID_HANDLER(IDOK, OnOK)
       COMMAND_RANGE_HANDLER(ID_FILE_NEW, ID_FILE_CLOSE, OnFileCmd)
       <U>REFLECT_NOTIFICATIONS()</U>
    END_MSG_MAP()

    Then, declare your buttons:

       WTLEX::CAutoMenuButton   m_ctlOK;
       WTLEX::CMenuButton       m_ctlButtons[4];

    And assign it an ID:

       m_ctlOK = GetDlgItem(IDOK);
    
       for(int i = 0; i < 4; i++)
       {
          m_ctlButtons[i] = GetDlgItem(IDC_NORMAL + i); 
          m_ctlButtons[i].SetMenuID(IDR_BTNMENU);
       }

    SetMenuID does not need to be called when you supply it in the constructor:

       CMainDlg() : m_ctlOK(IDR_BTNMENU)
       {
       }

    That's all :)

    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

    Paul Bludov



    Russian Federation Russian Federation

    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
    -- There are no messages in this forum --
    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.5.120517.1 | Last Updated 18 Mar 2001
    Article Copyright 2000 by Paul Bludov
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid