Win32自定义消息框 [英] Win32 custom message box

查看:161
本文介绍了Win32自定义消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个自定义消息框.我要自定义的是按钮的文字.

MessageBoxW(
  NULL,
  L"Target folder already exists. Do you want to overwrite the folder?",
  L"No title",
  MB_YESNOCANCEL | MB_ICONQUESTION
  );

我只想将按钮文本更改为OverwriteSkipCancel.
最简单的方法是什么?

我必须使它具有与Windows默认消息框相同的外观.

解决方案

正如其他人所说,一种典型的方法是创建一个对话框资源并拥有一个完全独立的对话框,您需要按照其外观设计GUI类似于标准对话框(以满足您对外观的要求).如果您想接受短信,则可能需要添加代码以适当调整窗口大小.

不过,对于那些想深入研究高级事物的人来说,还有另一种选择.尽管MessageBox API不能提供很多用于fint调整的功能,但您仍然可以使用SetWindowsHookEx.在注册了钩子之后,您可以拦截标准的MessageBox窗口过程,并以自己喜欢的方式将其子类化.

典型的事情包括:

  • 更改按钮文字
  • 添加更多控件
  • 添加定时自动关闭

连接标准窗口可以完成所有这些操作.

UPD.嘿,我意识到我有一些与SetWindowsHookEx共享的代码: http://alax.info/blog/127

I want to make a custom message box. What I want to customize is the button's text.

MessageBoxW(
  NULL,
  L"Target folder already exists. Do you want to overwrite the folder?",
  L"No title",
  MB_YESNOCANCEL | MB_ICONQUESTION
  );

I'd like to just change the buttons text to Overwrite, Skip, Cancel.
What's the most simple way?

I have to make this as having same look and feel with Windows default messagebox.

解决方案

As said by others, a typical way is to create a dialog resource and have a completely independent dialog, which GUI you need to design in the way that it looks like standard dialog (to meet your request for feel and look). If you want to accept text messages, you might probably need to add code which resizes the window appropriately.

Still, there is another option for those who feel like diving into advanced things. While MessageBox API does not offer much for fint tuning, you still have SetWindowsHookEx in your hands. Having registgered the hook, you can intercept standard MessageBox window procedure and subclass it in the way you like.

Typical things include:

  • changing button text
  • adding more controls
  • adding timed automatic close

Hooking standard window can do all of those.

UPD. Hey, I realized I have some code with SetWindowsHookEx to share: http://alax.info/blog/127

这篇关于Win32自定义消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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