Solved

MouseMove or GotFocus on a menu?

Posted on 2001-06-06
8
178 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

734 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