CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2002
    Location
    Ukraine
    Posts
    228

    Question 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?

  2. #2
    Join Date
    Jun 2004
    Posts
    102
    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.

  3. #3
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457
    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.

  4. #4
    Join Date
    Jun 2004
    Posts
    102
    Quote 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.

  5. #5
    Join Date
    May 2002
    Location
    Ukraine
    Posts
    228
    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.

  6. #6
    Join Date
    Sep 2002
    Posts
    924
    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.

  7. #7
    Join Date
    May 2002
    Location
    Ukraine
    Posts
    228
    No. SetFocus does not help.
    I did all in OnInitDialog.
    Is it right place?

  8. #8
    Join Date
    Sep 2002
    Posts
    924
    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.

  9. #9
    Join Date
    May 2002
    Location
    Ukraine
    Posts
    228

    Cool

    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?

  10. #10
    Join Date
    Sep 2002
    Posts
    924
    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.

  11. #11
    Join Date
    May 2002
    Location
    Ukraine
    Posts
    228
    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
  •  





Click Here to Expand Forum to Full Width

Featured