unable to show back the NSWindow when using CGDisplay

Discussion in 'Mac Programming' started by Monaj, Jun 8, 2011.

  1. macrumors regular

    Joined:
    May 24, 2009
    #1
    Hi all,

    I am making an application in which:

    1. when user selects display menu option -> the window is displayed over whole screen and
    2. when user selects hide menu option - >the window which was visible over whole screen gets hidden.

    Problem is -

    Can anyone suggest me, how can I resolve it?

    Below is the part of code:

    Code:
    - (IBAction)hideMenuAction:(id)sender
    {	
    	[window orderOut:nil];
    	if (CGDisplayRelease( kCGDirectMainDisplay ) != kCGErrorSuccess) {
               NSLog( @"Couldn't release the main display!" );
            }
    }
    
    - (IBAction)displayMenuAction:(id)sender
    {
    	[window makeKeyAndOrderFront:nil];
            if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
               NSLog( @"Couldn't capture the main display!" );
            }
    	[window setLevel:CGShieldingWindowLevel()];
    }
    Thanks,

    Monaj
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Maybe you need to reset the window level?
     
  3. thread starter macrumors regular

    Joined:
    May 24, 2009
    #3
    Solution found

    The problem is resolved when I placed the code line: [window makeKeyAndOrderFront:nil]; below the if block in displayMenuAction.

    So now the code is:

    Code:
    - (IBAction)displayMenuAction:(id)sender
    {
         if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
               NSLog( @"Couldn't capture the main display!" );
            }
        [window makeKeyAndOrderFront:nil];
        [window setLevel:CGShieldingWindowLevel()];
    }
     
  4. thread starter macrumors regular

    Joined:
    May 24, 2009
    #4
    New Problem: text fields are appearing uneditable.

    I have started facing a new problem:

    Please suggest.
     

Share This Page