Solved

How to get Highlighted Menu Item Text in Visual Basic ?

Posted on 2001-09-17
7
306 Views
Last Modified: 2013-11-25
How to get Highlighted Menu Item in Visual Basic
( I want to Display Menu Item Text in Status Bar - Similar to Visual C++ Menu )

Amit

0
Comment
Question by:amit_panjwani
[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
  • 3
7 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 300 total points
ID: 6487971
Requires subclassing:

Option Explicit


Private Sub Form_Load()
   Show
'    frmMenuSub.Show
   Call sGetMenuHandles(Me.hWnd)
   gProcOld = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf fMenuProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
   Call SetWindowLong(hWnd, GWL_WNDPROC, gProcOld)
End Sub

Module code:

Option Explicit
Public gProcOld As Long
Public x As Long
Public y As Long

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any,
ByVal Length As Long)
Public Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private mMenuIDs() As Long
Dim mhMenu As Long
Dim mhSubMenu As Long

Public Const GWL_WNDPROC = (-4)
Public Const WM_MENUSELECT = &H11F


Public Const MF_BYCOMMAND& = &H0&
Public Const MF_BYPOSITION& = &H400&


Public Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal
wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long


Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal
nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As
Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Function fMenuProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
   Dim str As String
   Dim words(1 To 2) As Integer
   Dim strCaption As String
   Dim lngRet As Long
   If iMsg = WM_MENUSELECT Then
       
       'Stop
       x = wParam
       y = lParam
       
       'frmMenuSub.List1.AddItem Format(x)
       Debug.Print Format(x), y
       
       CopyMemory words(1), x, 4
       
       strCaption = String(255, 0)
       'Low word has MnuID
       If words(1) = -1 Then
           'Head menu
           lngRet = GetMenuString(mhMenu, words(1), strCaption, 255, MF_BYCOMMAND)
       Else
           'Submenu
           lngRet = GetMenuString(mhSubMenu, words(1), strCaption, 255, MF_BYCOMMAND)
       End If
       strCaption = Left$(strCaption, lngRet)
       

       
       
       Select Case strCaption

       Case "bbb"
           str = "BBB"
       Case "ccc"
           str = "CCC"
       Case "ddd"
           str = "DDD"
       End Select




       frmMenu.Label1 = str
   End If
   
   fMenuProc = CallWindowProc(gProcOld, hWnd, iMsg, wParam, lParam)
End Function



Public Sub sGetMenuHandles(hWnd As Long)
   
   mhMenu = GetMenu(hWnd)
   mhSubMenu = GetSubMenu(mhMenu, 0)
       

End Sub

You would have to tailor it to your app.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6489166
<listening..>
0
 
LVL 4

Author Comment

by:amit_panjwani
ID: 6490873
I will get back as soon as I work out PaulHews proposed solution.

Amit
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 38

Expert Comment

by:PaulHews
ID: 6491005
Let me know if you need any help.
0
 
LVL 4

Author Comment

by:amit_panjwani
ID: 6496217
Thank you  PaulHews,

I could not get time to check code, I will check and get back if I need more help, meanwhile , Thank you for offering soltution.


Amit Panjwani

0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6496416
Ok, hopefully I'll still be receiving notifications.  There is a bug in EE that turns off some notifications after an answer is accepted.  My email address is in my profile if you need help and I'm not responding here.
0
 
LVL 4

Author Comment

by:amit_panjwani
ID: 6499570
Sure, Thank you.

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

Suggested Solutions

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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

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