gpt4 book ai didi

c++ - 将 TaskDialogConfig 与 std::string 一起使用

转载 作者:行者123 更新时间:2023-11-28 02:59:10 25 4
gpt4 key购买 nike

我正在尝试使用 TASKDIALOGCONFIG 结构创建一个任务对话框。我的应用程序使用 Unicode。这是我的代码:

string error_text = get_error_text();
string error_code = get_error_code();

TASKDIALOGCONFIG tdc = { sizeof(TASKDIALOGCONFIG) };
tdc.dwCommonButtons = TDCBF_OK_BUTTON;
tdc.pszMainIcon = TD_ERROR_ICON;
tdc.pszWindowTitle = _T("Error");
tdc.pszContent = error_text.c_str(); /* of course this will give a
const char* instead of a wchar_t* */
tdc.pszExpandedInformation = error_code.c_str(); // here is the same thing
tdc.hwndParent = m_wndParent;

TaskDialogIndirect(&tdc, NULL, NULL, NULL);

我已经研究了一下这个问题,但我还没有找到解决方案。谁能帮帮我?

最佳答案

你有两个选择:

  1. 使用 ANSI 文本。使用 TASKDIALOGCONFIGATaskDialogIndirectA 执行此操作。
  2. 使用 Unicode 文本。将字符串从 std::string 切换到 std::wstring

我个人会推荐后一种选择。

我还建议您不要使用 tchar.h,并停止使用 _T(...)。由于您只针对 Unicode,因此您应该编写 L"Error" 而不是 _T("Error")。如果您正在编写必须为 MBCS 和 Unicode 目标编译的代码,那么使用 tchar.h 才有意义。在我们需要为 Win 95/98 和 Win NT/2000 编译的日子里,这是一个必要的邪恶。但那些日子早已一去不复返了。

关于c++ - 将 TaskDialogConfig 与 std::string 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21293147/

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