Solved

Changing Bitmaps Drawn Over An Ownerdraw Push Button On/Off On Mouse Hover..

Posted on 2004-04-06
5
437 Views
Last Modified: 2013-12-03
Hi All,
Here comes the same stuff again.. no dialog-box nothing, just a main window, ghwndApp, created with CreateWindowEx(......), on the top of it one command button created like,

HWND hwndcommand1=CreateWindow("BUTTON",NULL,WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON | BS_BITMAP | BS_OWNERDRAW | BS_FLAT,600,320,169,48,ghwndApp,NULL,(HINSTANCE)GetWindowLong(ghwndApp,GWL_HINSTANCE),NULL);

It's a Ownerdraw, bitmap button, I used WM_DRAWITEM Message To Paint the Button with the HBITMAP bitmap1 (already loaded).

All works fine.
Now what I want more is to change the bitmap over the button to a different picture  (that bitmap also loaded) when the mouse is over the button and back to the old bitmap when the mouse is not.

For that I guess,  I have to _TrackMouseEvent() for this command button window, hwndcommand1
I did the same just after creating the button as::

TRACKMOUSEEVENT track1;
track1.cbSize=sizeof(TRACKMOUSEEVENT);
track1.dwFlags=TME_HOVER | TME_QUERY;
track1.hwndTrack=(HWND)hwndcommand1;
track1.dwHoverTime=HOVER_DEFAULT;


_TrackMouseEvent(&track1);

But I am not getting any sort of WM_MOUSEHOVER, when I move mouse over this button.

How can we achieve this kind of stuff, please show some guidelines. To change bitmaps over a button, one while normal and one while the mouse is over it.

Thank You.

Regards,
Bonns
0
Comment
Question by:bonnseye
5 Comments
 
LVL 6

Expert Comment

by:joghurt
ID: 10769047
Isn't your WM_MOUSEHOVER handler called at least once? You should put a breakpoint or message box there.
Probably you may include a bit more of your source.

- "Hover tracking stops when WM_MOUSEHOVER is generated. The application must call TrackMouseEvent again if it requires further tracking of mouse hover behavior." [from MSDN]
- How do you change the bitmap? Do you call Invalidate so that the button gets redrawn?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 100 total points
ID: 10769068
WM_MOUSEHOVER is posted to Button and not to it's parent window. Subclass button and handle this message in button window procedure.
0
 

Author Comment

by:bonnseye
ID: 10774377
Thanks joghurt and AlexFM
joghurt, it is not called even once, there is one message box already over there,
Yes MSDN says that you should call TrackMouseEvent() again for further tracking after wm_mousehover is called, but since it is not called even once after issuing TrackMouseEvent, so this I guess is not the case.
To redraw I intent to use InvalidateRect(), but here even wm_mousehover is not called....

AlexFM, let me see your method. Will get back soon.

Regards,
Bonns
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 32
Vb.Net Loading Word 11 98
Poor Man's .NET Framework Certification 2 47
Authentication of Web Services 3 53
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

15 Experts available now in Live!

Get 1:1 Help Now