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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -