如何在win 32 c ++中的按钮上显示文本和图标? [英] how to show text an d icon on button in win 32 c++?

查看:31
本文介绍了如何在win 32 c ++中的按钮上显示文本和图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同时获得图标和文本,所以我没有在我的按钮上设置 BM_ICON.在WM_INITDIALOG(是的,按钮在对话框中)我说:

I wanted to get both icon and text, so I didn't set BM_ICON on my button. In WM_INITDIALOG (yes, the button is in a dialog) I say:

SendDlgItemMessage(hwndDlg, IDC_CREATE, BM_SETIMAGE, IMAGE_ICON, reinterpret_cast<LPARAM>(create_image));

它不起作用.该按钮仅显示文本.现在,如果我确实设置了 BS_ICON样式,它有效,但没有文字,如文档所述.以防万一,create_image 实例化如下:

It doesn't work. The button shows text only. Now, if I do set the BS_ICON style, it works, but there's no text, as documented. Just in case, create_image is instantiated as follows:

create_image = LoadImage(g_current_instance, MAKEINTRESOURCE(IDI_ICONCREATE), IMAGE_ICON, 32, 32, LR_SHARED);

那么我该如何让它发挥作用呢?

So how do I make it work?

推荐答案

我相信您想要的是OwnerDraw"按钮.您可以在它们上面混合文本和图形.您提供 3 个按钮状态,它会根据您的指示绘制.

I believe what you want is called an "OwnerDraw" button. You can mix text and graphics on them. You provide the 3 button-states and it draws what you tell it.

Ownerdraw 控件示例:http://www.codeguru.com/cpp/controls/buttonctrl/advancedbuttons/article.php/c5161

Ownerdraw Control Example: http://www.codeguru.com/cpp/controls/buttonctrl/advancedbuttons/article.php/c5161

上面的链接可能有点极端,但您现在可以使用搜索词来查找大量示例.我记得 Petzolds 的Programming Windows"也有一个例子.

The link above might be a bit extreme, but you now have a search term to find lots of examples. I remember Petzolds "Programming Windows" also has an example.

请注意,您可以使用这些按钮制作非矩形按钮.通常,当您在 Windows 上看到形状怪异的按钮时,他们就是这样做的.

Note that you can make non-rectangular buttons with these. Generally when you see a weird shaped button on Windows, this is how they do it.

搜索示例:Win32 ownerdraw 按钮.

Search Example: Win32 ownerdraw button.

这篇关于如何在win 32 c ++中的按钮上显示文本和图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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