1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Radio buttons in Carcon C with XCode, simple question

Discussion in 'Mac Programming' started by GothicChess.Com, Jun 22, 2007.

  1. macrumors regular


    I'm just trying to turn off one radio button and turn the other one on when a hit on it occurs. I am NOT using a pre-defined cluster from Interface Builder, just 2 separate radio buttons.

    Is there any reason why I can see my dialog box (indicating I made it into the code block) yet the controls do not reflect the fact I hit them?

    I must be missing something so elementary it almost defies explanation :)

    #define		kFirstRadioSig		'frad'
    #define		KSecondRadioSig		'srad'
    #define		kFirstRadio_ID		63
    #define		KSecondRadio_ID		64
    DialogRef		alert;
    DialogItemIndex userItemHit;
    ControlID	radio_button_control_ID;
    ControlRef	radio_button_control_ref;
    GetEventParameter(your_event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &the_command);
    	case KSecondRadioSig: 
    		 /* 1st radio button turns off ... */
    		 radio_button_control_ID.signature = kFirstRadioSig;
    		 radio_button_control_ID.id = kFirstRadio_ID;
    		 GetControlByID(g_drawer_window_with_buttons, &radio_button_control_ID, &radio_button_control_ref);
    		 SetControlValue(radio_button_control_ref, 0);
    		 /* 2nd radio button turns on  ... */
    		 radio_button_control_ID.signature = KSecondRadioSig;
    		 radio_button_control_ID.id = KSecondRadio_ID;
    		 GetControlByID(g_drawer_window_with_buttons, &radio_button_control_ID, &radio_button_control_ref);
    		 SetControlValue(radio_button_control_ref, 1);
    		 CreateStandardAlert(kAlertPlainAlert, CFSTR("--- YOU MADE IT HERE ---"), CFSTR("Definitely made it to this part of the code for sure."), NULL, &alert);
    		 RunStandardAlert(alert, NULL, &userItemHit);
  2. Moderator emeritus


    AppKit? ;)
  3. macrumors regular


    This was of no help whatsoever, thanks.

  4. macrumors regular

    Where did the variable g_drawer_window_with_buttons come from. You use it to try and change the radio buttons but you do not use it to create the alert, hence if the problem was here you would get the alerts but not the expected behavior.

    Also can you breakpoint on the GetControlByID() function and see if radio_button_control_ID etc are updated to reasonable values i.e. not 0x0 or null.

    btw, now might be the time to mention I am a Cocoa programmer so I'm debugging this completely abstractly :p.

  5. macrumors regular


    Hi Chris,

    I built this with XCode and InterfaceBuilder. So, g_drawer_window_with_buttons is just a name I made up for the window (which is a drawer that slides out of another window) and it is of type WindowRef. The actual resource for the window is in InterfaceBuilder.

    The odd thing is, the radio buttons "do their thing" from the code module properly, namely, the code block does what I want when I hit them, its just they don't fill in and indicate that I hit them! In the good-ole-days all you have to do was call SetCtlValue with a data type of ControlHandle but now I am trying to figure out how to do it.
  6. macrumors regular

    Could you package up the code as a small independent Xcode project exemplifying the problem. It's really difficult to debug without seeing it :)



Share This Page