How to I make a form, where it shows the Form's Caption and Includes a Icon, but doesnt have the X to close out the program at the top? Thanx
Printable View
How to I make a form, where it shows the Form's Caption and Includes a Icon, but doesnt have the X to close out the program at the top? Thanx
Here's how to disable the X button, so you can have a caption and icon on the form.
Code:Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&
Private Sub Form_Load()
Dim hSysMenu As Long
Dim nCnt As Long
' First, show the form
Me.Show
' Get handle to our form's system menu
' (Restore, Maximize, Move, close etc.)
hSysMenu = GetSystemMenu(Me.hwnd, False)
If hSysMenu Then
' Get System menu's menu count
nCnt = GetMenuItemCount(hSysMenu)
If nCnt Then
' Menu count is based on 0 (0, 1, 2, 3...)
RemoveMenu hSysMenu, nCnt - 1, _
MF_BYPOSITION Or MF_REMOVE
RemoveMenu hSysMenu, nCnt - 2, _
MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
DrawMenuBar Me.hwnd
' Force caption bar's refresh. Disabling X button
Me.Caption = "Try to close me!"
End If
End If
End Sub
go to the form properties box and set the 'controlbox' option to false.
crptcblade, that will make the X button not visible, but the program's icon will not show.
sorry, i missed that part of the original thread 8-)
Cool thanx, both ways will work fine for me. I really only wanted the [X] gone but it will work without the icon showing as well. Thanks alot :D
Short and Simple.
Code:Private Declare Function GetSystemMenu Lib "User32" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
Private Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Const MF_BYPOSITION = &H400
Private Sub Form_Load()
Call RemoveMenu(GetSystemMenu(hWnd, 0), 6, MF_BYPOSITION)
End Sub
Megatron:
Are you saying that your example code will remove the close
(X) button or that you need to still disable the control box
and your code will allow the icon to stay?
Never mind, just tried your code and it works. BTW, can the
other controls be greyed out also?
Through playing around, I found that there are 7 menu
items (based on 0):
0 - ?
1 - Move
2 - Size
3 - Minimize
4 - Maximize
5 - ?
6 - Close (ALT-4) and greys out "X"
0 and 5 didn't seem to do anything and although you can't
use the Minimize and Maximize control icons they do not get
greyed out.
[Edited by dsy5 on 09-07-2000 at 09:04 PM]
Megatron,
How would I use your code if I put it in a module? For some reason, it doesn't seem to disable the X if I put the first 3 lines of code in a module and change the first 2 to "Public"..
But it does work on the form that it's being called from..
My idea is that I'm developing a standard library of code that I can reuse in various projects..
Thanks for any help you can provide to make this work..
Dan
If you use something like this:
That should work. Megatron's function works for the current window handle only, so it needs to be in a form.Code:Private Function Remove(hWnd as Long) As Integer
Remove = RemoveMenu(GetSystemMenu(hWnd, 0), 6, MF_BYPOSITION)
End Function
One edit later...
Damn! That bug's still there :(
[Edited by parksie on 09-16-2000 at 02:12 AM]
To gray out the Max button, you do not need any API. Just set the MaxButton property to False.