|
-
Sep 7th, 2000, 05:51 PM
#1
Thread Starter
Member
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
"..Follow the white rabbit.."
-
Sep 7th, 2000, 05:55 PM
#2
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
-
Sep 7th, 2000, 05:56 PM
#3
go to the form properties box and set the 'controlbox' option to false.
-
Sep 7th, 2000, 05:59 PM
#4
crptcblade, that will make the X button not visible, but the program's icon will not show.
-
Sep 7th, 2000, 06:02 PM
#5
sorry, i missed that part of the original thread 8-)
-
Sep 7th, 2000, 06:06 PM
#6
Thread Starter
Member
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
"..Follow the white rabbit.."
-
Sep 7th, 2000, 06:36 PM
#7
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
-
Sep 7th, 2000, 06:49 PM
#8
Hyperactive Member
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]
-
Sep 16th, 2000, 01:06 AM
#9
Frenzied Member
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
-
Sep 16th, 2000, 01:09 AM
#10
Monday Morning Lunatic
If you use something like this:
Code:
Private Function Remove(hWnd as Long) As Integer
Remove = RemoveMenu(GetSystemMenu(hWnd, 0), 6, MF_BYPOSITION)
End Function
That should work. Megatron's function works for the current window handle only, so it needs to be in a form.
One edit later...
Damn! That bug's still there 
[Edited by parksie on 09-16-2000 at 02:12 AM]
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 16th, 2000, 11:43 AM
#11
To gray out the Max button, you do not need any API. Just set the MaxButton property to False.
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
|