[英]Create alert / message box in command line OSX app
我正在嘗試創建一個僅打開警報的簡單應用。 所以想象一下
int main(int argc, const char * argv[]) {
int result = SomeMagicAlertFunction("Hello World", "Yes", "No");
printf("User picked: %d¥n", result);
}
我已經找到了有關NSAlert
一些信息,但所有示例均適用於完整的OSX Apps,該類帶有如下所示的應用程序包
+-MyApp.app
|
+-Contents
|
+-MacOS
|
+-MyApp
等等,但是我只想在命令行應用程序中發出警報。 一個文件,而不是應用程序包。 在OSX的C / C ++或Objective C中可能嗎? 我看到了有關NSRunAlertPanel
但是在優勝美地中已刪除,並說要使用NSAlert
。
稍后找到答案
#import <Cocoa/Cocoa.h>
void SomeMagicAlertFunction(void) {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Delete the record?"];
[alert setInformativeText:@"Deleted records cannot be restored."];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] == NSAlertFirstButtonReturn) {
}
//[alert release];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.