radio buttons

This is a discussion on radio buttons within the Windows Programming forums, part of the Platform Specific Boards category; I'm just beginning programming in windows, and I added radio buttons to my dialog box and I can't get them ...

  1. #1
    RonShel
    Guest

    radio buttons

    I'm just beginning programming in windows, and I added radio buttons to my dialog box and I can't get them to work. Which function should I use to say "If this radio button is activated, do this."? I looked in MSDN, and I tried using BN_CLICKED but I can't get it to work, and when I tried to use switch(wCommand){
    case IDC_RADIO1: function();
    break;
    }
    The program does function() the moment the user clicks on the radio button, instead of waiting until the user presses ok.
    I'd appreciate any help if you have suggestions,
    Thanks in advance,
    Ron
    P.S. Thank you Sunlight for your wonderful tutorial, it really helped me alot getting started!

  2. #2
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    check out these API's

    CheckDlgButton() and IsDlgButtonChecked().

    this checks the radio button, if it's already checked it uncecks it.

    Code:
    case IDC_RADIO1:
    	if(IsDlgButtonChecked(hwnd, IDC_RADIO1) == BST_CHECKED)
    	{
    		CheckDlgButton(hwnd, IDC_RADIO1, BST_UNCHECKED);
    	}
    	else
    	{
    		CheckDlgButton(hwnd, IDC_RADIO1, BST_CHECKED);
    	}
    break;
    hope it helps

  3. #3
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    i think i may have misunderstood your question. let me see if this better.

    Code:
    case IDOK: // ID of your OK button
    	if(IsDlgButtonChecked(hwnd, IDC_RADIO1) == BST_CHECKED)
    	{
    		// if the radio button is checked  do your stuff
    	}
    	else
    	{
    		// if its not do your other stuff
    
    	}
    break;

  4. #4
    zoo
    Guest
    To get it to wait until the user presses the OK button, put your IsDlgButtonChecked() within the case for the OK button. For example:

    case WM_COMMAND:
    if(wParam==IDOK)
    {
    if (IsDlgButtonChecked(hwndDlg,SAVE))
    EndDialog(hwndDlg,SAVE);
    return TRUE;
    }

    In this example, if the SAVE dialog button is checked, the dialog box is hidden, and the program returns to the where the dialog box was created. If you want to keep the dialog box active, do your processing, and take out the EndDialog() statement.

  5. #5
    zoo
    Guest
    Forgot to format the code:

    Code:
          case WM_COMMAND:
             if(wParam==IDOK)
             {
                 if (IsDlgButtonChecked(hwndDlg,SAVE))
                    EndDialog(hwndDlg,SAVE);
                 return TRUE;
             }

  6. #6
    RonShel
    Guest
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OwnerDrawn Radio Buttons?
    By Devil Panther in forum Windows Programming
    Replies: 0
    Last Post: 02-11-2006, 11:02 AM
  2. Radio Buttons in Visual C++ 6
    By Ripper1 in forum Windows Programming
    Replies: 22
    Last Post: 05-16-2003, 08:54 AM
  3. create radio buttons
    By bluecoder in forum Windows Programming
    Replies: 10
    Last Post: 05-14-2002, 01:01 AM
  4. Group radio buttons
    By ski6ski in forum Windows Programming
    Replies: 0
    Last Post: 09-01-2001, 10:19 AM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21