-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMessageBox.m
45 lines (40 loc) · 1.54 KB
/
MessageBox.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <Cocoa/Cocoa.h>
@interface Window : NSWindow {
NSButton* buttonShowMessage;
}
- (IBAction) OnButtonClick:(id)sender;
- (BOOL)windowShouldClose:(id)sender;
@end
@implementation Window
- (instancetype)init {
buttonShowMessage = [[[NSButton alloc] initWithFrame:NSMakeRect(10, 265, 100, 32)] autorelease];
[buttonShowMessage setTitle:@"MessageBox"];
[buttonShowMessage setBezelStyle:NSBezelStyleRounded];
[buttonShowMessage setTarget:self];
[buttonShowMessage setAction:@selector(OnButtonClick:)];
[buttonShowMessage setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
[super initWithContentRect:NSMakeRect(100, 100, 300, 300) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO];
[self setTitle:@"MessageBox example"];
[[self contentView] addSubview:buttonShowMessage];
[self setIsVisible:YES];
return self;
}
- (IBAction) OnButtonClick:(id)sender {
NSAlert* alert = [[NSAlert alloc] init];
[alert setMessageText:@"Message"];
[alert setInformativeText:@"Hello, World!"];
[alert setAlertStyle:NSAlertStyleCritical];
[alert addButtonWithTitle:@"OK"];
//[alert addButtonWithTitle:@"Cancel"];
[alert beginSheetModalForWindow:self completionHandler:^(NSModalResponse returnCode) {}];
}
- (BOOL)windowShouldClose:(id)sender {
[NSApp terminate:sender];
return NO;
}
@end
int main(int argc, char* argv[]) {
[NSApplication sharedApplication];
[[[[Window alloc] init] autorelease] makeMainWindow];
[NSApp run];
}