Win32自定义消息框
我想制作一个自定义消息框。我想要自定义的是按钮的文本。
MessageBoxW(
NULL,
L"Target folder already exists. Do you want to overwrite the folder?",
L"No title",
MB_YESNOCANCEL | MB_ICONQUESTION
);
我只想将按钮文本更改为覆盖
、跳过
、取消
。
最简单的方法是什么?
我必须使其与 Windows 默认消息框具有相同的外观和感觉。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如其他人所说,典型的方法是创建一个对话框资源并拥有一个完全独立的对话框,您需要以看起来像标准对话框的方式设计该GUI(以满足您对感觉和外观的要求)。如果您想接受短信,您可能需要添加适当调整窗口大小的代码。
不过,对于那些想要深入研究高级事物的人来说,还有另一种选择。虽然
MessageBox
API 没有提供太多的 fint 调整功能,但您仍然可以使用SetWindowsHookEx
。注册钩子后,您可以拦截标准MessageBox
窗口过程并按照您喜欢的方式对其进行子类化。典型的事情包括:
标准窗口可以执行所有这些操作。
UPD。嘿,我意识到我有一些
SetWindowsHookEx
代码可以分享:http://alax.info/blog/127< /a>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 haveSetWindowsHookEx
in your hands. Having registgered the hook, you can intercept standardMessageBox
window procedure and subclass it in the way you like.Typical things include:
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您可以创建一个自己的对话框。或者,您可以使用本文中所述的窗口挂钩。
该文章的存档版本可以在 web.archive.com。
You could create an own dialog. Or you could use a window hook as described in this article.
An archived version of the article can be found on web.archive.com.
创建一个对话框资源(使用 GUI 编辑器或手动)并调用
DialogBox
就可以了。除了其参数支持的行为之外,无法改变MessageBox
的行为。也就是说,您的消息框可以很好地使用库存是/否选项。
Make a dialog resource (with a GUI editor, or by hand) and call
DialogBox
on it. There's no way to alterMessageBox
behaviour, other than what's supported by its arguments.That said, your message box can very well use stock Yes/No options.
Vista 中引入的任务对话框功能完全按照您的要求进行操作并遵循流行的系统主题。但是,如果您必须支持 XP,那么这对您来说就不太舒服了。
The task dialog functionality introduced in Vista does exactly what you want and follows the prevailing system theme. However, if you have to support XP, then this will be of little comfort to you.
我知道这个问题很老了,但我现在才偶然发现它。
我想扩展有关使用
TaskDialog
而不是MessageBox
的其他答案。下面是一个使用 TaskDialog 来精确执行所要求的操作的简洁示例; 更改按钮的文本:一些值得注意的事情:
TaskDialogIndirect
,而不是基本的TaskDialog
函数pszMainIcon
中指定的内容也会显示在标题栏中。MB_ICONQUESTION
等效的内容,引用来自 此论坛帖子:< code>不要使用问号图标来提问。再次强调,仅对帮助入口点使用问号图标。无论如何,都不需要使用问号图标来提问 - 将主指令作为问题就足够了。TaskDialogIndirect
并在返回时检查其值(文档应该很清楚)I know this question is old, but I just stumbled upon it now.
I would like to expand the other answers in regards to using a
TaskDialog
instead of aMessageBox
. Here's a concise example of using a TaskDialog to do precisely what was asked; change the button's texts:Some noteworthy things:
TaskDialogIndirect
, not the basicTaskDialog
functionpszMainIcon
is displayed in the title bar as wellMB_ICONQUESTION
, quoting a quote from this forumpost:Don't use the question mark icon to ask questions. Again, use the question mark icon only for Help entry points. There is no need to ask questions using the question mark icon anyway—it's sufficient to present a main instruction as a question.
TaskDialogIndirect
and checking its value on return (the documentation should be pretty clear)这里是一个小型开源库,可以让您自定义消息框。由 Hans Ditrich 开发。
我已在另一个允许嵌入此类 MessageBox 中的自定义图标甚至可以从 控制台应用程序。
我还应该指出任务对话框。这是使用它的示例:
Here is a small open source library that allows you to customize Message Boxes. Developed by Hans Ditrich.
I have successfully used it in another POC that allows embedding a custom icon in such MessageBox that can be called even from a Console application.
I should also point to the Task Dialog. Here is an example of using it: