Solved

MouseMove or GotFocus on a menu?

Posted on 2001-06-06
8
174 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 77
Access 2013 combo box not working 3 44
Spell Check in VB6 13 112
Excel Automation VBA 19 70
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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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