Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
API to disable X
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00720274
Message ID:
00720576
Views:
8
I Randy,

The code you are using was designed for VB6 not .NET. Here is a way to disable the close button from working.
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)
>
>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform