?
Solved

Button no longer looks like a button...

Posted on 2000-03-16
9
Medium Priority
?
307 Views
Last Modified: 2013-12-03
Hi,

I am trying to customise the background colour of the buttons on my Win32 dialog (e.g. 1 red and 1 yellow). I have been investigating WM_CTLCOLORBTN and it only works with owner drawn buttons.

I have a MESSAGE_HANDLER() for the WM_CTLCOLORBTN and it is called before every button is drawn and if it is an owner drawn button the button will change its background colour to the HBRUSH that the message returns.

The only problem is, when the dialog displays, the button just looks like a flat rectangle. It is no longer raised like a button and I have lost the text on the button face.

Can anyone help me with this.. I have searched the archives and can't figure out why this has happened.. Do I have to supply the button images myself?!?!?!

Thanks in advance..

Emma
0
Comment
Question by:middlel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 5

Expert Comment

by:vachooho
ID: 2624758
you must overwrite OnDrawItem() and draw your button itself.
It is ownerdrawn!
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 236 total points
ID: 2625819
MS SDK says:

Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or BS_PUSHLIKE styles do not use the returned brush. Buttons with these styles are always drawn with the default system colors. Drawing push buttons requires several different brushes-face, highlight and shadow-but the WM_CTLCOLORBTN message allows only one brush to be returned. To provide a custom appearance for push buttons, use an owner-drawn button.
0
 

Author Comment

by:middlel
ID: 2627253
My button is an owner-drawn button.. So I have to handle the OnDraw message and provide 2 bitmaps.. One for the 3D look and one for how it looks when it has been pressed...? How do I make sure that the button is displayed properly when it is clicked and not clicked?

Would I have to send some kind of draw message when the user clicks..?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 15

Expert Comment

by:NickRepin
ID: 2627346
In the WM_DRAWITEM handler, you have to check DRAWITEMSTRUCT.itemState member and draw the button accordingly.

ODS_DISABLED - button is disabled
(if your button can be disabled)

ODS_FOCUS - draw the focus rectangle (if you need it)

ODS_SELECTED - the button is pressed.
0
 

Author Comment

by:middlel
ID: 2627443
I have added a WM_DRAWITEM message for the dialog and it necer gets called.. I was hoping that the message would be on the parent control and it would just tell me which button the message was for.. Do I need to specifically handle the WM_DRAWITEM for each control..?

Also how do I tell the dialog to draw the button with my selected bitmap or default bitmap etc...

I was originally just coloring the button in with the following code when I handled the WM_CTLCOLORBTN message:

/*      HBRUSH hBrush = 0;

      ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);

      DeleteObject(hBrush);
      
      hBrush = CreateSolidBrush(RGB(255,0,0));  
      
      return (LRESULT)hBrush;
*/
0
 

Author Comment

by:middlel
ID: 2628561
I have managed to get the button to work now.. I did have to create 3 images and I had to handle the item action in the LPDRAWITEMSTRUCT and if it was a selected action, I then had to check the item state to see if it was being selected or if it had just obtained the focus.. It was a real long winded process though..

Just one more question though... Why have I lost my button text.? Is there any way to get it back.? I tried calling TextOut() on the hDC but it didn't do anything..

thanks in advance

Emma
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2629732
You have to draw the text yourself every time when you draw the button.
Do it after drawing the bitmap.

TextOut must work fine, but it's better to use DrawText().
0
 

Author Comment

by:middlel
ID: 2636253
Ok, using DrawText() has displayed the title but the area immediately behind the text is now grey again...? I have tried to make it transparent but can't find anything to do that..?

Cheers!

Emma
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2637912
SetBkColor/SetTextColor or SetBkMode/SetTextColor
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question