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

先配置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啦

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

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

1 include $(GNUSTEP_MAKEFILES)/common.make
2  
3 TOOL_NAME=HelloWorld
4 HelloWorld_OBJC_FILES=HelloWorld.m
5  
6 include $(GNUSTEP_MAKEFILES)/tool.make

好了,之后就是这样的:

 

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

main.m

01 #include "AppController.h"
02 #include <AppKit/AppKit.h>
03  
04 int main(int argc, const char*argv[])
05 {
06    NSAutoreleasePool *pool;
07    AppController *delegate;
08     
09    pool = [[NSAutoreleasePool alloc] init];
10    delegate = [[AppController alloc] init];
11  
12    [NSApplication sharedApplication];
13    [NSApp setDelegate: delegate];
14  
15    RELEASE(pool);
16    return NSApplicationMain (argc, argv);
17 }

 

AppController.h

01 #ifndef _AppController_H_
02 #define _AppController_H_
03  
04 #include <Foundation/NSObject.h>
05  
06 @class NSWindow;
07 @class NSTextField;
08 @class NSNotification;
09  
10 @interface AppController : NSObject
11 {
12    NSWindow *window;
13    NSTextField *label;
14 }
15  
16 - (void)applicationWillFinishLaunching:(NSNotification *) not;
17 - (void)applicationDidFinishLaunching:(NSNotification *) not;
18  
19 @end
20  
21 #endif /* _AppController_H_ */

 

AppController.m

01 #include "AppController.h"
02 #include <AppKit/AppKit.h>
03  
04 @implementation AppController
05 - (void) applicationWillFinishLaunching: (NSNotification *) not
06 {
07    /* Create Menu */
08    NSMenu *menu;
09    NSMenu *info;
10  
11    menu = [NSMenu new];
12    [menu addItemWithTitle: @"Info"
13                    action: NULL
14             keyEquivalent: @""];
15    [menu addItemWithTitle: @"Hide"
16                    action: @selector(hide:)
17             keyEquivalent: @"h"];
18    [menu addItemWithTitle: @"Quit"
19                    action: @selector(terminate:)
20             keyEquivalent: @"q"];
21  
22    info = [NSMenu new];
23    [info addItemWithTitle: @"Info Panel..."
24                    action: @selector(orderFrontStandardInfoPanel:)
25             keyEquivalent: @""];
26    [info addItemWithTitle: @"Preferences"
27                    action: NULL
28             keyEquivalent: @""];
29    [info addItemWithTitle: @"Help"
30                    action: @selector (orderFrontHelpPanel:)
31             keyEquivalent: @"?"];
32  
33    [menu setSubmenu: info
34             forItem: [menu itemWithTitle:@"Info"]];
35    RELEASE(info);
36  
37    [NSApp setMainMenu:menu];
38    RELEASE(menu);
39  
40    /* Create Window */
41    window = [[NSWindow alloc] initWithContentRect: NSMakeRect(300, 300, 200, 100)
42                                         styleMask: (NSTitledWindowMask |
43                                                     NSMiniaturizableWindowMask |
44                                                     NSResizableWindowMask)
45                                           backing: NSBackingStoreBuffered
46                                             defer: YES];
47    [window setTitle: @"Hello World"];
48  
49    /* Create Label */
50    label = [[NSTextField alloc] initWithFrame: NSMakeRect(30, 30, 80, 30)];
51    [label setSelectable: NO];
52    [label setBezeled: NO];
53    [label setDrawsBackground: NO];
54    [label setStringValue: @"Hello World"];
55  
56    [[window contentView] addSubview: label];
57    RELEASE(label);
58 }
59  
60 - (void) applicationDidFinishLaunching: (NSNotification *) not
61 {
62    [window makeKeyAndOrderFront: self];
63 }
64  
65 - (void) dealloc
66 {
67   RELEASE(window);
68   [super dealloc];
69 }
70  
71 @end

helloworldInfo.plist

01 {
02    ApplicationDescription = "Hello World Tutorial";
03    ApplicationIcon = "";
04    ApplicationName = HelloWorld;
05    ApplicationRelease = 0.1;
06    Authors = "";
07    Copyright = "Copyright (C) 200x by ...";
08    CopyrightDescription = "Released under...";
09    FullVersionID = 0.1;
10    URL = "";
11 }

GNUmakefile

01 GNUSTEP_MAKEFILES=/GNUstep/System/Library/Makefiles
02  
03 include $(GNUSTEP_MAKEFILES)/common.make
04  
05 APP_NAME = HelloWorld
06 HelloWorld_HEADERS = AppController.h
07 HelloWorld_OBJC_FILES = main.m AppController.m
08 HelloWorld_RESOURCE_FILES = HelloWorldInfo.plist
09  
10 include $(GNUSTEP_MAKEFILES)/application.make

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

效果,有图有真相:

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

 当然uikit类库在windows下还是不能用,就是说ios开发不了,各位有钱的买mac没钱的黑苹果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值