Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autohide MSGBOX, possible?

Status
Not open for further replies.

codecref

Programmer
Dec 8, 2003
118
US
is it possible to autohide msgbox in 1 or 3 second or something like that?

thanks.
 
It might be possible with API calls, I am really not sure. But wouldn't it be easier to create your own message box form and just add a timer. Food for thought.

zemp
 
Just wanted to give an alternate solution. (Code found on the net, and at the source, the author was "Daniel Biener")

Code:
[B]Module[/B]
Option Explicit

Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Const NV_CLOSEMSGBOX As Long = &H5000&
Private sLastTitle As String

Public Function ACmsgbox(AutoCloseSeconds As Long, prompt As String, Optional buttons As Long, _
                         Optional title As String, Optional helpfile As String, _
                         Optional context As Long) As Long

    sLastTitle = title
    SetTimer Screen.ActiveForm.hWnd, NV_CLOSEMSGBOX, AutoCloseSeconds * 1000, AddressOf TimerProc
    ACmsgbox = MsgBox(prompt, buttons, title, helpfile, context)

End Function

Private Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)

  Dim hMessageBox As Long

    KillTimer hWnd, idEvent

    Select Case idEvent
      Case NV_CLOSEMSGBOX
        hMessageBox = FindWindow("#32770", sLastTitle)
        If hMessageBox Then
            Call SetForegroundWindow(hMessageBox)
            SendKeys "{enter}"
        End If
        sLastTitle = vbNullString
    End Select

End Sub

Code:
[B]Form[/B]
Option Explicit

Private Sub Form_Click()
    ACmsgbox 2, "Hi"
End Sub

Now click on the form.

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
If using XP, another alternative is the MessageBoxTimeout function (that is if you don't mind using an un-documented function):

Declare Function MessageBoxTimeout Lib "user32.dll" Alias
"MessageBoxTimeoutA" (_
Byval hwnd As Long, _
Byval lpText As String, _
Byval lpCaption As String, _
Byval uType As Long, _
Byval wLanguageID As Long, _
Byval lngMilliseconds As Long) As Long

Same as MessageBoxEx but with an additional timeout parameter.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top