我看到了很多问题,但我找不到任何帮助我的东西。我看过很多苹果开发者的页面,但我发现这些页面有点不清楚。
我想在Objective-C++中开发应用程序,而不需要Xcode或任何其他为我完成所有工作的IDE。我的IDE是Atom,我用g++编译。我有以下类来创建窗口:
#ifndef WINDOW_H
#define WINDOW_H
#import "Cocoa/Cocoa.h"
class Window
{
private: NSWindow* window;
public: Window(const char* title, int x, int y, int w, int h, NSColor* bg = [NSColor colorWithCalibratedRed:0.3f green:0.3f blue:0.3f alpha:1.0f])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
NSRect frame = NSMakeRect(x, y, w, h);
NSUInteger windowStyle = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable;
NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:windowStyle];
this->window = [[[NSWindow alloc] initWithContentRect:rect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO] autorelease];
[this->window makeKeyAndOrderFront: this->window];
[this->window setBackgroundColor: bg];
[this->window setTitle: [NSString stringWithUTF8String:title]];
[this->window orderFrontRegardless];
[pool drain];
[NSApp run];
}
};
#endif
据我所知,我需要用NSView做一些事情,但我不确定我应该做什么。如何从窗口中获取关键输入?