Public Const WM_SYSCOMMAND As Integer = 274 Public Const SC_CLOSE As Integer = 61536 Private CloseButtonClicked As Boolean = False Private Sub MyForm_Closing(ByVal sender As Object, _ ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If Me.CloseButtonClicked = True Then Me.CloseButtonClicked = False 'reset close button detector e.Cancel = True Return End If End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then Me.CloseButtonClicked = True End If MyBase.WndProc(m) End Sub>Hello all, I am having trouble getting an API function call to work. When the X is clicked on the control box, my form closes, but my application stays in debugging mode, meaning the application is still running. I know it is because I have two threads running in the background that keep on running when the X is clicked. Below is the code I am using. Any suggestions. TIA.
> Inherits System.Windows.Forms.Form > > Dim NewForm As Form > Public pclsThreadNotify As clsThreadNotify > Public pclsThreadReceived As clsThreadReceived > > > ' New Code > Public Declare Function GetSystemMenu Lib "user32" ( _ > ByVal hwnd As Long, _ > ByVal bRevert As Long) As Long > Public Declare Function GetMenuItemCount Lib "user32" ( _ > ByVal hMenu As Long) As Long > Public Declare Function RemoveMenu Lib "user32" ( _ > ByVal hMenu As Long, _ > ByVal nPosition As Long, _ > ByVal wFlags As Long) As Long > Public Declare Function DrawMenuBar Lib "user32" ( _ > ByVal hwnd As Long) As Long > > Public Const MF_BYPOSITION = &H400& > Public Const MF_DISABLED = &H2& > >In the form load > > Dim hMenu As Long, nCount As Long > > 'Get handle to system menu > hMenu = GetSystemMenu(Me.Handle.ToInt64, 0) > > 'Get number of items in menu > nCount = GetMenuItemCount(hMenu) > > 'Remove last item from system menu (last item is 'Close') > Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION) > > 'Redraw menu > DrawMenuBar(Me.Handle.ToInt64) > >