MFC Question - How can I tell if a button has been pressed, not a specific button, but just the event of a button press?
-
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 :)
-
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 :)
-
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 :)
-
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 :)
Handle the
BN_CLICK
notification in the parent window. This notification is packaged as aWM_COMMAND
message.Steve
-
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 } }
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
-
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
-
Handle the
BN_CLICK
notification in the parent window. This notification is packaged as aWM_COMMAND
message.Steve
-
Handle the
BN_CLICK
notification in the parent window. This notification is packaged as aWM_COMMAND
message.Steve
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 -
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 :-DThe
WM_HSCROLL
andWM_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 theNM_CLICK
notification.Steve
-
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 } }
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]