Is there a way I can hide a form's window "close" button in order to avoid a user from accidently closing the window and shutting the application down??
Thanks!!!!
Printable View
Is there a way I can hide a form's window "close" button in order to avoid a user from accidently closing the window and shutting the application down??
Thanks!!!!
This code will not allow the user to unload your form.
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Cancel = True End Sub
I don't know of a way to temporarily hide the X.
CHnage your window Controlbox to false...(this hides all 3 buttons)
with ControlBox = False...if you clear the field for the form caption...the title bar will disappear
Yes, you can:
VB Code:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu 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 Private Const MF_BYPOSITION = &H400& Private Const MF_DISABLED = &H2& Private Const MF_GRAYED = &H1& Private Sub Form_Load() Dim hM As Long, HMCount As Long hM = GetSystemMenu(Me.hwnd, False) HMCount = GetMenuItemCount(hM) ModifyMenu hM, HMCount - 1, MF_BYPOSITION Or MF_GRAYED, 0, "Close" End Sub
This will disable the X and the Close option.
EDIT (+Code): Oops, I can't type today.
Microbasic I thought the same thing but didn't see a point in it since the borderstyle could just be changed at design time.
Well...Micro's solution might be better anyway... I just gave the quick/easy way to fix it..But if the Min/Max buttons are still needed. then definately go with the API's
Yeah, but if you change the borders, you get rid of the familiar "WINDOWS" look.
I mean, you wouldn't have the Title Bar, System Menu, MinMax/"?" Buttons, and size borders (or at least 3D borders)
Sorry about the Chit chat, but...Quote:
Originally posted by [LGS]Static
Well...Micro's solution might be better anyway... I just gave the quick/easy way to fix it..But if the Min/Max buttons are still needed. then definately go with the API's
That's interesting. Even after a year of absense from VBForums, people still know to call me "Micro" (especially if they're newer members who probably never knew me before).
Again, sorry for the digression.
Micor...not sure if you remember me.. Geoff_xrx (I pulled a name change after my "year" of absence)
Oh, OK. I still remember you, Geoff.
That Lightning VB Avatar should have tipped me off. [oops, OT again]
Hi Microbasic, i guest this code also generate the similiar result as yours :D
VB Code:
Option Explicit Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Private Sub Form_Load() RemoveMenu GetSystemMenu(Me.hwnd, 0), 6, MF_BYPOSITION End Sub
Yes, but could it also do this?
VB Code:
'REENABLES THE X BUTTON Dim hM As Long, HMCount As Long hM = GetSystemMenu(Me.hwnd, False) HMCount = GetMenuItemCount(hM) ModifyMenu hM, HMCount - 1, MF_BYPOSITION Or &H0, 0, "Close"
Of course, you could always rewrite it as this:
VB Code:
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 Private Sub Form_Load() ModifyMenu GetSystemMenu(Me.hwnd, False), 6, &H401&, 0, "Close" End Sub
Uuuuh...OK.
Thanks everyone!! This is exactly what I'm looking for.
So, now that I keep users from closing the window accidentally how can I close the form with a command button. Why am I not getting the .unload method?
Quote:
Originally posted by Jason Carden
So, now that I keep users from closing the window accidentally how can I close the form with a command button. Why am I not getting the .unload method?
VB Code:
Call GetSystemMenu(Me.hwnd, True) Unload Me
I you use microbasics code to disable
all you need is the "Unload Me" statement
Well that's what I thought, but it's not working. Could it be b/c I'm using the cancel = true in my form_queryunload event??
Yes.
as shawn says.. :)Quote:
Originally posted by Shawn N
Yes.
Yes.