0

我正在尝试使用结构创建一个任务对话框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);

我已经研究了这个问题,但我还没有找到解决方案。有人可以帮助我吗?

4

1 回答 1

2

你有两个选择:

  1. 使用 ANSI 文本。通过使用TASKDIALOGCONFIGA和来做到这一点TaskDialogIndirectA
  2. 使用 Unicode 文本。将您的字符串从 切换std::stringstd::wstring

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

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

于 2014-01-22T20:22:58.523 回答