osx - User Switch Notification by Carbon in Objective C -


following codes https://developer.apple.com/library/mac/#documentation/macosx/conceptual/bpmultipleusers/concepts/userswitchnotifications.html#//apple_ref/doc/uid/20002210-cjbjdagf

demonstrates how aware of user switch event . can't use code user switch purpose ,and doesn't work me. how use code notified when user switch occurs?

pascal osstatus switcheventshandler (eventhandlercallref nexthandler,                                         eventref switchevent,                                         void* userdata) {     if (geteventkind(switchevent)== keventsystemusersessiondeactivated)     {         // perform deactivation tasks here.     }     else     {         // perform activation tasks here.     }      return noerr; }  void switcheventsregister() {     eventtypespec switcheventtypes[2];     eventhandlerupp switcheventhandler;      switcheventtypes[0].eventclass = keventclasssystem;     switcheventtypes[0].eventkind = keventsystemusersessiondeactivated;     switcheventtypes[1].eventclass = keventclasssystem;     switcheventtypes[1].eventkind = keventsystemusersessionactivated;      switcheventhandler = neweventhandlerupp(switcheventshandler);     installapplicationeventhandler(switcheventhandler, 2,                                     switcheventtypes, null, null); 

you need start event loop using runapplicationeventloop()

the main may looks this:

int main(int argc, char *argv[]) {     switcheventsregister();      runapplicationeventloop();      return 0; } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -