Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checkbox and Spacebar press

3 views
Skip to first unread message

Daniel Chambers

unread,
Oct 13, 2004, 10:26:47 AM10/13/04
to
Hey!
I have a checkbox on my dialog (CButton) and I have it set up so when it
is checked\unchecked it disables enables a editbox.
When you click on the checkbox with the mouse, the BN_CLICKED message is
successfully sent and my handler function is run and the editbox is
disabled/enabled.
However, when you press spacebar to change the state of the checkbox,
BN_CLICKED is not sent (but the state of checkbox is changed) and my
handler function is not run. BUT, if you move the mouse in the dialog at
the same as pressing the spacebar, the BN_CLICKED message IS sent and my
handler function runs. What's up with this?
I used Spy++ and checked for whether WM_KEYUP messages were being sent
when the spacebar is pressed. They are.
Unfortunately, Visual C++ doesnt seem to have an Event Handler
(specifically for my checkbox) for the WM_KEYUP message. So I need
BN_CLICKED to work with spacebar when the mouse isnt moving.
Any ideas? (If you need more information please ask)

Thanks in advance,
Daniel Chambers

--

M

unread,
Oct 13, 2004, 6:00:23 PM10/13/04
to
If you need to intercept the WM_KEYUP message for your control you could:

1. Derive a class from CButton, override the WM_KEYUP message in your
derived class.
or
2. Trap the WM_KEYUP Message in your dialog's PreTranslateMessage (which
would probable be easier if all you are enabling or disabling things).

M

"Daniel Chambers" <kyle...@hotmail.com> wrote in message
news:opsftbqx...@phoenix-ii.vic.optushome.com.au...

Sergey Kochkarev

unread,
Oct 14, 2004, 3:47:14 AM10/14/04
to
"Daniel Chambers" <kyle...@hotmail.com> wrote in message news:<opsftbqx...@phoenix-ii.vic.optushome.com.au>...

Try ON_COMMAND. Implement it in a dialog class that contains the button:

in h:

class MyDialog
{

....
// Generated message map functions
//{{AFX_MSG(SelectAddressDialog)
//}}AFX_MSG
afx_msg void OhMyButtonPressedOrClicked();
DECLARE_MESSAGE_MAP()
};

in cpp:

BEGIN_MESSAGE_MAP( MyDialog, CDialog )
//}}AFX_MSG_MAP
ON_COMMAND( ID_MYBUTTON, OhMyButtonPressedOrClicked )
END_MESSAGE_MAP( )

void MyDialog::OhMyButtonPressedOrClicked()
{
::MessageBox("Well, this guy from the internet is right");
}

Greetings!

Daniel Chambers

unread,
Oct 15, 2004, 9:47:01 AM10/15/04
to
Thanks to both of you for your help! I learnt something new from both
of you (which I will use somewhere else), but I found the solution to
my problem: i wasn't checking the state of the checkbox with a mask!!

eg. (For people who read this)

CButton m_CtrlCheck;
if (m_CtrlCheck.GetState() == 521) {} //WRONG!!
if (m_CtrlCheck.GetState() & 0x0001) {} //Right!! Use a mask!

Thanks again!

koch...@pisem.net (Sergey Kochkarev) wrote in message news:<c882495.04101...@posting.google.com>...

0 new messages