Carbon PostEventToQueue sample code prevent from crash of windows and controls

Posted on Updated on

this sample function just presents the example to send command event into queue, this could prevent from thread unsafe problem that cause control or window crashed when you send event from a process to another,

  • remember that control and window events should be processed in main thread.
  • PostHICommand seems like call event handle directly, so use PostEventtoQueue is a better solution

mySendEvent(UInt32 commandID)
EventRef nextEvent = NULL;
HICommandExtended nextCmd;

memset(&nextCmd,0,sizeof(HICommandExtended)) ;
nextCmd.commandID = commandID ;
// =0 ;
// = 0 ;
SetEventParameter(nextEvent,kEventParamDirectObject,typeHICommand,sizeof(nextCmd),&nextCmd) ;
PostEventToQueue(GetMainEventQueue(),nextEvent,1) ;
ReleaseEvent(nextEvent) ;



在下方填入你的資料或按右方圖示以社群網站登入: 標誌

您的留言將使用 帳號。 登出 /  變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )


您的留言將使用 Facebook 帳號。 登出 /  變更 )


連結到 %s