Re: Catching button pressed messages
- From: "Tom Serface" <tserface@xxxxxxx>
- Date: Tue, 26 Sep 2006 08:41:23 -0700
Ah, that makes sense.
You may want to take a look at a CCheckBox with BS_PUSHLIKE style set. I
don't know if this would work for you, but since you want to know if the
button is clicked either way it may be interesting:
http://msdn2.microsoft.com/en-us/library/tf9hd91s.aspx
You can set this in the properties for a checkbox. Like I said, I don't
know if this would work for you, but it is an intersting UI.
Tom
"JoeB" <joe@xxxxxxxxxx> wrote in message
news:etXD3DY4GHA.2464@xxxxxxxxxxxxxxxxxxxxxxx
I needed to send a message when the button changes state, so just detecting
button down was not enough. The BM_SETSTATE message was sent when ever the
change occurs, so was the simplist solution.
I figured that the extra message when the button is clicked normally could
be stopped if i handled the OnLButtonUp message, and just released the
mouse capture, and did NOT call the base implimentation.
It seems to work, but not calling the base implimentation, i cant figure
out why the button redraws correctly?
the redraw must have been called from a different handler somewhere in the
CButton class.
J
Tom Serface wrote:
Oops. Sorry, I didn't see that you'd figured out a solution. However,
you may still want to take a look at this post. It seems to me that
detecting the WM_LBUTTONDOWN would be an easier solution. You could just
replace CButton in your dialog with your derived class name
CButtonPressed (for example).
http://www.codeguru.com/forum/archive/index.php/t-51872.html
Tom
"JoeB" <joe@xxxxxxxxxx> wrote in message
news:enUbugX4GHA.512@xxxxxxxxxxxxxxxxxxxxxxx
Hi
I decided to sub-classed the button, and handled the buttons OnWndMsg
method looking for the BM_SETSTATE message.
When found, i compared the state value with the previous value set in
OnWndMsg (stored as a member variable in my sub-class), and if the value
is different (state has changed) i send BN_CLICKED to the parent and
update the variable.
--- CODE ---
BOOL CButtonSubClass::OnWndMsg(UINT message, WPARAM wParam, LPARAM
lParam, LRESULT* pResult)
{
// If the state has changed, tell the parent.
if( message == BM_SETSTATE )
{
if( wParam != m_wLastState ) // State has changed.
{
m_wLastState = wParam;
// Manually update the state.
CButton::SetState(wParam ? true : false);
// Send message to parent informing of the change.
GetParent()->SendMessage(WM_COMMAND, MAKELONG(GetDlgCtrlID(),
BN_CLICKED), (LPARAM)m_hWnd);
*pResult = 0;
return 0;
}
}
return CButton::OnWndMsg(message, wParam, lParam, pResult);
}
------------
This allows me to receive button click events each time the button state
changed from down-->up, or up-->down.
In the parent OnButtonClicked handler, i then GetState() and look for
BST_PUSHED to determine if the button is up or down.
--- CODE ---
void CParentClass::OnBnClickedButton1()
{
bool bPressed = (m_Button.GetState() & BST_PUSHED) ? true : false;
}
------------
When the button is actually clicked normally, i receive two BN_CLICKED
messages, both reporting the button is 'up' but that doesn't really
matter too much, i can live with that.
Cheers all..
J
Jeff Partch wrote:
"JoeB" <joe@xxxxxxxxxx> wrote in message
news:OrmlLvU4GHA.512@xxxxxxxxxxxxxxxxxxxxxxx
Hi,Yes, that's so you can start to click a button and the change your mind
I need to detect the pressing of a button. A standard button.
OnBnClicked appears to only be fired when the button is released, and
by moving the mouse off of it before you release it.
OnLButtonDown does not appear to be fired at all if pressing a button.WM_LBUTTONDOWN will be sent to the button itself. To handle it you'll
need to map it in a subclass. Or... if you can arrange for this button
to be created without the WS_EX_NOPARENTNOTIFY extended window style,
you can handle the WM_PARENTNOTIFY message in the parent. Remember
though that a button can be pressed with the keyboard too.
Anyone think of a different message that i need to handle?A rather wild idea: Handle WM_CTLCOLOR and -- when it's sent by the
button of interest, send it a BM_GETSTATE and look for BST_PUSHED.
.
- References:
- Catching button pressed messages
- From: JoeB
- Re: Catching button pressed messages
- From: Jeff Partch
- Re: Catching button pressed messages
- From: JoeB
- Re: Catching button pressed messages
- From: Tom Serface
- Re: Catching button pressed messages
- From: JoeB
- Catching button pressed messages
- Prev by Date: Re: dialogs cannot be moved
- Next by Date: Re: Events and messages and two different classes
- Previous by thread: Re: Catching button pressed messages
- Next by thread: Re: Catching button pressed messages
- Index(es):
Relevant Pages
|