Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get Highlighted Menu Item Text in Visual Basic ?

Posted on 2001-09-17
7
Medium Priority
?
324 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 1200 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 53

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

610 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