gpt4 book ai didi

c++ - 从 C++ 在 Mac OSX 上启动一个打开的对话框

转载 作者:太空狗 更新时间:2023-10-29 23:04:42 24 4
gpt4 key购买 nike

我有一个包含代码的头文件

#ifndef PLATFORM_DEPENDENCE
#define PLATFORM_DEPENDENCE

#define USE_MAC
#include "WindowsFunctions.h"
#include "MacFunctions.h

#endif

WindowsFunctions.h:

#ifndef WINTRANSFERINCLUDE
#define WINTRANSFERINCLUDE
#ifdef USE_WINDOWS

#include <string>
#include <boost/shared_ptr.hpp>

using namespace std;

#include <windows.h>
#include <Shlobj.h>

boost::shared_ptr<wstring> browseFolder();
boost::shared_ptr<vector<wstring>> getFilesInDirRecursiveImplementation(boost::shared_ptr<vector<wstring>> dirs, boost::shared_ptr<vector<wstring>> files);

#endif
#endif

和 MacFunctions.h:

#ifndef MACTRANSFERINCLUDE
#define WACTRANSFERINCLUDE
#ifdef USE_MAC

#include <string>
#include <boost/shared_ptr.hpp>

using namespace std;

boost::shared_ptr<wstring> browseFolder();
boost::shared_ptr<vector<wstring>> getFilesInDirRecursiveImplementation(boost::shared_ptr<vector<wstring>> dirs, boost::shared_ptr<vector<wstring>> files);

#endif
#endif

WindowsFunctions.cpp 已经实现,并且可以运行。我将如何为 Mac 做这件事?我已经编写了一个打开对话框的方法,但我不知道如何将数据返回到在 C++ 中调用它的位置。

这是打开对话框的代码:

#import <Cocoa/Cocoa.h>
#include <string>

std::string* path() {
NSOpenPanel *op = [NSOpenPanel openPanel];
if ([op runModal] == NSOKButton) {
NSURL *nsurl = [[op URLs] objectAtIndex:0];
// nsurl.path contains the NSString I want to return as std::string
}
// ???
return something;
}

我该怎么做,或者我是否以错误的方式解决了这个问题?

最佳答案

有点啰嗦,但就是这样:

std::string([[nsurl path] UTF8String]);

编辑:好吧,所以也许不是长篇大论。

关于c++ - 从 C++ 在 Mac OSX 上启动一个打开的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22068159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com