5
我想知道一种方法来从C++应用程序打开OS X上的默认浏览器,然后打开请求的URL。C++ OS X打开默认浏览器
编辑:我解决了它这样的:
system("open http://www.apple.com");
我想知道一种方法来从C++应用程序打开OS X上的默认浏览器,然后打开请求的URL。C++ OS X打开默认浏览器
编辑:我解决了它这样的:
system("open http://www.apple.com");
如果你喜欢使用的system("open ...")
本地OS X的API,而不是您可以使用此代码:
#include <string>
#include <CoreFoundation/CFBundle.h>
#include <ApplicationServices/ApplicationServices.h>
using namespace std;
void openURL(const string &url_str) {
CFURLRef url = CFURLCreateWithBytes (
NULL, // allocator
(UInt8*)url_str.c_str(), // URLBytes
url_str.length(), // length
kCFStringEncodingASCII, // encoding
NULL // baseURL
);
LSOpenCFURLRef(url,0);
CFRelease(url);
}
int main() {
string str("http://www.example.com");
openURL(str);
}
,你必须用正确的OS X架构编译:
g++ file.cpp -framework CoreFoundation -framework ApplicationServices
看的文档进行Launch Services。