OWNER DRAW Button painting problem

Windows specific questions.
Post Reply
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

OWNER DRAW Button painting problem

Post by kcvinu »

Hi all,
I have two owner draw buttons. (lets say ODB )
I am using WM_DRAWITEM message to paint these buttons.
this is the pseudo code
if mouse is entered on the ODB
invalidate the ODB
if mouse leave from ODB
invalidate the ODB
In the WM_DRAWITEM message, i handled the drawing like this -
if mouse is on ODB
change back color of ODB
if mouse leaved from ODB
revert the back color change
if ODB is clicked
change back color of ODB
So this is my idea. But if i click on one ODB, then another ODB change its back color.
So how to stop this behaviour. How do i ensure that only clicked button is change its color.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: OWNER DRAW Button painting problem

Post by jj2007 »

How do you check which button is responsible for the WM_DRAWITEM message?
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: OWNER DRAW Button painting problem

Post by kcvinu »

@jj2007,
To be frank, I think i dont know. My drawing function takes only one parameter. It is an LPDRAWITEMSTRUCT . I know that the struct contains an hwndItem member. here is the pseudo code of this drawing function for clarity.

1. CButton is a User Defined Type. (Lets say a class)
2. This class has a CreateButton() method. And it has some properties like backColor, foreColor, hoverBackColor, hoverForeColor, clickBackColor, clickForeColor etc.
3. There is another class named Window. It has a dictionary property. (key : HWND, value : Control). Here, Control means any control, it could be a CButton, a Label, a TextBox etc. When i create a control, i just put the newly created CButton's handle and CButton class into this dictionary.
4. The WndProc function of CButton is subclassed. So hwnd = a CButton handle. So i can get the CButton class by searching for the hwnd key in that dictionary. After getting the class object, i can pass the class properties like backColor and foreColor to the GDI functions. This is what i am doing.
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: OWNER DRAW Button painting problem

Post by kcvinu »

@jj2007,
At last, I found the problem !!
It was the second parameter of the InvalidateRect() function. In wm_mousemove and wm_mouseleave msgs, i call this IvalidateRect with second parameter as "NULL". After a long time virtual debugging, i found that it accepts the rect of the control. Now, i can control which button should be painted. Thanks for guiding me.
Post Reply