Messagebox检测YesNoCancel按钮

use*_*531 3 c++ vcl messagebox

我在C++ Builder中使用VCL Forms应用程序.我可以在某些代码中帮助显示带有YesNoCancel按钮的消息框,然后检测是否按下了是,否或取消按钮.

这是我的代码:

if(MessageBox(NULL, "Test message", "test title",  MB_YESNOCANCEL) == IDYES)
{

}
Run Code Online (Sandbox Code Playgroud)

我包括以下内容:

#include <windows.h>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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);
Run Code Online (Sandbox Code Playgroud)

值:integerNumberOfImportantAppointments是一个整数.如何在消息框中显示?

我收到以下错误:无效的指针添加.

此外,我可以选择消息框的图标吗?这种情况下的一个问题.

Mar*_*ram 10

干得好.您需要在调用中使用宽字符,MessageBox并且需要将结果存储在变量中,然后再确定下一步操作.

const int result = MessageBox(NULL, L"Test message", L"test title",  MB_YESNOCANCEL);

switch (result)
{
case IDYES:
    // Do something
    break;
case IDNO:
    // Do something
    break;
case IDCANCEL:
    // Do something
    break;
}
Run Code Online (Sandbox Code Playgroud)

更新,问题编辑后:

// Format the message with your appointment count.
CString message;
message.Format(L"You have %d important appointments. Do you wish to view them?", integerNumberOfImportantAppointments);

// Show the message box with a question mark icon
const int result = MessageBox(NULL, message, L"test title",  MB_YESNOCANCEL | MB_ICONQUESTION);
Run Code Online (Sandbox Code Playgroud)

您应该阅读MessageBox的文档.