| | |
Apply code to 'x' button on form
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
•
•
Id like it so that when you click the 'x' button to close the program it doesnt just end.
VB Syntax (Toggle Plain Text)
Private Sub cmdX_Click() unload Me End Sub Private Sub Form_Unload(Cancel As Integer) Dim intReturn As Integer intReturn = MsgBox("Ready to Exit", vbOKCancel, "Exit?") If intReturn = vbOK Then Else Cancel = True End If End Sub
Hi rabbithaveit
I would suggest the API way as it gives you more flexibility... See picture attached...
Please place a Command Button on the form so that you can exit.
Paste this code in the general declaration of the form...
I would suggest the API way as it gives you more flexibility... See picture attached...
Please place a Command Button on the form so that you can exit.
Paste this code in the general declaration of the form...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Option Explicit Private Declare Function DeleteMenu 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 Const MF_BYPOSITION = &H400& Private ReadyToClose As Boolean Private Sub RemoveMenus(frm As Form, remove_restore As Boolean, _ remove_move As Boolean, remove_size As Boolean, remove_minimize As Boolean, _ remove_maximize As Boolean, remove_seperator As Boolean, remove_close As Boolean) Dim hMenu As Long '~~> Get the form's system menu handle. hMenu = GetSystemMenu(hwnd, False) If remove_close Then DeleteMenu hMenu, 6, MF_BYPOSITION If remove_seperator Then DeleteMenu hMenu, 5, MF_BYPOSITION If remove_maximize Then DeleteMenu hMenu, 4, MF_BYPOSITION If remove_minimize Then DeleteMenu hMenu, 3, MF_BYPOSITION If remove_size Then DeleteMenu hMenu, 2, MF_BYPOSITION If remove_move Then DeleteMenu hMenu, 1, MF_BYPOSITION If remove_restore Then DeleteMenu hMenu, 0, MF_BYPOSITION End Sub Private Sub cmdClose_Click() ReadyToClose = True Unload Me End Sub Private Sub Form_Load() '~~> Remove the Close system menu item and the menu separator. RemoveMenus Me, False, False, False, False, False, True, True End Sub '~~> Cancel if ReadyToClose is false. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Cancel = Not ReadyToClose End Sub
Last edited by koolsid; Mar 27th, 2009 at 5:48 am.
A good excercise for the Heart is to bend down and help another up...
Please Mark your Thread "Solved", if the query is solved...
==>If a post has helped you then Please Rate it!
Please Mark your Thread "Solved", if the query is solved...
==>If a post has helped you then Please Rate it!
Thanks for replying guys.
hkdani thanks again. I will be sure to try that solution
Koolsid I like the concept but it seems a bit complicated for mke at the moment....
thanks for the reply. But I dont want answer per say...I prefer solutions. So I can learn from them. I'll be sure to look up the API and put your coding to use soon. So thank you
Will be back with a post if it works hkdani
Thanks again guys
-Russell aka Rabbit
hkdani thanks again. I will be sure to try that solution
Koolsid I like the concept but it seems a bit complicated for mke at the moment....
thanks for the reply. But I dont want answer per say...I prefer solutions. So I can learn from them. I'll be sure to look up the API and put your coding to use soon. So thank you
Will be back with a post if it works hkdani
Thanks again guys
-Russell aka Rabbit
@jbennet
Can you supply an image to support that?
Thanks in advance
-Russell aka Rabbit
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
In the code editor click (i think its the right) combo box at the top and choose where it says terminate with a lightning bolt next to it
Can you supply an image to support that?
Thanks in advance
-Russell aka Rabbit
![]() |
Similar Threads
- Help! PHP form mailer not working. (PHP)
- Please help with passing data from one form to another form (VB.NET)
- Convert SINGLE-file upload into multiple files with foreach loop, cant figure out (PHP)
- Redesign an input type="file" (JavaScript / DHTML / AJAX)
- Variable scope problem (C++)
- Word Macros (Computer Science)
- .net validation/javascript conflict (ASP.NET)
- Go to a certain page when button is pressed and do it securely (ASP.NET)
- Storing dynamic form values in Arrays for display & insert (PHP)
- Access Sub switchboard password protection (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how to use the keypress function is visual basic 6
- Next Thread: Searching for records contained in access from VB
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






