PDA

View Full Version : Carbon Controls


anonuser
2004.09.05, 03:12 PM
I created several controls, all have the same signature just as they should and differ by ID.

Here's what my event type spec looks like.
EventTypeSpec mainSpec[] = {
{ kEventClassCommand, kEventCommandProcess },
{ kEventClassMouse, kEventMouseDown },
{ kEventClassControl, kEventControlActivate }
};

I install the window handler, as a general purpose handler.

I get my command from my event, just as you would normally.

But I need to know which control sent the event.

I figured this would work.
GetEventParameter(event,kEventParamControlRef,
typeControlRef,NULL,sizeof(test),
NULL,&test)

but that doesn't work.
I get -1700 for a result code, unkown control.
I've tried several different Params.
none work.
I never get a control ref.
which i really really need.

Let me know if you want me to post the entire application. I'ts rather messy because of debug code, but i'll clean it up if you want it posted.

dair
2004.09.06, 02:34 AM
You need to retrieve the HICommand from the command process event:

HICommandExtended hiCmd;

GetEventParameter(event, kEventParamDirectObject, typeHICommand,
NULL, sizeof(hiCmd), NULL, &hiCmd);

switch (hiCmd.commandID) {
case kCommandFromControl1:
DoControl1();
break;

case kCommandFromControl2:
DoControl2();
break;

case kCommandFromControl3:
DoControl3();
break;
}
If you also need the ControlRef, you can get it from the hiCmd.source.control field (and similarly or MenuRefs or WindowRefs, if the command originated from a menu or window).

anonuser
2004.09.07, 07:17 AM
I've already solved this problem thanks anyway :D