我正在使用C++ Builder中的VCL表单应用程序。 请帮我编写一些代码,以显示具有YesNoCancel按钮的消息框,然后检测是否按下了是、否或取消按钮。
以下是我的代码:
if(MessageBox(NULL, "Test message", "test title", MB_YESNOCANCEL) == IDYES)
{
}
我已经包含了以下内容:
#include <windows.h>
我收到以下错误:
E2034 无法将 'char const[13]' 转换为 'const wchar_t *'
E2342 参数 'lpText' 的类型不匹配 (需要 'const wchar_t *',得到 'const char *')
更新
这是我的代码:
const int result = MessageBox(NULL, L"You have " + integerNumberOfImportantAppointments + " important appointments. Do you wish to view them?", L"test title", MB_YESNOCANCEL);
变量 integerNumberOfImportantAppointments 是一个整数,如何在消息框中显示它?
我遇到了以下错误: 无效的指针加法。
另外,我可以选择消息框的图标吗?在这个案例中是一个问题。
CString
是微软MFC类。对于C++Builder VCL,请改用WideString
(C++Builder 2007或更早版本)或UnicodeString
(C++Builder 2009或更高版本),例如:WideString s = "You have " + IntToStr(integerNumberOfImportantAppointments) + " important appointments. Do you wish to view them?"; MessageBox(NULL, s.c_bstr(), ...);
或UnicodeString s = "You have " + IntToStr(integerNumberOfImportantAppointments) + " important appointments. Do you wish to view them?"; MessageBox(NULL, s.c_str(), ...);
。 - Remy Lebeau