![]() |
|
QA: Why doesn't my CButton work right?
By Michael Wolraich, September 21, 2001.
QuestionWhen I click I cannot press my button. If I press on the button then move stylus out of the button and then back then the button is pressed. What is wrong? AnswerYou may have noticed that when you create an MFC CButton on the Pocket PC, it doesn't highlight properly when you press it, and it doesn't always send a BN_CLICKED notification that it has been pressed. Actually, if you press and release quickly, it works fine, but if you press and hold, it un-highlights and fails to send a notification. Such erratic behavior occurs because of a bug (feature?) in Microsoft's implementation of CWnd::OnLButtonDown(). If you look in mfc/src/wincore.cpp, you'll notice the following snippet: This method, inherited by CButton, causes two problems. First, SHRecognizeGesture() call delays the normal highlight behavior of the button. Second, when the user presses the button and holds it, SHRecognizeGesture() returns TRUE. That causes the default behavior to be skipped so that the BN_CLICKED notification is never sent when the button is released. Happily, there is a simple workaround. Just create a new class that inherits from CButton and overwrites CButton::OnLButtonDown() as follows: or if you need to keep the SHRecognizeGesture() functionality around: Similar problems may occur with other MFC controls that use OnLButtonDown(). They can be worked around in a similar manner. SampleYou can download a sample application (10 Kb) that shows working of different type of buttons (with bug, without bug, etc). DiscussDiscuss this article. Here you can write your comments and read comments of other developers. |
|||||||||||||||||||||