windows下objective-c的cocoa框架编程,可以有图形界面哟
来源:互联网 发布:win7服务优化批处理 编辑:程序博客网 时间:2024/06/07 02:12
先配置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没钱的黑苹果
- windows下objective-c的cocoa框架编程,可以有图形界面哟
- Objective-C 的语法与 Cocoa 框架
- Objective-C 简介Cocoa框架
- (经典推荐) Objective-C 的语法与Cocoa 框架----02
- (经典推荐) Objective-C 的语法与Cocoa 框架----01
- Objective-C 的语法与Cocoa 框架----01
- [代码编程规范][代码样式][cocoa]Cocoa Style For Objective-C 下
- Objective-C入门 简介Cocoa框架
- Objective-C入门 简介Cocoa框架
- Windows上使用Objective-c和Cocoa
- Windows上使用Objective-c和Cocoa
- Windows上使用Objective-C和Cocoa
- Objective C的编译器有哪些,如何搭建Windows/linxu下OBJ-C环境(大全)
- 【Objective-C编程】 Foundataion框架的详解
- Objective-C Cocoa的delegate机制解释
- Cocoa入门-objective-c的读书笔记3
- Xcode,Objective-c,Cocoa的区别
- XCode、Objective-C、Cocoa !!!
- 找出数组中2个只出现一次的数字
- 开源视频编辑平台 Kaltura 融资 2500 万美元
- iOS核心系统编程最佳实践:事件
- VC++2005中操作SQLCE3.0
- SQLServer2005中常见的数字函数
- windows下objective-c的cocoa框架编程,可以有图形界面哟
- 新浪微博出现短暂故障 蓝V账号无法打开
- iOS核心系统编程最佳实践:视图
- 使用vim编辑可执行文件--16进制模式
- Windows 生日快乐!27年27件大事记
- Windows Phone 8 面临吸引开发者难题
- 关于包含头文件而编译时却一个未定义错误的原因(未使用命名名字空间)
- 乌云曝光铁道部12306网站出现SQL漏洞
- VS2008连接SQLServer 2005注意点