How to display error messages?

本文提供了一个使用Windows API中的MessageBox函数展示不同样式消息框的示例代码。通过四种不同的消息类型(错误、警告、信息及询问)展示了消息框的基本用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Try this one, it displays four different styles messages, maybe you get the idea of how message boxes work. The last one prompts you with a question.

  1. #include <windows.h>
  2. int main(int argc, char* argv[])
  3. {
  4. MessageBox(NULL, "Serious error", "<Message title here>", MB_ICONSTOP|MB_SETFOREGROUND);
  5. MessageBox(NULL, "Warning", "<Message title here>", MB_ICONEXCLAMATION|MB_SETFOREGROUND);
  6. MessageBox(NULL, "Info", "<Message title here>", MB_ICONINFORMATION|MB_SETFOREGROUND);
  7. if(IDYES == MessageBox(NULL, "Click Yes or No",
  8. "<Message title here>",
  9. MB_ICONQUESTION|MB_YESNO|MB_SETFOREGROUND))
  10. {
  11. MessageBox(NULL, "You clicked Yes",
  12. "<Message title here>",
  13. MB_ICONINFORMATION|MB_SETFOREGROUND);
  14. }
  15. else
  16. {
  17. MessageBox(NULL, "You clicked No",
  18. "<Message title here>",
  19. MB_ICONINFORMATION|MB_SETFOREGROUND);
  20. }
  21. return 0;
  22. }
转自:http://www.daniweb.com/software-development/cpp/threads/109791/how-to-display-error-messages
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值