Not tried this yet
http://vbnet.mvps.org/index.html?cod...xhooktimer.htm
is there a better way then that? thats tons of code for a msgbox
Printable View
Not tried this yet
http://vbnet.mvps.org/index.html?cod...xhooktimer.htm
is there a better way then that? thats tons of code for a msgbox
I would suggest making your own using a simple form and a timer...
that the only way?
No... clearly there's another way... but as you pointed out... that's a lot of code.
-tg
here's a simple example:
vb Code:
Public Class Form1 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 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t As New Threading.Thread(AddressOf closeMsgbox) t.Start(10) '10 second delay MsgBox("message") 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 End Class
It looks an interesting coding example. I might work through it solely because it works with the Win32 model; something which isn't really covered in MSDN.
I've found a very simple way to do this, using the windows API messageBox Call.
This will open a new MessageBox, and close the previous one every time the timer ticks. What it does is it creates a messagebox under the hidden window form2. Closing form2 will then close the messagebox as well.Code:Private form2 As New Form()
<DllImport("user32.dll", CharSet := CharSet.Unicode)> _
Public Shared Function MessageBox(hWnd As IntPtr, text As [String], caption As [String], type As UInteger) As Integer
End Function
Private Sub timer1_Tick(sender As Object, e As EventArgs)
form2.Close()
form2 = New Form()
MessageBox(form2.Handle, "test", "test", 0)
End Sub
I haven't actually tried this in vb, I converted the code I wrote in c#... but it should work the same way.
A little modifications.
Usage:
Code:msgboxautoclose("Sample message goes here", MsgBoxStyle.Information, "Title Message", 20)
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