演示了如何了解用户切换事件。但我不能将此代码用于用户切换目的,它对我不起作用。 如何在用户切换时使用此代码进行通知?
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);
答案 0 :(得分:0)
您需要使用RunApplicationEventLoop()
主要可能是这样的:
int main(int argc, char *argv[])
{
SwitchEventsRegister();
RunApplicationEventLoop();
return 0;
}