Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC Question - How can I tell if a button has been pressed, not a specific button, but just the event of a button press?

MFC Question - How can I tell if a button has been pressed, not a specific button, but just the event of a button press?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skyapie
    wrote on last edited by
    #1

    Is there any message that gets posted on event of a button press? The ON_BN_CLICKED is used for specific buttons and that message gets sent if the specific button is pressed. If I have a dialog with 10 buttons, and I want to know if a button got pressed (any button, it doesn't matter which), how do I do this? Thanks, skyapie :)

    R N S 3 Replies Last reply
    0
    • S skyapie

      Is there any message that gets posted on event of a button press? The ON_BN_CLICKED is used for specific buttons and that message gets sent if the specific button is pressed. If I have a dialog with 10 buttons, and I want to know if a button got pressed (any button, it doesn't matter which), how do I do this? Thanks, skyapie :)

      R Offline
      R Offline
      Rinu_Raj
      wrote on last edited by
      #2

      Derive a class say ButtonEx from CButton and over ride DrawItem( LPDRAWITEMSTRUCT lpDIS ) Create buttons as the object of ButtonEx ButtonEx::DrawItem( LPDRAWITEMSTRUCT lpDIS ) { if(( lpDIS->itemState & ODS_SELECTED )) { // means buton is clicked } }

      S A 2 Replies Last reply
      0
      • S skyapie

        Is there any message that gets posted on event of a button press? The ON_BN_CLICKED is used for specific buttons and that message gets sent if the specific button is pressed. If I have a dialog with 10 buttons, and I want to know if a button got pressed (any button, it doesn't matter which), how do I do this? Thanks, skyapie :)

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        u will receive a WM_COMMAND message(OnCommand) when any button is pressed. Also check the HIWORD of the wParam is BN_CLICKED to ensure that the message has arrived due to a button click.

        nave

        1 Reply Last reply
        0
        • S skyapie

          Is there any message that gets posted on event of a button press? The ON_BN_CLICKED is used for specific buttons and that message gets sent if the specific button is pressed. If I have a dialog with 10 buttons, and I want to know if a button got pressed (any button, it doesn't matter which), how do I do this? Thanks, skyapie :)

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Handle the BN_CLICK notification in the parent window. This notification is packaged as a WM_COMMAND message.

          Steve

          S 2 Replies Last reply
          0
          • R Rinu_Raj

            Derive a class say ButtonEx from CButton and over ride DrawItem( LPDRAWITEMSTRUCT lpDIS ) Create buttons as the object of ButtonEx ButtonEx::DrawItem( LPDRAWITEMSTRUCT lpDIS ) { if(( lpDIS->itemState & ODS_SELECTED )) { // means buton is clicked } }

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            This is a very strange way of going about things. The code in question will fire every time a clicked button is rendered and not just once when it's clicked.

            Steve

            R 1 Reply Last reply
            0
            • S Stephen Hewitt

              This is a very strange way of going about things. The code in question will fire every time a clicked button is rendered and not just once when it's clicked.

              Steve

              R Offline
              R Offline
              Rinu_Raj
              wrote on last edited by
              #6

              Thank you for pointing out I was only thinking about getting the selection status. My solution was poor.

              1 Reply Last reply
              0
              • S Stephen Hewitt

                Handle the BN_CLICK notification in the parent window. This notification is packaged as a WM_COMMAND message.

                Steve

                S Offline
                S Offline
                skyapie
                wrote on last edited by
                #7

                Thanks! It worked :-D

                1 Reply Last reply
                0
                • S Stephen Hewitt

                  Handle the BN_CLICK notification in the parent window. This notification is packaged as a WM_COMMAND message.

                  Steve

                  S Offline
                  S Offline
                  skyapie
                  wrote on last edited by
                  #8

                  Hi again, thanks for the reply last time.... Do you know how to do the same thing for the events where the user moves a scroll bar or clicks in a list box/list control? I couldn't get it to work using the OnCommand method, so I used OnNotify. See code here... BOOL CBaseFormView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { NMHDR* pNMHDR = (NMHDR*)lParam; /* ** I have no clue what 0xFFFFFF4 is.... it just seems to be the value that gets posted ** when the user scrolls. */ if(pNMHDR->code == 0xFFFFFFF4) { AsyncServicesUpdateInactivityTimer(this->m_hWnd); } return CFormView::OnNotify(wParam, lParam, pResult); } Except I'm not sure what the notification codes for selecting something within a list box or list control, or moving the scrollbar are. Thanks again Skyapie :-D

                  S 1 Reply Last reply
                  0
                  • S skyapie

                    Hi again, thanks for the reply last time.... Do you know how to do the same thing for the events where the user moves a scroll bar or clicks in a list box/list control? I couldn't get it to work using the OnCommand method, so I used OnNotify. See code here... BOOL CBaseFormView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { NMHDR* pNMHDR = (NMHDR*)lParam; /* ** I have no clue what 0xFFFFFF4 is.... it just seems to be the value that gets posted ** when the user scrolls. */ if(pNMHDR->code == 0xFFFFFFF4) { AsyncServicesUpdateInactivityTimer(this->m_hWnd); } return CFormView::OnNotify(wParam, lParam, pResult); } Except I'm not sure what the notification codes for selecting something within a list box or list control, or moving the scrollbar are. Thanks again Skyapie :-D

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #9

                    The WM_HSCROLL and WM_VSCROLL messages are sent when scrolling occurs in a Window's standard scroll bar. When the user clicks in a control it depends on the control. For example List View controls send the NM_CLICK notification.

                    Steve

                    1 Reply Last reply
                    0
                    • R Rinu_Raj

                      Derive a class say ButtonEx from CButton and over ride DrawItem( LPDRAWITEMSTRUCT lpDIS ) Create buttons as the object of ButtonEx ButtonEx::DrawItem( LPDRAWITEMSTRUCT lpDIS ) { if(( lpDIS->itemState & ODS_SELECTED )) { // means buton is clicked } }

                      A Offline
                      A Offline
                      ANIL KUMAR SHARMA INDIA
                      wrote on last edited by
                      #10

                      I like to autosize the owner draw button depending upon the text that it load dynamically based on localization strings. so some strings are large than others. Keeping this I override DrawItem in the inherited class from CButton. The sample code is below void CMyGraphicButton::DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct) { CString cs; CString cslong; ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData; if (!lpszText || lpszText == (LPCTSTR)-1) { GetWindowText (cs); } else cs = lpszText; // now i m trying to resize , so let try to increase the size of button unconditioally // I get //lpDrawItemStruct>rcItem.left =0 //lpDrawItemStruct>rcItem.right =75 //lpDrawItemStruct>rcItem.top = 0 //lpDrawItemStruct>rcItem.bottom = 25 //As my button is on extreme right side of dialog so i tried to extend/increase the size of // button of the left side as follows lpDrawItemStruct>rcItem.left -= 25 ; // but the above causes the text to be moved on right side insead of resize/increase the //button size. Any idea or help is appriciated. Thanks Anil }

                      [AKS]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups