Thread: Radio Buttons in a dialog box

  1. #1
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195

    Radio Buttons in a dialog box

    In an application I've written, I've got a dialog box with some radio buttons, as shown below. I test for them in the usual way of a switch statement in a callback proc as shown, although I don't know how to link them so that if one is pressed, the others are deactivated and the one which is pressed is activated.

    Code:
    /* resource.rc */
    IDD_OPTIONS DIALOG DISCARDABLE 50, 50, 120, 120
    STYLE DS_SETFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME
    CAPTION "Options"
    FONT 8, "MS Sans Serif"
    BEGIN
        RADIOBUTTON     "640x480", IDC_NEW_RADIO1, 30, 20, 30, 15
        RADIOBUTTON     "800x600", IDC_NEW_RADIO2, 70, 20, 30, 15
        RADIOBUTTON     "1024x768", IDC_NEW_RADIO3, 30, 60, 30, 15
        RADIOBUTTON     "1600x1200", IDC_NEW_RADIO4, 70, 60, 30, 15
        /* More options here */
    END
    Code:
    /* This is part of my main.cpp */
    BOOL CALLBACK OptionsDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
         BOOL ret = FALSE;
         /* Returns TRUE if everything goes smoothly, FALSE otherwise */
        switch(Message)
        {
            case WM_INITDIALOG:
                 
                 ret = TRUE;
                 break;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                                      case IDC_NEW_RADIO1:
                                           /* Activate current option in the dialog, while deactivating the others */
                                           ret = TRUE;
                                           break;
                                           
                                      case IDC_NEW_RADIO2:
    
                                           ret = TRUE;
                                           break;
                                           
                                      case IDC_NEW_RADIO3:
    
                                           ret = TRUE;
                                           break;
                                           
                                      case IDC_NEW_RADIO4:
    
                                           ret = TRUE;
                                           break;
                }
            break;
            default:
                // ret = FALSE;
                break;
        }
        return ret;
    }

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    To set a radio button try:

    Code:
    SendMessage(Handle2Control, BM_SETCHECK, 1,0);
    and to unset a radio button try:
    Code:
    SendMessage(Handle2Control, BM_SETCHECK, 0,0);
    /edit.
    or put the related radio buttons in a group box.
    Last edited by Bajanine; 12-29-2008 at 12:50 PM.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  3. #3
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    Ok, my next question, is how do I get the handle of the resource in the dialog box, given that I'm creating the dialog from a resource file rather than using the CreateWindowEx() function?

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    As in how to get the control to the radio buttons?

    HWND Handle2Control = GetDlgItem( hwnd, IDC_NEW_RADIO# );

    should do.
    Last edited by twomers; 01-02-2009 at 06:48 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Parent of a BrowseForFolder dialog box
    By @nthony in forum Windows Programming
    Replies: 4
    Last Post: 01-08-2007, 02:54 PM
  3. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  4. radio buttons in group box
    By COBOL2C++ in forum Windows Programming
    Replies: 3
    Last Post: 09-15-2003, 05:26 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM