Solved

Button no longer looks like a button...

Posted on 2000-03-16
9
304 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…

733 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