Solved

MouseMove or GotFocus on a menu?

Posted on 2001-06-06
8
180 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month4 days, 5 hours left to enroll

630 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