4

I have a button, if i were to say click a checkbox, it should then give one of two buttons focus.

I am not sure how to use BM_SETSTATE - if that is the way to do it.

// snip...
    case WM_COMMAND:
    switch (LOWORD(wParam))
    {
    case IDC_CHECK:
        if (IsDlgButtonChecked(hDlg, IDC_CHECK))
        {
            EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
            EnableWindow(GetDlgItem(hDlg, IDCANCEL), TRUE);
            BM_SETSTATE // ... ?? 
        }
        else  
// ... snip

any help is greatly appreciated! thanks much!

2 Answers 2

5

I'm not sure if you understand exactly what you're asking, but maybe.

The highlight state indicates whether the button is highlighted as if the user had pushed it. It does not indicate whether the button has focus nor does it indicate whether the button is checked or not.

If you really want to do this though, use the Button_SetState macro.


Just in case:

  • If you want to set the check state on a button use the Button_SetCheck macro.
  • If you want to set the focus on a button use the SetFocus Win32 API.
  • Note: Above I mentioned a couple macros, you can instead use SendMessage and pass the appropriate message as documented on the message in MSDN.
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I want the focus, so that if the end user hits enter, I want it to have a default action (in this case, the one with less consequences)
@Jonathan: In that case you want the second bullet point under the horizontal bar (SetFocus).
Thanks Brian, that did the trick. I couldn't find the documentation on SetFocus anywhere for some reason!
2

To make a button default in win32 (which i guess is your question) can simply be done by sending the button a BM_SETSTYLE message with BS_DEFPUSHBUTTON as the WPARAM...

HWND hwndButton = CreateWindow("button", "OK", WS_VISIBLE |...);

SendMessage(hwndButton, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, TRUE);

Hope this helps... ;-)

1 Comment

It helped me! But I was surprised the button that was the default style continued to look defaulted. I found this, which solved my issue: SendMessage( hDlg, DM_SETDEFID, (WPARAM) IDOK, 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.