tags:

views:

312

answers:

2

How to create a radio button and see if it's checked?

  • Windows Vista
  • Dev-C++
  • Win32 API
  • WM styles
+4  A: 

To find out whether a radio button (or check box) is checked, send the BM_GETCHECK message to the control and check the return value. You will need the HWND of your control; to get that from the control ID, call GetDlgItem().

Greg Hewgill
That sounds painful :( `textBox.Checked` is where it's at.
Mark
@Mark: The Win32 API is pretty low level as far as GUI frameworks go.
Greg Hewgill
Oh I know. That's *why* it's painful :)
Mark
+2  A: 

Use CreateWindow() or CreateWindowEx() with the button style BS_RADIOBUTTON or BS_AUTORADIOBUTTON to create one. E.g.:

HWND radioButtonHandle = CreateWindow(
    TEXT("BUTTON"), TEXT("my radio button"), 
    WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON,
    /* ... */);
Georg Fritzsche