?
Solved

How to get Highlighted Menu Item Text in Visual Basic ?

Posted on 2001-09-17
7
Medium Priority
?
313 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

764 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