Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Does anyone know the code to make allow the user to quit the program? Just placing "End" doesn't work for me. Well, for me it does, but on anyone else's computer, it won't let the program start, giving an error. I had a little problem with the end yesterday when I had a button which would close it. It said something about unmanaged code. I moved the end into a file menu, and it seemed to work fine. My beta testers though can't run it when the end is in the file menu (didn't have them test with it for the button), but it works fine when it's not in the menu. Any ideas will be appreciated.

Dodge

Grab Life By The Horns

Posted
Thanks! Now you would have thought that for me searching about that yesterday for prolly 15 to 30 minutes I woudl have found something. This board is great! Thanks again.

Dodge

Grab Life By The Horns

  • 5 weeks later...
Guest holtzy
Posted

I'm have trouble exiting the entire program. The code...

 

Application.Exit()

 

isn't working. In VBA I used Quit. Is there any reason I couldn't use this code?

  • 1 year later...
  • Leaders
Posted

i built this example a while back , if you wish to make sure all forms get closed, then close the main form....

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As String, ByVal lParam As String) As Integer
Private Const WM_CLOSE As Integer = &H10

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim frmTypes() As Type = Reflection.Assembly.GetExecutingAssembly.GetTypes
   Dim fType As Type
   Dim hwnd As Integer
   Try
       For Each fType In frmTypes
       If Not fType.Name = Me.Name Then '/// make sure we dont accidently close the main Form.
           hwnd = FindWindow(vbNullString, fType.Name)
           If Not hwnd = 0 Then
               PostMessage(hwnd, WM_CLOSE, vbNullString, vbNullString)
           End If
       End If
       Next
   Catch ex As Exception
       MessageBox.Show(ex.Message)
   Finally
       MyBase.Close() '/// now all other Form's are closed , we can close the main Form.
   End Try
End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...