|
-
May 30th, 2001, 12:32 PM
#1
GetMenu (Megatron or Matthew, please help!!!)
How can I loop through all the menus in a window, even those that are not visible? GetMenu only returns handles for visible menus.
-
May 30th, 2001, 12:55 PM
#2
Hyperactive Member
The people you asked for help do indeed post a lot...but they're not the only ones on this this board who can answer basic questions.
I don't know what you're doing with the menu's, so I just added each one to a listbox. Just change the code in the If statement to do what you need.
NOTE: for this example I made sure that each menu's name started with "mnu" (i.e. mnuFile, mnuEdit). This is good coding practice and makes this example easy
Try this:
Code:
Private Sub Command1_Click()
Dim mymenu As Control
'form1 is the form with the menu's you want.
'I'm sure you can figure out what to do with multiple
'forms :p
For Each mymenu In Form1.Controls
If InStr(1, mymenu.Name, "mnu") Then
List1.AddItem mymenu.Name
End If
Next
End Sub
-
May 30th, 2001, 01:01 PM
#3
Use the TypeName Function!
Code:
Private Sub Command1_Click()
Dim mymenu As Control
'form1 is the form with the menu's you want.
'I'm sure you can figure out what to do with multiple
'forms
For Each mymenu In Form1.Controls
If strComp(TypeName(mymenu), "Menu") = 0 Then
List1.AddItem mymenu.Name
End If
Next
End Sub
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
May 30th, 2001, 01:04 PM
#4
SORRY GUYS!!!! These menus are not on my form. I need to access them via API.
Again, Megatron or Matthew, PLEASE HELP!!!
-
May 30th, 2001, 01:08 PM
#5
Frenzied Member
my, arent we getting cocky?
-
May 30th, 2001, 01:08 PM
#6
I suspected as much :P
Oh well, I don't know. I bow before the superior knowledge of the vbforum's elite.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
May 30th, 2001, 01:11 PM
#7
Hyperactive Member
Perhaps you should have (*ahem*) give that information in your first post...
-
May 30th, 2001, 01:14 PM
#8
O, LORDS Megatron and Matthew, I bow before thee (plural?). I offer thee all the memory my humble machine has to give. I pledge with all of my processing speed to grant you the bandwidth you request. O please, help. Grant me this assistance. Do not deny me this one time!!!!
:'( OH I POUR MY HEART OUT :'(
. .>-
\/ /
/-|--
/\
/ \
-
May 30th, 2001, 01:14 PM
#9
Frenzied Member
no shi't eh?
some people just get on yer nerves
nice people trying to help him and all they get is cockyness
and when they answer the question properly, he gets all cocky about that its not what he asked..
ok enough about bitchin
-
May 30th, 2001, 01:16 PM
#10
Originally posted by Acoustic
Perhaps you should have (*ahem*) give that information in your first post...
well, I thought that mentioning the GetMenu() API function was enough sorry
-
May 30th, 2001, 01:19 PM
#11
Originally posted by kovan
no shi't eh?
some people just get on yer nerves
nice people trying to help him and all they get is cockyness
and when they answer the question properly, he gets all cocky about that its not what he asked..
ok enough about bitchin
I really apologize. I never mean bad. I am just a little impatient as my manager needs this ASAP,
-
May 30th, 2001, 02:38 PM
#12
Try this:
Code:
Private Declare Function GetMenu Lib "user32" (ByVal _
hWnd As Long) As Long
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As _
Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu _
As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal _
hMenu As Long) As Long
Private 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
Private Const MF_BYPOSITION = &H400&
Private Sub ListMenuStructure(ByVal hWnd As Long, ByRef oList As ListBox)
Dim lMenu As Long
lMenu = GetMenu(hWnd)
oList.Clear
If lMenu Then RecurseMenu lMenu, oList, 1
End Sub
Private Sub RecurseMenu(ByVal lMenu As Long, ByRef oList As ListBox, ByVal iLevel As Long)
Dim lItems As Long
Dim lItem As Long
Dim sCaption As String
lItems = GetMenuItemCount(lMenu)
If lItems Then
For lItem = 0 To lItems - 1
sCaption = Space$(255)
sCaption = Left$(sCaption, GetMenuString(lMenu, lItem, ByVal sCaption, 255, MF_BYPOSITION))
oList.AddItem String((iLevel - 1) * 2, "-") & sCaption
If GetSubMenu(lMenu, lItem) Then
RecurseMenu GetSubMenu(lMenu, lItem), oList, iLevel + 1
End If
Next
End If
End Sub
Private Sub Command1_Click()
ListMenuStructure FindWindowEx(0, 0, "NotePad", vbNullString), List1
End Sub
-
May 30th, 2001, 02:41 PM
#13
By the way, I believe that's Aaron Young's code .
-
May 30th, 2001, 02:49 PM
#14
I am deeply humbled as I bow before thee, my master. I will try it, thanx.
-
May 30th, 2001, 03:36 PM
#15
:'( sorry. It does not work. It only shows those menus that are visible. Maybe Ill just tell ya what Im tryin to accomplish. I need to get all of the menu items in a specific IE window (who's handle i have) and get the handles to all menus and thereby disable those I wish too. However, getmenu returns 0, so the only menu i can touch is the system menu. SO if u have a way of doing this any other way, i would be deeply greatful. thanx!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|