|
-
August 23rd, 2004, 04:48 AM
#1
I need a boring dialog
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?
-
August 23rd, 2004, 05:45 AM
#2
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.
-
August 23rd, 2004, 07:15 AM
#3
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:
Code:
// Set button one to the default...
SendMessage(hwndButton1, BM_SETSTYLE, BS_DEFPUSHBUTTON, FALSE);
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-
August 23rd, 2004, 07:57 AM
#4
 Originally Posted by Bond
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:
Code:
// Set button one to the default...
SendMessage(hwndButton1, BM_SETSTYLE, BS_DEFPUSHBUTTON, FALSE);
Yes, of course.
-
August 23rd, 2004, 10:59 AM
#5
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.
-
August 23rd, 2004, 11:03 AM
#6
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.
-
August 23rd, 2004, 11:19 AM
#7
No. SetFocus does not help.
I did all in OnInitDialog.
Is it right place?
-
August 23rd, 2004, 11:26 AM
#8
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.
-
August 23rd, 2004, 01:13 PM
#9
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
Other Ideas?
-
August 23rd, 2004, 02:20 PM
#10
Code:
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).
Last edited by RussG1; August 23rd, 2004 at 02:43 PM.
-
August 24th, 2004, 02:58 AM
#11
Yes, it realy works.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|