2011-05-27 141 views
1

現在我終於設法通過http://cocoadevcentral.com/articles/000028.php 創建一個全屏窗口輝煌的教程。現在問題如何使用下面的代碼來顯示碼頭和菜單欄,因爲目前我有一個完全黑屏,我想看到一個菜單欄和一個碼頭。那可能嗎?NSWindow全屏顯示,但顯示碼頭

- (void)applicationDidFinishLaunching:(NSNotification *)notification 
{ 
    int windowLevel; 
    NSRect screenRect; 
    // Capture the main display 
    if (CGDisplayCapture(kCGDirectMainDisplay) != kCGErrorSuccess) { 
     NSLog(@"Couldn't capture the main display!"); 
     // Note: you'll probably want to display a proper error dialog here 
    } 
    // Get the shielding window level 
    windowLevel = CGShieldingWindowLevel(); 
    // Get the screen rect of our main display 
    screenRect = [[NSScreen mainScreen] frame]; 
    // Put up a new window 
    mainWindow = [[NSWindow alloc] initWithContentRect:screenRect 
            styleMask:NSBorderlessWindowMask 
            backing:NSBackingStoreBuffered 
            defer:NO screen:[NSScreen mainScreen]]; 
    [mainWindow setLevel:windowLevel]; 
    [mainWindow setBackgroundColor:[NSColor blackColor]]; 
    [mainWindow makeKeyAndOrderFront:nil]; 
    // Load our content view 
    [slideShowPanel setFrame:screenRect display:YES]; 
    [mainWindow setContentView:[slideShowPanel contentView]]; 
} 

回答

2

花了一些嘗試,但我想通了;

- (void)applicationDidFinishLaunching:(NSNotification *)notification 
{ 
int windowLevel; 
NSRect screenRect; 
// Capture the main display 

// Get the screen rect of our main display 
screenRect = [[NSScreen mainScreen] frame]; 
// Put up a new window 
mainWindow = [[NSWindow alloc] initWithContentRect:screenRect 
             styleMask:NSBorderlessWindowMask 
              backing:NSBackingStoreBuffered 
              defer:NO screen:[NSScreen mainScreen]]; 
[mainWindow setLevel:windowLevel]; 
[mainWindow setBackgroundColor:[NSColor blackColor]]; 
[mainWindow makeKeyAndOrderFront:nil]; 
// Load our content view 
[slideShowPanel setFrame:screenRect display:YES]; 
[mainWindow setContentView:[slideShowPanel contentView]]; 

} 
+0

我diff'ed這些,這是一個很大的區別...你在哪裏獲得了能夠顯示碼頭+菜單欄的功能?我不能得到它的工作... – 2011-11-19 19:46:27

+0

windowLevel被使用前未初始化。我猜它隨機創建了適當的值,將窗口級別設置爲高於所有其他窗口,但低於CGShieldingWindowLevel()返回的值。我會極力鼓勵以適當的方式來做到這一點,比如windowLevel = CGShieldingWindowLevel() - 1; – ekscrypto 2012-06-03 19:02:02