Click to See Complete Forum and Search --> : How to create push buttons with icons on them?


josedsilva
April 20th, 2005, 01:53 AM
Hi,

How can I create icons on command buttons? These command buttons are drawn on a dialog template created in the resource editor.
I tried obtaining a device context to the command button on receipt of WM_DRAWITEM and WM_CTLCOLORBTN messages and using the DrawIcon() API.
But, the icon was painted beneath the command button.
I want to create a command button with an icon painted on it.

Thanks,
Jose D'silva

soorajchirag
April 20th, 2005, 03:35 AM
Hi,

I did try something like this some time back. I just recall it slightly....

You can get the Window for the Button using GetWindow() and change its icon using SetIcon()....

This should work

Regards
Soorajchirag

Elementer
April 20th, 2005, 06:25 PM
If you need only a image button for your application, I suggest you to get a image button control troughout the web, I remember to see something but I don't remember where, but I think there are a lot of image button .ocx and others...

Regards

g_gili
April 21st, 2005, 03:37 AM
Hi,

How can I create icons on command buttons? These command buttons are drawn on a dialog template created in the resource editor.
I tried obtaining a device context to the command button on receipt of WM_DRAWITEM and WM_CTLCOLORBTN messages and using the DrawIcon() API.
But, the icon was painted beneath the command button.
I want to create a command button with an icon painted on it.

Thanks,
Jose D'silva
If you want bitmapp buttons you can try this
CBitmapButton myButton;

// Create the bitmap button (must include the BS_OWNERDRAW style).
myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
CRect(10,10,100,100), pParentWnd, 1);

// Load the bitmaps for this button.
myButton.LoadBitmaps(IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE);

josedsilva
April 26th, 2005, 01:14 PM
Thanks guys,

I found a solution to this question. You need to process the WM_INITDIALOG message and Send a message to the command button.
E.g.
case WM_INITDIALOG:

SendDlgItemMessage(hDlg,IDC_MYBUTTON,BM_SETIMAGE,(WPARAM) IMAGE_ICON, (LPARAM) hIcon);
......
break;


Please read the MSDN documentation for the correct syntax of SendDlgItemMessage();

Andreas Masur
April 26th, 2005, 03:44 PM
[ Merged threads ]