Re: Dynamically created default CButton
- From: "Timothy Dean" <tim.dean@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 13 Apr 2007 09:23:22 -0600
Both:
If the visible button is the default button, it will trigger when the
Enter key is pressed. If it is not the default, or not present, the
button in the upper right will trigger when the Enter key is pressed.
For some reason, default buttons that are created at run time using Create
and the BS_DEFPUSHBUTTON style do not work like normal default buttons
created with the resource editor. When you press enter, the default button
will not fire. Instead the OnOk message is fired. That is what is causing
this challenge. If the default button would work like it is supposed to (as
it does when it is created with the dialog editor), it wouldn't be a
problem. So now I need to "roll my own" default button handler which is a
challenge since the DM_GETDEFID message doesn't work either.
Timothy Dean
<r_z_aret@xxxxxxxxxxxx> wrote in message
news:604t131tkfibv2ibeogo8iiop6kaqupmr6@xxxxxxxxxx
On Thu, 12 Apr 2007 09:02:50 -0600, "Timothy Dean"
<tim.dean@xxxxxxxxxxxxxxxxxxx> wrote:
I am talking about the OK button that you can optionally display in the
upper right corner of the app in addition to, or replacing the X button.
If
a user clicks on that button, it will fire the OnOK message. If there was
a
default button on the page, I need to make sure NOT to fire the default
button. If they hit enter on that page, as long as some other button
doesn't have focus, the same OnOK message will fire. In that case, I need
to search the page for a default button and execute that action. I could
do
some special handling in PreTranslateMessage, but this is definately not
my
prefered approach. Using OnOK is really not the prefered approach for
this
either.
The right approach is to use the DM_GETDEFID message which was created for
this very purpose. Windows will fire this message when it needs to know
if
I don't use MFC. So I'll answer in straight Win32 and then try to
translate in MFC.
Straight Win32
Leave the button in the upper right corner and its handler alone. If
another button is visible, make sure it has a unique Control ID. Then
handle WM_COMMAND messages for that Control ID.
MFC
Leave the button in the upper right corner and its handler alone. If
another button is visible, make sure its ID isn't IDOK, and assign a
separate handler to it.
Both:
If the visible button is the default button, it will trigger when the
Enter key is pressed. If it is not the default, or not present, the
button in the upper right will trigger when the Enter key is pressed.
Timothy Dean
"Dan McCarty" <dmccarty@xxxxxxxxx> wrote in message
news:1176328921.184618.24530@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 6, 10:12 am, "Timothy Dean" <tim.d...@xxxxxxxxxxxxxxxxxxx>
wrote:
There is a message that is supposed to handle this,
DM_GETDEFID. This message will be sent to the parent window asking for
the
default button ID. This works great in Windows, but doesn't seem to
fire
at
all in CE or Pocket PC. Any ideas? Thanks.
Sorry, I was offline for a few days.
You could always use PreTranslateMessage() to catch the Enter key
yourself and handle that case, but I don't usually recommend doing
this unless you have a really good reason. You haven't shared all
your details for doign this, but why do you want different behavior
between a click and a keypress? You will confuse your users.
-Dan.
"Dan McCarty" <dmcca...@xxxxxxxxx> wrote in message
news:1175805421.564646.170550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 3, 5:37 pm, "Timothy Dean" <tim.d...@xxxxxxxxxxxxxxxxxxx>
wrote:
When I dynamically create a CButton (using Create) and set its style
to
BS_DEFPUSHBUTTON, it doesn't receive the OnButtonClick when the
Enter
key
is
pressed. It always sends the IDOK command through.
Because when you dynamically create the button you haven't let MFC
define the MESSAGE_MAP like it does when you create the button in the
resource editor.
Just handle IDOK in a switch statement in your OnCommand or OnCmdMsg
handlers and call OnButtonClick(), which is what MFC is doing anyway.
-Dan.
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and
please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com
.
- References:
- Dynamically created default CButton
- From: Timothy Dean
- Re: Dynamically created default CButton
- From: Dan McCarty
- Re: Dynamically created default CButton
- From: Timothy Dean
- Re: Dynamically created default CButton
- From: Dan McCarty
- Re: Dynamically created default CButton
- From: Timothy Dean
- Re: Dynamically created default CButton
- From: r_z_aret
- Dynamically created default CButton
- Prev by Date: Get an error RC2104 : undefined keyword or key name: TBS_AUTOTICKS when I try to change anything resource editor
- Next by Date: Re: Change the UI-Language display from English to Czech/Polish/Hu
- Previous by thread: Re: Dynamically created default CButton
- Next by thread: How to get character set category of mail body on CrossBow
- Index(es):