How to draw a rectangle in mouse move event

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

How to draw a rectangle in mouse move event

Post by kcvinu »

Hi all,
I have an owner draw button. Now, i want to draw a rectangle (or change the back color of the button) when user moves mouse pointer in the button rect. And of course, i want to delete it in the mouse leave event.
This button is a subclassed one. So i can get the mouse move and mouse leave events easily and i am using TrackMouseEvent also.
Now, this is my plan and i didn't test it yet.
1. Register two user defined messages with either wm_app or with wm_user. ( I don't know which is better. )
a) MY_MSG_DRAW_RECT
b) MY_MSG_ERASE_RECT
2. In button's mouse move event set a global flag variable as true and send the MY_MSG_DRAW_RECT message to parent window.
3. In parent window's WndProc, receive this message and draw the rectangle around button and update window
4. In button's mouse leave event, set the global flag variable as false and send the MY_MSG_ERASE_RECT message to parent window
4. In parent window's WndProc, if i receive the MY_MSG_ERASE_RECT message, then erase the rectangle and update window.
Please guide me to solve this problem. Thanks in advance.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: How to draw a rectangle in mouse move event

Post by D.J.Peters »

Often GUI's controls create an MOUSE_ENTER and MOUSE_LEAVE events
(if the control is an event receiver and enabled of course)
If this kind of events are fired you can highlight the control (change the colors and or change the shape)

Joshy
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: How to draw a rectangle in mouse move event

Post by kcvinu »

@ D.J.Peters,
Thanks for the reply.
Bu i think i am having hard time. I can send the wm_user message to parent window. Parent is receiving that too, but parent is not calling WM_DRAWITEM after that.
I have wrote code to change the button backcolor in WM_DRAWITEM handler. Specially when (itemState and ODS_HOTLIGHT) is become true. But nothing is happening. I dont know why.
My assumption is that itemState member of DRAWITEMSTRUCT will handle when i hover mouse on a button.
Post Reply