Solved

Button no longer looks like a button...

Posted on 2000-03-16
9
293 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
  • 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 59 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.  …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now