继上一步Windows下的Objective-C集成开发环境(IDE)的搭建 (一)配置运行命令行程序后,今天来讲解一下如何使用
codeblocks配置开发使用cocoa framework开发GUI程序。
#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);
}
我们使用一个helloworld开始旅程。
这个helloworld程序共有五个文件:main.m、AppController.h、AppController.m、helloworldInfo.plist和GNUmakefile。图形界面的设计全部在代码中。
#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);
}
#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_ */
#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
{
ApplicationDescription = "Hello World Tutorial"; ApplicationIcon = ""; ApplicationName = HelloWorld; ApplicationRelease = 0.1; Authors = ""; Copyright = "Copyright (C) 200x by ..."; CopyrightDescription = "Released under..."; FullVersionID = 0.1; URL = ""; }
GNUSTEP_MAKEFILES=D:/GNUstep/GNUstep/System/Library/Makefiles include $(GNUSTEP_MAKEFILES)/common.make APP_NAME = GUI $(APP_NAME)_HEADERS = AppController.h $(APP_NAME)_OBJC_FILES = main.m AppController.m $(APP_NAME)_RESOURCE_FILES = guiInfo.plist include $(GNUSTEP_MAKEFILES)/application.make
-------------- Clean: Debug in gui ---------------
Cleaned "gui - Debug" -------------- Build: Debug in gui --------------- Using makefile: GNUmakefile This is gnustep-make 2.6.1. Type 'make.exe print-gnustep-make-help' for help. Making all for app GUI... Copying resources into the app wrapper... Process terminated with status 0 (0 minutes, 1 seconds) 0 errors, 0 warnings
Windows下架设自己的DNS服务器
发表于 2007-09-17 由 charlee 相信有很多人都想架设自己的DNS服务器。我们知道世界上最好用的DNS服务器软件就是BIND;但是我辈使用Windows操作系统的人就无福享用这Unix下的顶级软件了。
或者可以用Windows Server自带的DNS服务器试试?需要安装Server版的Windows不说,麻烦的配置和令人迷惑的图形界面就够受的了。
难道就没有一个了吗?
柳暗花明又一村,突然发现BIND居然有Windows版,这这这………… 赶快下载下来试一下,居然成功地配好了DNS。
BIND的Windows版叫做ntbind,在isc的ftp上有下载。我下载的是ntbind-9.2.5版。解压之后运行安装程序,默认安装到C:\Windows\system32\dns下。
装好之后就是配置工作了,不过在这之前建议先将 C:\Windows\system32\dns\bin 添加到 PATH 环境变量中,这样配置时就可以用 dig工具来代替难用的 nslookup了。然后再将自己机器的DNS地址改为 127.0.0.1。注意修改DNS时别忘记ISP提供的DNS地址,过一会儿要用到。
打开 C:\Windows\system32\dns\etc 目录,建立配置文件 named.conf,内容如下:
named.conf
options {
// zone文件的位置
directory "C:\Windows\system32\dns\etc";
// 无法解析的域名就去查询ISP提供的DNS
// 在下面的IP地址位置上填写ISP的DNS地址
forwarders {
1.2.3.4;
1.2.3.5;
};
// 仅允许本机和子网内的机器查询
allow-query {
127.0.0.1;
192.168.0.0/24;
};
};
// 根DNS
zone "." {
type hint;
file "named.root";
};
// localhost
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
// localhost的反向解析
zone "0.0.127.in-addr.arpa" {
type master;
file "localhost.rev";
};
// example.com
zone "example.com" IN {
type master;
file "example.com.zone";
};
# End of named.conf
然后逐个建立named.conf中提到的几个文件,都放在 C:\Windows\system32\dns\etc 下。
named.root:可以从ftp.rs.internic.net(匿名FTP)上下载。
localhost.zone:针对localhost的正向解析。
$TTL 1D
@ IN SOA localhost. root.localhost. (
2007091701 ; Serial
30800 ; Refresh
7200 ; Retry
604800 ; Expire
300 ) ; Minimum
IN NS localhost.
localhost. IN A 127.0.0.1
localhost.rev:针对127.0.0.1的反向解析。
$TTL 1D
@ IN SOA localhost. root.localhost. (
2007091701 ; Serial
30800 ; Refresh
7200 ; Retry
604800 ; Expire
300 ) ; Minimum
IN NS localhost.
1 IN PTR localhost.
example.com.zone:是我们为自己的域的正向解析配置。
example.com. IN SOA ns1.example.com. root.example.com. (
2007091701 ; Serial
30800 ; Refresh
7200 ; Retry
604800 ; Expire
300 ) ; Minimum
IN NS ns1.example.com.
* IN A 192.168.0.2 ; 将所有域名都泛解析到192.168.0.2上
OK,这几个配置文件写好之后,启动命令行,输入以下命令:
C:\> named -f -g -d 1
即可在控制台启动named。如果不能启动请仔细观察输入结果并自行查找错误。
然后你可以用dig命令来测试返回结果是否正确。
C:\> dig www.google.com
C:\> dig www.sina.com.cn
你也可以打开浏览器,看看能否正常上网。另外因为我们配置了 example.com 的域,所以 abc.example.com 应该能访问你架设在 192.168.0.2 上的 Web 服务器。
一切正常访问之后,我们还有一件事情要做:配置使用 rndc 命令来控制bind。请执行以下命令: C:> cd C:\Windows\system32\dns\etc C:\Windows\system32\dns\etc> rndc-confgen > rndc.conf
即可在 C:\Windows\system32\dns\etc 下生成 rndc.conf 文件。编辑这个文件,并将该文件的后半部分剪切到 named.conf 末尾,配置即完成。
重启 named,然后在命令行输入 rndc reload,应该能在named的控制台看到重新加载配置文件的信息,说明配置成功。
最后一步,利用srvany将named安装为服务,即大功告成。(srvany需要安装Windows 2003 Server Resource Kit)
instsrv ntbind C:\Windows\system32\dns\bin\named.exe
参考文献
■Replace ms dns with bind9
■DNS HOWTO, 4.forwarding
■内部向けDNSサーバの構築
■名前解決の仕組みとゾーンファイルの設定
此条目由 charlee 发表在 software 分类目录,并贴了 bind、dns、server 标签。将固定链接加入收藏夹。
Windows Servers 2003企业版的IE的安全级别被限制为高级,一般网站无法访问,如何在不添加信任站点的情况下更改安全级别呢?
由于Windows Server 2003是微软为服务器设计的操作系统,所以微软认为使用服务器进行Internet浏览会增加服务器遭受潜在安全攻击的可能性,因此在默认设置下,Windows Server 2003系统启用了系统内的Internet Explorer增强安全配置。在这种安全设置之下,可以降低服务器遭受潜在安全攻击的可能性,但同时该设置将使部分网页无法正常显示,并且在浏览的过程中经常会发生需要将目标网站加入到信任站点列表后才能够访问的问题,个人用户使用起来会非常不便,因此我们需要改变这项安全设置。
如果您决定不使用Internet Explorer增强的安全配置,则可通过“开始|控制面板|添加或删除程序”功能,在“添加或删除程序”对话框中单击“添加/删除Windows组件”。在弹出对话框中列出的Windows组件中清除“Internet Explorer 增强的安全配置”的选中状态,然后单击完成,就可以在重启动Internet Explorer浏览器后使增强的安全设置失效。
如果您想保留增强的安全设置功能,而又希望尽量减少它带来的不便,那么可以在打开浏览器时弹出“系统已启动增强的安全设置”警告对话框时,选中左下角的“以后不显示这个信息”对话框来避免每次转到新的网页都收到一次警告。
或者,您也可以点击“开始|控制面板|Internet选项”,在“Internet选项”对话框中单击“安全”选项卡,拉动滑块将Internet、本地Intranet、受信任的站点或受限制站点等区域按照您的需要进行设置