Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Snippet] Autoclose Msgbox
#1
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.

USB Anti-virus? Try USB Drive Defender
[Image: 8bQCusS.jpg]
Reply
#2
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().
Reply
#3
I am sure I can find this useful somehow thanks for this.
Reply
#4
(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.
USB Anti-virus? Try USB Drive Defender
[Image: 8bQCusS.jpg]
Reply
#5
This wouldn't either without
Code:
AppActivate(Me.Text)

so put that in and SendKeys should work.
Reply
#6
I think this had been posted before, I saw this when I clicked the Search Button Smile
[Image: UTLN2.gif]
That's not my Sig . So don't flame me.
Reply
#7
(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.
USB Anti-virus? Try USB Drive Defender
[Image: 8bQCusS.jpg]
Reply
#8
Thanks, I was looking for this.~
Was too lazy to search Google :]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Snippet] Check Email if gmail and valid password length euverve 4 1,816 05-20-2011, 06:51 AM
Last Post: stephen5565
  [Snippet] Get Local Getway euverve 1 1,027 05-16-2011, 07:56 PM
Last Post: KoBE
  [Snippet] Get OS Uptime euverve 0 877 05-12-2011, 07:08 PM
Last Post: euverve
  [Snippet] Random pick from list (Range) euverve 0 693 05-12-2011, 08:22 AM
Last Post: euverve
  [Release] Msgbox Generator for VB.NET euverve 12 3,195 05-12-2011, 03:03 AM
Last Post: euverve

Forum Jump:


Users browsing this thread: 1 Guest(s)