Home » Miscellaneous » How to create a self Closing Message Box
How to create a self Closing Message Box
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 'Miscellaneous - How to create a self Closing Message Box Public Const NV_CLOSEMSGBOX As Long = &H5000& Public Declare Function SetTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&, ByVal uElapse&, _ ByVal lpTimerFunc&) Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, _ ByVal lpWindowName$) Public Declare Function LockWindowUpdate& Lib "user32" (ByVal hwndLock&) Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hWnd&) Public Declare Function MessageBox& Lib "user32" Alias "MessageBoxA" (ByVal hWnd&, ByVal lpText$, _ ByVal lpCaption$, ByVal wType&) Public Declare Function KillTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&) Public Const API_FALSE As Long = 0& Public Sub TimerProc(ByVal hWnd&, ByVal uMsg&, ByVal idEvent&, ByVal dwTime&) Call KillTimer(hWnd, idEvent) Dim hMessageBox& hMessageBox = FindWindow("#32770", "Self Closing Message Box") If hMessageBox Then Call SetForegroundWindow(hMessageBox) SendKeys "{enter}" End If Call LockWindowUpdate(API_FALSE) End Sub Private Sub Form_Load() 'Replace the '4000' below with the number of milliseconds the message box will appear. '1000 milliseconds = 1 second SetTimer hWnd, NV_CLOSEMSGBOX, 4000&, AddressOf TimerProc Call MessageBox(hWnd, "Watch this message box close itself after four seconds", "Self Closing Message Box", MB_ICONQUESTION Or MB_TASKMODAL) End Sub |
Enjoy this article?
Filed under: Miscellaneous
Leave a comment