Click to See Complete Forum and Search --> : How to diable close button of form ???
lactasoy
Aug 19th, 2000, 06:30 AM
How to diable close button of form ???
but i can use min and max button
on the form ....
please tell me how to...
thank you
hypnos
Aug 19th, 2000, 09:25 AM
In the form's unload event you could put this
Cancel = True
hypnos
Aug 19th, 2000, 09:39 AM
Of course if you used the method I told you above the only way to close the form would be by using the end command which would close the entire app. This isn’t a problem if you only intend on using one form. I know its possible to disable the X button so it can’t be clicked at all but I’m not sure how.
Try this.
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
hypnos
Aug 19th, 2000, 09:57 AM
Now I’m really confused. I read in an API book that you can’t use Integer values in an API declaration. However, the two above declarations are using Integer values. Was the book wrong or did I misinterpret something?
Sam Finch
Aug 19th, 2000, 09:57 AM
If you want to put it back at some point then use this to gray it out and ungray it
Option Explicit
Private Const MF_BYCOMMAND = &H0&
Private Const MF_ENABLED = &H0&
Private Const MF_GRAYED = &H1&
Private Const SC_CLOSE = &HF060&
Private Const FOOLVB = -10
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Public Sub DisableClose(frm As Form)
Dim hMenu As Long
hMenu = GetSystemMenu(frm.hwnd, 0)
If hMenu Then _
Call ModifyMenu(hMenu, SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED, FOOLVB, "Close")
Call DrawMenuBar(frm.hwnd)
End Sub
Public Sub EnableClose(frm As Form)
Dim hMenu As Long
hMenu = GetSystemMenu(frm.hwnd, 0)
If hMenu Then _
Call ModifyMenu(hMenu, FOOLVB, MF_BYCOMMAND Or MF_ENABLED, SC_CLOSE, "Close")
Call DrawMenuBar(frm.hwnd)
End Sub
it also makes the x button go gray as a visual indicator
Sam Finch
Aug 19th, 2000, 10:02 AM
I don't know where you read that hypnos, Integers aren't used often in API declares, usually longs are used instead but there are some APIs which take a integer parameters.
Integer's are uncommon but are still used. A C++ WORD is the same as VB's ByVal Integer.
hypnos
Aug 19th, 2000, 11:14 AM
I read it in "Visual Basic 6 Win32 API Tutorial". Maybe the guy was just saying there is no reason to use them?
Maybe he was just generalizing it. Yes you can declare everything as Long; but the other data types save space. For example, you can convert Char to Long or Byte. Both are acceptable but Byte saves a lot more space.
Just incase you're interested, here are C to VB conversions.
HWMD ByVal var As Long
LPSTR ByVal var As String
HDC ByVal var As Long
WORD ByVal var As Integer
DWORD ByVal var As Long
CHAR ByVal var As Byte (or String * 1)
INT ByVal var As Integer
INT FAR * intValue As Integer
CHAR FAR * ByVal var As String
LONG ByVal var As Long
LONG FAR * var As Long
BYTE ByVal var As Byte
BOOL ByVal var As Boolean
UNSIGNED SHORT ByVal var As Integer
UNSIGNED CHAR ByVal var As Integer
UNSIGNED LONG ByVal var As Long
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.