From: rahul on
I deleted OK and Cancel button from standard MFC dialog box
application.

I am creating one button dynamically (through calling Create()
function ) in OnInitDialog() function. with BS_DEFPUSHBUTTON style.
There is no other button of this style in dialog box.

but when i press enter dialog box closes due to calling
OnBnClickedOk() (OK button handler, even though OK button is not in
the dialog box) ..

In short , handler of button which i have created with
BS_DEFPUSHBUTTON style is not called. Why??



From: Mikel on
On 4 jun, 12:08, rahul <hyrahu...(a)gmail.com> wrote:
> I deleted OK and Cancel button from standard MFC dialog box
> application.
>
> I am creating one button dynamically (through calling Create()
> function ) in OnInitDialog() function. with BS_DEFPUSHBUTTON style.
> There is no other button of this style in dialog box.
>
> but when i press enter dialog box closes due to calling
> OnBnClickedOk() (OK button handler, even though OK button is not in
> the dialog box) ..
>
> In short , handler of button which i have created with
> BS_DEFPUSHBUTTON style is not called. Why??

By default, pressing enter calls the handler for IDOK (which is the ID
for the OK button), so if you don't want it to close the dialog, you
have to override it and comment out the call CDialog::OnOK() there.
The same happens with IDCANCEL and the escape key
From: Joseph M. Newcomer on
See below...
On Fri, 4 Jun 2010 03:08:33 -0700 (PDT), rahul <hyrahul64(a)gmail.com> wrote:

>I deleted OK and Cancel button from standard MFC dialog box
>application.
>
>I am creating one button dynamically (through calling Create()
>function ) in OnInitDialog() function. with BS_DEFPUSHBUTTON style.
>There is no other button of this style in dialog box.
****
Why? What's wrong with the dialog editor for doing this? I'll bet you actually gave
*constant values* for the button position and dimensions, which is, of course, always an
error.

Note that the dialog editor exists to create controls for you, and any attempt on your
part to do so with Create() requires you deal with *all* the implications of creating an
object, which is to see that it is the correct size on EVERY POSSIBLE MACHINE it might be
running on, with every conceivable graphics card, every version of a graphics driver,
every possible screen size and resolution, and every possible default font setting the
user might choose. This happens automatically if you create the control in the dialog
editor. It takes a lot of work if you do it in OnInitDialog. So why do you feel you have
to do a Create() in the OnInitDialog?
****
>
>but when i press enter dialog box closes due to calling
>OnBnClickedOk() (OK button handler, even though OK button is not in
>the dialog box) ..
****
Did you call the SetDefID() function to set the button to be ACTUALLY a default pushbutton
(not just look like one, which is all the style bit does!)

If you hit enter, and you have NOT called SetDefID, then a WM_COMMAND:IDOK is generated by
default. If you hit ESC, a WM_COMMAND:IDCANCEL is generated by default. Generally, you
want to create OnOK and OnCancel virtual handlers with no bodies to avoid any potential
confusion.
****
>
>In short , handler of button which i have created with
>BS_DEFPUSHBUTTON style is not called. Why??
>
****
Because it is not the default pushbutton, it just *looks* like one!
joe
***
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm