Support Forums
[Snippet] Autoclose Msgbox - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [Snippet] Autoclose Msgbox (/showthread.php?tid=18836)



[Snippet] Autoclose Msgbox - euverve - 05-18-2011

I have derived this code from this post.
Code:
http://www.vbforums.com/showpost.php?p=3745046&postcount=5

And created a simple function for autoclosing msgbox.
Usage:
Code:
msgboxautoclose("Sample message goes here", MsgBoxStyle.Information, "Title Message", 20)

20 is the delay to close the msgbox

Code:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte,
                       ByVal bScan As Byte, _
                       ByVal dwFlags As Byte, _
                       ByVal dwExtraInfo As Byte)

    Private Const VK_RETURN As Byte = &HD
    Private Const KEYEVENTF_KEYDOWN As Byte = &H0
    Private Const KEYEVENTF_KEYUP As Byte = &H2

    Public Sub msgboxautoclose(ByVal Message As String, Optional ByVal Style As MsgBoxStyle = Nothing, Optional ByVal title As String = Nothing, Optional ByVal delay As Integer = 5)
        Dim t As New Threading.Thread(AddressOf closeMsgbox)
        t.Start(delay) '5 second default delay
        MsgBox(Message, Style, title)
    End Sub

    Private Sub closeMsgbox(ByVal delay As Object)
        Threading.Thread.Sleep(CInt(delay) * 1000)
        AppActivate(Me.Text)
        keybd_event(VK_RETURN, 0, KEYEVENTF_KEYDOWN, 0)
        keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)
    End Sub

Credits goes to paul and modification from me.




RE: [Snippet] Autoclose Msgbox - KoBE - 05-18-2011

Thanks for sharing. Not sure why would use this but it seems to work as stated. To make this simpler, I'm sure you could use SendKeys().


RE: [Snippet] Autoclose Msgbox - PURP - 05-18-2011

I am sure I can find this useful somehow thanks for this.


RE: [Snippet] Autoclose Msgbox - euverve - 05-19-2011

(05-18-2011, 01:02 PM)KoBE Wrote: Thanks for sharing. Not sure why would use this but it seems to work as stated. To make this simpler, I'm sure you could use SendKeys().

Sendkeys is not working if the msgbox is not on focus.


RE: [Snippet] Autoclose Msgbox - KoBE - 05-19-2011

This wouldn't either without
Code:
AppActivate(Me.Text)

so put that in and SendKeys should work.


RE: [Snippet] Autoclose Msgbox - stephen5565 - 05-20-2011

I think this had been posted before, I saw this when I clicked the Search Button Smile


RE: [Snippet] Autoclose Msgbox - euverve - 05-20-2011

(05-20-2011, 06:42 AM)stephen5565 Wrote: I think this had been posted before, I saw this when I clicked the Search Button Smile

I guess we are of different approach.


RE: [Snippet] Autoclose Msgbox - Pyratepig - 05-25-2011

Thanks, I was looking for this.~
Was too lazy to search Google :]