如何使用 Windows MessageBox() C 函数?

Wix*_*Wix 2 c windows messagebox

有人能告诉我如何在 C 中显示可以打印变量的消息框吗?

我的意思是这样的:

#include <stdio.h>
#include <windows.h>

main()
{
    int x = 5;
    MessageBox(0, "Variable x is equal to %d", "Variable", 0); 
    /* Where do I specify the variable so that 5 will display?*/

    getch();
}
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

          Variable

 Variable x is equal to 5.
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Bar*_*chs 5

MessageBox本身不支持printf像格式。您必须为此使用snprintf

char buf[1024];
snprintf(buf, 1024, "Variable x is equal to %d", x);

MessageBox(0, buf, "Variable", 0);
Run Code Online (Sandbox Code Playgroud)