Radio buttons in Carcon C with XCode, simple question

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

  1. macrumors regular

    GothicChess.Com

    Joined:
    Apr 6, 2007
    Location:
    Philadelphia, PA
    #1
    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 :)


    Code:
    #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);
    
    switch(the_command.commandID)
    {
    	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);
    	break;
    }
    
    
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    AppKit? ;)
     
  3. thread starter macrumors regular

    GothicChess.Com

    Joined:
    Apr 6, 2007
    Location:
    Philadelphia, PA
    #3
    This was of no help whatsoever, thanks.

    :)
     
  4. macrumors regular

    Joined:
    Jul 5, 2005
    Location:
    London, UK
    #4
    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.

    Chris
     
  5. thread starter macrumors regular

    GothicChess.Com

    Joined:
    Apr 6, 2007
    Location:
    Philadelphia, PA
    #5
    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

    Joined:
    Jul 5, 2005
    Location:
    London, UK
    #6
    Could you package up the code as a small independent Xcode project exemplifying the problem. It's really difficult to debug without seeing it :)

    Thanks

    Chris
     

Share This Page