슬프게도 NSApplication을 실행해야하지만 앱 번들이 필요하지 않습니다.
프로젝트를 만들 때 유형으로 "Foundation"을 선택해야합니다. 그럼 당신은 이런 식으로 설정할 수 있습니다 :
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
@interface MyAppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window;
}
@end
@implementation MyAppDelegate
-(id) init
{
self = [super init];
if (self)
{
// total *main* screen frame size //
NSRect mainDisplayRect = [[NSScreen mainScreen] frame];
// calculate the window rect to be half the display and be centered //
NSRect windowRect = NSMakeRect(mainDisplayRect.origin.x + (mainDisplayRect.size.width) * 0.25,
mainDisplayRect.origin.y + (mainDisplayRect.size.height) * 0.25,
mainDisplayRect.size.width * 0.5,
mainDisplayRect.size.height * 0.5);
/*
Pick your window style:
NSBorderlessWindowMask
NSTitledWindowMask
NSClosableWindowMask
NSMiniaturizableWindowMask
NSResizableWindowMask
*/
NSUInteger windowStyle = NSTitledWindowMask | NSMiniaturizableWindowMask;
// set the window level to be on top of everything else //
NSInteger windowLevel = NSMainMenuWindowLevel + 1;
// initialize the window and its properties // just examples of properties that can be changed //
window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO];
[window setLevel:windowLevel];
[window setOpaque:YES];
[window setHasShadow:YES];
[window setPreferredBackingLocation:NSWindowBackingLocationVideoMemory];
[window setHidesOnDeactivate:NO];
[window setBackgroundColor:[NSColor greenColor]];
}
return self;
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification
{
// make the window visible when the app is about to finish launching //
[window makeKeyAndOrderFront:self];
/* do layout and cool stuff here */
}
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
/* initialize your code stuff here */
}
- (void)dealloc
{
// release your window and other stuff //
[window release];
[super dealloc];
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool
{
NSApplication *app = [NSApplication sharedApplication];
[app setDelegate:[[[MyAppDelegate alloc] init] autorelease]];
[app run];
}
return 0;
}
그 라인 [응용 프로그램 실행]을 염두에 두십시오; 응용 프로그램 루프 내에서 또는 새 스레드 (응용 프로그램 루프 선호)에서 논리를 실행해야하므로 블로킹합니다.
희망이 있습니다.
편집 : 부 .. 너무 늦었습니다!
질문에 이유를 추가 할 수 있다면 도움이 될 것입니다. –
일반적인 접근법은 "명령 줄 앱"을 앱 번들 내의 실행 파일에 대한 심볼릭 링크로 심볼릭 링크하는 것입니다. Mac OS X 런처/도크에는 번들이 필요합니다. 번들에 문제가 있다면 번들을 사람들이 볼 수 없게 될 것입니다 (예 :/Applications가 아님). 그리고 그 차이점은 무엇입니까? 사람들이 네 물건을 두 번 클릭 할 수 없도록 확실히해야합니까? –