Solved

MouseMove or GotFocus on a menu?

Posted on 2001-06-06
8
172 Views
Last Modified: 2008-03-06
Is there a way to determine if a menu has focus or the mouse moves over a menu?  The only event available for the VB Menu object is Click, but I want to know if the user moves over a menu item before they click it.
0
Comment
Question by:mpmagin
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Expert Comment

by:Microsoft
ID: 6161184
this is an example of how to get a value when the mouse is over an object maybe this might help you
to get an idea.


Call this function, passing the list box's hwnd, x, and y, from the list box's mousemove event, and
the item the mouse is over will be selected

Option Explicit
Private Const LB_SETCURSEL = &H186
Private Const LB_GETCURSEL = &H188
Private Type POINTAPI
   X As Long
   Y As Long
End Type

Private Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Declare Function LBItemFromPt Lib "COMCTL32.DLL" _
(ByVal hLB As Long, ByVal ptX As Long, ByVal ptY As Long, _
ByVal bAutoScroll As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Long) As Long

Public Sub HighlightLBItem(ByVal LBHwnd As Long, _
ByVal X As Single, ByVal Y As Single)

Dim ItemIndex As Long
Dim AtThisPoint As POINTAPI
AtThisPoint.X = X \ Screen.TwipsPerPixelX
AtThisPoint.Y = Y \ Screen.TwipsPerPixelY
Call ClientToScreen(LBHwnd, AtThisPoint)
ItemIndex = LBItemFromPt(LBHwnd, AtThisPoint.X, _
  AtThisPoint.Y, False)
If ItemIndex <> SendMessage(LBHwnd, LB_GETCURSEL, 0, 0) Then
   Call SendMessage(LBHwnd, LB_SETCURSEL, ItemIndex, 0)
End If

End Sub

try that

cheers
andy

I could be just pissing in the wind, i don't know if any of what ive suggested but im trying to help
as best as i can

if its not what you wont then never mind im only Human

cheers
Andy  
Comment
From
0
 
LVL 6

Accepted Solution

by:
JonFish85 earned 100 total points
ID: 6161542
here something else:

http://161.58.186.98/demos/subclassmenus/

it might be the same as Andy posted above, but worth a shot
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6161597
mpmagin,

Are you wanting to use this to be able to enable/disable certain menu items, or to show/do something as they move over the menu items?

If you want to disable/enable menu items you can do it in the parent menu click event since it will run before the menu items expand, so if you have a menu like:

File
--Menu 1
--Menu 2
--Menu 3

When the mouse moves over the file menu item it will fire the click event before the menu expands, you can set the other menus enabled/disabled at this time in the File menu click event.  Even though they might not have actually clicked it themselves, the event still runs.

If you want to show or do something for each individual menu you will need to subclass the form as JonFish85 has suggested.  The example he gave you will do what you want.

My two cents...
Shannon
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6161681
YOU MEAN the example Microsoft has given, as Jon has stated his example may do the same as mine.

sorry to seem alittle upset but don't want to lose points

you know how that feels.

cheers

Andy
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:JonFish85
ID: 6161716
microsoft, your answer will just work with listboxes no (ie the LB constants) no?
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6161754
Andy,

Sorry, but subclassing the menu system of the form is the best way if he wants mouse events for it.  What Jon may not know is that the example he suggested from VB World's website will do just that.  On the other hand your code deals with a listbox and will not notify him of a menu mouse event.  If I am missing something please let me know...I didn't mean to try to sway him into picking someone's answer over another:)

Regards,
Shannon
0
 

Author Comment

by:mpmagin
ID: 6164479
JonFish85

That was exactly what I needed.  Thanks!

mpmagin
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6164497
glad I could help!
0

Featured Post

What Security Threats Are You Missing?

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.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

17 Experts available now in Live!

Get 1:1 Help Now