您的位置:首页 > 移动开发 > Objective-C

windows下objective-c的cocoa框架编程,可以有图形界面哟

2012-11-18 20:44 1171 查看
先配置windows下的objective-c的开发环境

http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/下载下面几个包,注意版本,我现在试了一下这几个包结合在一起可以用,全用最新的话,可能会导致.dll缺失,运行时会有报错

gnustep-system-0.22.0-setup.exe

gnustep-core-0.22.0-setup.exe

gnustep-devel-1.0.0-setup.exe

gorm-1.2.8-setup.exe

ProjectCenter-0.5.0-setup.exe

从上到下依次安装

看见下图就说明linux模拟环境OK啦



然后试一下,当然先helloworld啦

#import <Foundation/Foundation.h>
int main (int argc,char *argv[])
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSLog(@"Hello World!");
[pool drain];
return 0;
}

makefile,不懂的查资料,文件命名为GNUmakefile木有后缀

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME=HelloWorld
HelloWorld_OBJC_FILES=HelloWorld.m

include $(GNUSTEP_MAKEFILES)/tool.make

好了,之后就是这样的:


有的朋友就要惊了,说我骗人,木有图形界面,急吼吼神马呀,要急孙子都有了。。。。下面是动真格的了:

main.m

#include "AppController.h"
#include <AppKit/AppKit.h>

int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool;
AppController *delegate;

pool = [[NSAutoreleasePool alloc] init];
delegate = [[AppController alloc] init];

[NSApplication sharedApplication];
[NSApp setDelegate: delegate];

RELEASE(pool);
return NSApplicationMain (argc, argv);
}


AppController.h

#ifndef _AppController_H_
#define _AppController_H_

#include <Foundation/NSObject.h>

@class NSWindow;
@class NSTextField;
@class NSNotification;

@interface AppController : NSObject
{
NSWindow *window;
NSTextField *label;
}

- (void)applicationWillFinishLaunching:(NSNotification *) not;
- (void)applicationDidFinishLaunching:(NSNotification *) not;

@end

#endif /* _AppController_H_ */


AppController.m

#include "AppController.h"
#include <AppKit/AppKit.h>

@implementation AppController
- (void) applicationWillFinishLaunching: (NSNotification *) not
{
/* Create Menu */
NSMenu *menu;
NSMenu *info;

menu = [NSMenu new];
[menu addItemWithTitle: @"Info"
action: NULL
keyEquivalent: @""];
[menu addItemWithTitle: @"Hide"
action: @selector(hide:)
keyEquivalent: @"h"];
[menu addItemWithTitle: @"Quit"
action: @selector(terminate:)
keyEquivalent: @"q"];

info = [NSMenu new];
[info addItemWithTitle: @"Info Panel..."
action: @selector(orderFrontStandardInfoPanel:)
keyEquivalent: @""];
[info addItemWithTitle: @"Preferences"
action: NULL
keyEquivalent: @""];
[info addItemWithTitle: @"Help"
action: @selector (orderFrontHelpPanel:)
keyEquivalent: @"?"];

[menu setSubmenu: info
forItem: [menu itemWithTitle:@"Info"]];
RELEASE(info);

[NSApp setMainMenu:menu];
RELEASE(menu);

/* Create Window */
window = [[NSWindow alloc] initWithContentRect: NSMakeRect(300, 300, 200, 100)
styleMask: (NSTitledWindowMask |
NSMiniaturizableWindowMask |
NSResizableWindowMask)
backing: NSBackingStoreBuffered
defer: YES];
[window setTitle: @"Hello World"];

/* Create Label */
label = [[NSTextField alloc] initWithFrame: NSMakeRect(30, 30, 80, 30)];
[label setSelectable: NO];
[label setBezeled: NO];
[label setDrawsBackground: NO];
[label setStringValue: @"Hello World"];

[[window contentView] addSubview: label];
RELEASE(label);
}

- (void) applicationDidFinishLaunching: (NSNotification *) not
{
[window makeKeyAndOrderFront: self];
}

- (void) dealloc
{
RELEASE(window);
[super dealloc];
}

@end

helloworldInfo.plist

{
ApplicationDescription = "Hello World Tutorial";
ApplicationIcon = "";
ApplicationName = HelloWorld;
ApplicationRelease = 0.1;
Authors = "";
Copyright = "Copyright (C) 200x by ...";
CopyrightDescription = "Released under...";
FullVersionID = 0.1;
URL = "";
}

GNUmakefile

GNUSTEP_MAKEFILES=/GNUstep/System/Library/Makefiles

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = HelloWorld
HelloWorld_HEADERS = AppController.h
HelloWorld_OBJC_FILES = main.m AppController.m
HelloWorld_RESOURCE_FILES = HelloWorldInfo.plist

include $(GNUSTEP_MAKEFILES)/application.make

然后在shell里make一下,你应该懂的

效果,有图有真相:


当然你也可以选择直接用grom来可视化编程,这个要看英文文档啦,不要紧的,英文跟狗叫区别真的差不多,我家的狗只要我老婆喊它英文名,摇着尾巴就过去了,英文文档如下http://www.gnustep.org/experience/PierresDevTutorial/index.html

当然uikit类库在windows下还是不能用,就是说ios开发不了,各位有钱的买mac没钱的黑苹果。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息