-
April 23rd, 2007, 03:32 AM
#1
Making the menu invisible
Hi,
Can someone help me in making the menus of the given window(for example on screen keyboard) invisible by any programming language. Is there any API that does this. Please help me out in this.Thanks in advance.
Vinoth
-
April 23rd, 2007, 04:27 AM
#2
Re: Making the menu invisible
You can use the combination of GetMenu and ShowWindow APIs to hide or show a menu. Lookup on MSDN for the documentation related to these APIs.
-
April 24th, 2007, 09:09 AM
#3
Re: Making the menu invisible
Sorry to revive this thread....
I tried this :
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5
Private Sub Command1_Click()
Dim retval As Long
Dim hwnd As Long, hSysMenu As Long, count As Long
hwnd = FindWindow(vbNullString, "Untitled - Notepad")
hSysMenu = GetMenu(hwnd)
retval = ShowWindow(hSysMenu, SW_HIDE)
End Sub
But my Notepad's menu doesn't disappear, in fact, nothing happens with Notepad. Am I doing something dumb again ¿
-
April 24th, 2007, 09:56 AM
#4
Re: Making the menu invisible
Well it doesn't work for me either. Let me do some research. I guess ShowWindow doesn't work with menus.
-
April 24th, 2007, 10:18 AM
#5
Re: Making the menu invisible
I couldn't get that method to work either (LastDLLError was "Invalid window handle."), but I did find a way to remove a menu (not hide it).
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&
Private Sub Command1_Click()
Dim retval As Long, i As Long
Dim hwnd As Long, hSysMenu As Long, count As Long
hwnd = FindWindow(vbNullString, "Untitled - Notepad")
hSysMenu = GetMenu(hwnd)
If hSysMenu Then
count = GetMenuItemCount(hSysMenu)
For i = 0 To count
'Removing an item from the menu repositions
'the menu items, so we always remove the first position
RemoveMenu hSysMenu, 0, MF_BYPOSITION Or MF_REMOVE
Next
End If
End Sub
Of course, if you actually need the menu at some time (e.g. make it visible again), this method wouldn't work.
-
April 24th, 2007, 10:46 AM
#6
Re: Making the menu invisible
I think the whole problem ( I may be wrong) is that the GetMenu API doesn't return the "whole menu object" ie. the MenuBar itself. Do you guys agree ¿ I've dabbed around a bit with FindWindowEx, but I don't know how to reference the MenuBar object.
I thought of RemoveMenu too, but it removes it, then what if we want it back ¿
Guys, sorry to have put everyone in a flat spin, it was just something I've also wanted to do too....
I love these threads
-
April 24th, 2007, 11:16 AM
#7
Re: Making the menu invisible
You, unfortunately, can't check if the handle returned by GetMenu is the right window handle, as Spy++ can't highlight or find the menu on Notepad (or other programs with standard menus).
Of course, if we looked at GetMenu's brother API function, SetMenu, we can see how to show and hide menus.
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetMenu Lib "user32.dll" (ByVal hwnd As Long, ByVal hMenu As Long) As Long
Dim nhwnd As Long, nhSysMenu As Long
Private Sub Command1_Click()
SetMenu nhwnd, 0
End Sub
Private Sub Command2_Click()
SetMenu nhwnd, nhSysMenu
End Sub
Private Sub Form_Load()
nhwnd = FindWindow(vbNullString, "Untitled - Notepad")
nhSysMenu = GetMenu(nhwnd)
End Sub
Note that this doesn't actually "hide" the menu, it will remove it as well, but since you're storing the handle to the menu (which does stay in memory), you can restore it.
-
April 24th, 2007, 11:24 AM
#8
Re: Making the menu invisible
Nice! Good stuff! Thanx Chaos!! Yeah, SetMenu never even crossed my mind! LOL!
-
April 25th, 2007, 01:51 AM
#9
Re: Making the menu invisible
Well I was wrong with the ShowWindow API. It is probably because of the evident reasons cited by Chaos. SetMenu is right.
That was a good one Chaos
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
|