开发者

how to show text an d icon on button in win 32 c++? [duplicate]

This question already has an answer here: How to put an icon on a text button? 开发者_开发知识库 (1 answer) Closed 5 years ago.

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));

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?


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 Control Example: http://www.codeguru.com/cpp/controls/buttonctrl/advancedbuttons/article.php/c5161

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.

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.

Search Example: Win32 ownerdraw button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜