|
-
Jan 16th, 2003, 09:23 PM
#1
Thread Starter
Lively Member
Closing form window??
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!!!!
-
Jan 16th, 2003, 09:26 PM
#2
Frenzied Member
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.
-
Jan 16th, 2003, 09:35 PM
#3
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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 16th, 2003, 09:38 PM
#4
Frenzied Member
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.
Last edited by Microbasic; Jan 16th, 2003 at 10:06 PM.
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jan 16th, 2003, 09:42 PM
#5
Frenzied Member
Microbasic I thought the same thing but didn't see a point in it since the borderstyle could just be changed at design time.
-
Jan 16th, 2003, 09:45 PM
#6
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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 16th, 2003, 09:46 PM
#7
-
Jan 16th, 2003, 09:48 PM
#8
Frenzied Member
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
Sorry about the Chit chat, but...
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.
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jan 16th, 2003, 09:51 PM
#9
Micor...not sure if you remember me.. Geoff_xrx (I pulled a name change after my "year" of absence)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 16th, 2003, 09:53 PM
#10
-
Jan 16th, 2003, 10:00 PM
#11
PowerPoster
Hi Microbasic, i guest this code also generate the similiar result as yours 
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
-
Jan 16th, 2003, 10:05 PM
#12
Frenzied Member
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"
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jan 16th, 2003, 10:08 PM
#13
Frenzied Member
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
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jan 16th, 2003, 10:22 PM
#14
Thread Starter
Lively Member
Uuuuh...OK.
Thanks everyone!! This is exactly what I'm looking for.
-
Jan 16th, 2003, 11:03 PM
#15
Thread Starter
Lively Member
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?
-
Jan 16th, 2003, 11:29 PM
#16
Frenzied Member
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
-
Jan 16th, 2003, 11:49 PM
#17
I you use microbasics code to disable
all you need is the "Unload Me" statement
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jan 16th, 2003, 11:55 PM
#18
Thread Starter
Lively Member
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??
-
Jan 17th, 2003, 12:10 AM
#19
Frenzied Member
-
Jan 17th, 2003, 01:31 AM
#20
Originally posted by Shawn N
Yes.
as shawn says.. 
Yes.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
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
|