Hi, I am developing a visual basic application. I have implemented no modal msgbox as following:

VB Code:
  1. Option Explicit
  2.  
  3. Private Declare Function MsgboxNoModal Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal
  4.  
  5. lpCaption As String, ByVal wType As Long) As Long
  6.  
  7. Const MB_ICONASTERISK = &H40&
  8.  
  9. Private Sub NoModalMsgboxExample()
  10.   Call MsgboxNoModal(100, "This is NO modal.", "No Modal Msgbox Example", MB_ICONASTERISK)
  11. End Sub

This works ok. The problem is that if I dont close all the message boxes that appear during execution of the application, when I finish the application it keeps on standby until I close all the message boxes, and then finishes.

If I add the following code I only close the last msgbox opened, but I would like to close all the message boxes that remain opened. Is there any way to close automatically all the message boxes that remain opened when I finish the application?

VB Code:
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  2.  
  3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  4.  
  5. Private Const WM_CLOSE = &H10
  6.  
  7. Private Sub Close_application()
  8.     Dim hWnd As Long
  9.     hWnd = FindWindow("#32770", "No Modal Msgbox Example")
  10.     SendMessage hWnd, WM_CLOSE, 0, 0
  11.     End
  12. End Sub

I am a beginner using API, so I would appreciate any help. Thank you very much for your help!!!