I’ve the following code :
NSRect contentRect = NSZeroRect;
contentRect.size = NSMakeSize(400, 400);
contentRect.origin = NSMakePoint(400, 400);
NSWindow* window = [[NSWindow alloc] initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
[window setBackgroundColor:[NSColor blackColor]];
[window setMovableByWindowBackground:NO];
[window setExcludedFromWindowsMenu:YES];
[window setAlphaValue:0.8];
[window setOpaque:NO];
[window setHasShadow:YES];
[window useOptimizedDrawing:YES];
[NSApp activateIgnoringOtherApps:YES];
[window makeKeyAndOrderFront:nil];
It’s called by - (BOOL) applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag. This function is called when clicking on the Dock icon.
Why is my window not showing ?
I also noticed that, when clicking dozen on times on the dock icon. Sometime I see my window appear for 1/10th a sec. Then it disappear.
If you are using ARC,
Then make
windowas property for the class. It will be solved as in this case it is getting released.Use :
@property(strong) NSWindow* window;