Click to See Complete Forum and Search --> : I need a boring dialog
Alex Rest
August 23rd, 2004, 05:48 AM
I want to create a boring dialog box that changes placement of buttons. For example, as the trial dialog of WizZip. I easy mix buttons, but cannot change default button. It is always #1 in the tab stop set. I tried SetFocus, NextDlgCtrl and SetDefID in InitDialog. No effects. Who have an idea?
sbubis
August 23rd, 2004, 06:45 AM
Handle WM_INITDIALOG in your dlgproc as follows:
case WM_INITDIALOG:
... Some initialization code
SetFocus (GetDlgItem (hWnd, IDC_BTN_YOU_WANT_TO_BE_DEFAULT));
return FALSE;
It is written in MSDN explaining WM_INITDIALOG message.
:wave:
Bond
August 23rd, 2004, 08:15 AM
A button with the BS_DEFPUSHBUTTON style will be selected when you press Enter in a dialog box. You will need to add this style to the button you wish to make your default in WM_INITDIALOG. Also, you should remove the style from the other buttons.
For example:
// Set button one to the default...
SendMessage(hwndButton1, BM_SETSTYLE, BS_DEFPUSHBUTTON, FALSE);
sbubis
August 23rd, 2004, 08:57 AM
A button with the BS_DEFPUSHBUTTON style will be selected when you press Enter in a dialog box. You will need to add this style to the button you wish to make your default in WM_INITDIALOG. Also, you should remove the style from the other buttons.
For example:
// Set button one to the default...
SendMessage(hwndButton1, BM_SETSTYLE, BS_DEFPUSHBUTTON, FALSE);
Yes, of course.
Alex Rest
August 23rd, 2004, 11:59 AM
Yes, it works. New button works as default.
But I have other problem. Selection rechatngle
disappears from old button and does not appear at new button.
I be glad to have comments to this problem too.
Thanks.
RussG1
August 23rd, 2004, 12:03 PM
That rectangle is the focus rectangle, which indicates which button currectly has the focus. Changing the default button does not change the focus, and will have to be done manually to move the focus to the new default button.
Alex Rest
August 23rd, 2004, 12:19 PM
No. SetFocus does not help.
I did all in OnInitDialog.
Is it right place?
RussG1
August 23rd, 2004, 12:26 PM
What did you return from OnInitDialog()?
The docs say:
"The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control specified by wParam. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus."
And you may have noticed the MFC comments that are generated when using MFC:
"return TRUE unless you set the focus to a control"
Thus you should return FALSE, if you want to set the focus to a control manually, from within WM_INITDIALOG/OnInitDialog.
Alex Rest
August 23rd, 2004, 02:13 PM
GetDlgItem(IDC_ORDERNOW)->SendMessage(BM_SETSTYLE, S_DEFPUSHBUTTON, FALSE);
GetDlgItem(IDC_CONTINUE)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
GetDlgItem(IDC_CONTINUE)->SetFocus();
return FALSE;
The story becomes fine.
As result I'v got two selection rectangles :sick:
Other Ideas?
RussG1
August 23rd, 2004, 03:20 PM
case WM_INITDIALOG:
{
SendMessage(GetDlgItem(hwnd, IDC_CONTINUE), BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
SendMessage(GetDlgItem(hwnd, IDC_ORDERNOW), BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
SetFocus(GetDlgItem(hwnd, IDC_CONTINUE));
return false;
}
break;
BTW: Note the rectangle you are speaking of is not the selection/focus rectangle, but rather the button border. If you only want to change the default button (including the border) but not the focus (i.e. if focus should not be on any button), then you do not need the SetFocus line above (you still do need the return false though).
Alex Rest
August 24th, 2004, 03:58 AM
Yes, it realy works.
Thanks.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.