Force my application to be the front most app...
Daniel Hazelbaker
daniel at highdesertchurch.com
Mon May 28 15:52:19 PDT 2007
On May 28, 2007, at 1:02 PM, Charles E. Heizer1 wrote:
> Thanks,
> I can’t seem to get it to work, and I think I know why but am not
> sure how to fix it.
>
> I close the window and then open it. The issue here is that
> makeKeyAndOrderFront using afterDelay seems to be in it’s own loop.
> How do I address this issue?
Off the top of my head, I would recommend using an NSTimer instead of
the performSelector:afterDelay: method.
e.g.
{
...
[NSTimer scheduledTimerWithTimeInterval:theDelay target:self
selector:@selector(forceIntoForeground:) userInfo:nil repeats:NO];
...
}
- (void)forceIntoForeground:(NSTimer *)timer
{
[mainWindow makeKeyAndOrderFront:self];
if (I_want_to_be_really_really_really_sure == YES) {
ProcessSerialNumber myPSN;
GetCurrentProcess(&myPSN);
SetFrontProcess(&myPSN);
}
}
> Thanks,
> - Charles
>
> - (IBAction)reminderButton:(id)sender
> {
>
> double theDelay;
>
> if ( [delayTimePopUp indexOfSelectedItem] == 0) {
> theDelay = 300; // 5 minutes
> } else if ([delayTimePopUp indexOfSelectedItem] == 1) {
> theDelay = 600; // 10 minutes
> } else if ([delayTimePopUp indexOfSelectedItem] == 2) {
> theDelay = 900; // 15 minutes
> } else if ([delayTimePopUp indexOfSelectedItem] == 3) {
> theDelay = 1800; // 30 minutes
> } else if ([delayTimePopUp indexOfSelectedItem] == 4) {
> theDelay = 3600; // 1 hour
> } else if ([delayTimePopUp indexOfSelectedItem] == 5) {
> theDelay = 7200; // 2 hours
> } else if ([delayTimePopUp indexOfSelectedItem] == 7) {
> theDelay = 10; // 2 hours
> } else if ([delayTimePopUp indexOfSelectedItem] == 6) {
> theDelay = 0; // No Delay selection was never
>
> // Display an alert dialog warning the user of the
> // reboot situation...
> NSAlert *alert = [[NSAlert alloc] init];
> [alert addButtonWithTitle:@"OK"];
> [alert addButtonWithTitle:@"Cancel"];
> [alert setMessageText:@"Ignore the reboot?"];
> [alert setInformativeText:@"Are you sure you want to ignore
> the reboot? You will not be warned to reboot again."];
> [alert setAlertStyle:NSWarningAlertStyle];
>
> if ([alert runModal] == NSAlertFirstButtonReturn) {
> // OK clicked, ignore the reboot dialog
> exit(0);
> }
>
> [alert release];
> }
>
> // If the time to delay is no 0 delay the app
> if ( theDelay != 0) {
> ProcessSerialNumber myPSN;
> GetCurrentProcess(&myPSN);
> [mainWindow orderOut:nil];
> [mainWindow performSelector:@selector
> (makeKeyAndOrderFront:) withObject:self afterDelay:theDelay];
> SetFrontProcess(&myPSN);
> }
>
> }
>
More information about the MacOSX-dev
mailing list