|
-
July 11th, 2007, 10:57 AM
#1
Disable "X" button on forms in VB6
I tried all the examples on this forum to do this but none seemed to work - the "X" botton still functioned. My big issue is that I create some temp files for WAV and AVI data and want to kill the files when the program closes. With exit buttons or menu selection my code executes fine and all files are eliminated but with the "X" button the clean-up is not done.
Thus I need a very short & consice method of either:
1.) Disabling the "X" button
OR
2.) So mehow executing the cleanup routine when "X" is pressed.
Thanks for any help you can give...again please do not redirect me to existing code links since they did not work...I already tried them.
-
July 11th, 2007, 11:01 AM
#2
Re: Disable "X" button on forms in VB6
Add this and it won't matter.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call MyExit
End Sub
If they click the X, your code will fire.
-
July 13th, 2007, 02:32 AM
#3
Re: Disable "X" button on forms in VB6
This will disable the 'x' close button by removing the system menu Close item.
Also removes the menu separator for asthetics.
Always provide a way for the form to be closed.
Code:
Option Explicit
'WRITTEN BY ROBDOG888
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 Declare Function GetMenuItemCount Lib "user32.dll" ( _
ByVal hMenu As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Sub Form_Load()
'REMOVE THE SYSTEM MENU ITEM - CLOSE
RemoveMenu GetSystemMenu(Me.hwnd, 0), GetMenuItemCount(GetSystemMenu(Me.hwnd, 0)) - 1, MF_BYPOSITION
'REMOVE THE MENU SEPARATOR
RemoveMenu GetSystemMenu(Me.hwnd, 0), GetMenuItemCount(GetSystemMenu(Me.hwnd, 0)) - 1, MF_BYPOSITION
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
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
|