WadeD
May 15th, 2000, 05:36 AM
Hi, I'm trying (unsuccessfully so far :()to add a menu to a foreign window which doesn't have a menu. I know the syntax is right because I can add the same exact menu to other progs (like Notepad). I checked to see if the window is technically a child window and it's not. That's the only restriction I've read about that disallows new menu creation. Any ideas??? Here's the code:Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function CreateMenu Lib "user32" () As Long
Private Declare Function SetMenu Lib "user32" (ByVal hwnd As Long, ByVal hMenu As Long) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Const MF_POPUP& = &H10&
Private Const MF_BYPOSITION& = &H400&
Private Const MF_STRING& = &H0&
Private Sub Form_Load()
Call AddMnu
End Sub
Private Sub AddMnu()
Dim lMnMnu As Long 'MenuBar Handle
Dim lMnuLevl1 As Long 'Top Level Menu Item
Dim lMnuLevl2 As Long 'Submenu Item
Dim lRetVal As Long 'Return Value from API Call
Dim NotepadWindow As Long 'Window Handle of Notepad
'NotepadWindow Handle is Found Using EnumWindows; I verified the handle in both cases (for Notepad and for the other foreign window) in the Debug Window
lMnMnu = CreateMenu
lMnuLevl1 = CreateMenu
lRetVal = InsertMenu(lMnMnu, 0, MF_POPUP Or MF_STRING Or MF_BYPOSITION, lMnuLevl1, "Test")
lMnuLevl2 = CreateMenu
lRetVal = InsertMenu(lMnuLevl1, 0, MF_STRING Or MF_BYPOSITION, lMnuLevl2, "&File")
lRetVal = SetMenu(NotepadWindow, lMnMnu)
lRetVal = DrawMenuBar(NotepadWindow)
End Sub
Thanks,
Wade
Private Declare Function CreateMenu Lib "user32" () As Long
Private Declare Function SetMenu Lib "user32" (ByVal hwnd As Long, ByVal hMenu As Long) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Const MF_POPUP& = &H10&
Private Const MF_BYPOSITION& = &H400&
Private Const MF_STRING& = &H0&
Private Sub Form_Load()
Call AddMnu
End Sub
Private Sub AddMnu()
Dim lMnMnu As Long 'MenuBar Handle
Dim lMnuLevl1 As Long 'Top Level Menu Item
Dim lMnuLevl2 As Long 'Submenu Item
Dim lRetVal As Long 'Return Value from API Call
Dim NotepadWindow As Long 'Window Handle of Notepad
'NotepadWindow Handle is Found Using EnumWindows; I verified the handle in both cases (for Notepad and for the other foreign window) in the Debug Window
lMnMnu = CreateMenu
lMnuLevl1 = CreateMenu
lRetVal = InsertMenu(lMnMnu, 0, MF_POPUP Or MF_STRING Or MF_BYPOSITION, lMnuLevl1, "Test")
lMnuLevl2 = CreateMenu
lRetVal = InsertMenu(lMnuLevl1, 0, MF_STRING Or MF_BYPOSITION, lMnuLevl2, "&File")
lRetVal = SetMenu(NotepadWindow, lMnMnu)
lRetVal = DrawMenuBar(NotepadWindow)
End Sub
Thanks,
Wade