如何使用 Windows MessageBox() C 函数? [英] How to use the Windows MessageBox() C function?

查看:48
本文介绍了如何使用 Windows MessageBox() C 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can someone tell me how I can display a message box in C that can print variables?

我的意思是这样:

#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();
}

看起来像这样:

          Variable

 Variable x is equal to 5.

提前致谢!

推荐答案

MessageBox 本身不支持printf 之类的格式.为此,您必须使用 snprintf :

MessageBox itself doen't support printf like formatting. You'll have to use snprintf for that:

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

MessageBox(0, buf, "Variable", 0);

这篇关于如何使用 Windows MessageBox() C 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆