|
-
Mar 4th, 2010, 03:47 PM
#1
Thread Starter
Fanatic Member
self closing message box
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
-
Mar 4th, 2010, 03:49 PM
#2
Addicted Member
Re: self closing message box
I would suggest making your own using a simple form and a timer...
Last edited by Spirited Machine; Mar 4th, 2010 at 03:58 PM.
-
Mar 4th, 2010, 05:25 PM
#3
Thread Starter
Fanatic Member
Re: self closing message box
-
Mar 4th, 2010, 05:42 PM
#4
Re: self closing message box
No... clearly there's another way... but as you pointed out... that's a lot of code.
-tg
-
Mar 4th, 2010, 05:48 PM
#5
Re: self closing message box
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 4th, 2010, 06:52 PM
#6
Lively Member
Re: self closing message box
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.
Technik ... Kniff, die Welt so einzurichten, dass wir sie nicht erleben mussen
Max Frisch
-
May 18th, 2011, 08:53 AM
#7
Member
Re: self closing message box
I've found a very simple way to do this, using the windows API messageBox Call.
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
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.
I haven't actually tried this in vb, I converted the code I wrote in c#... but it should work the same way.
-
May 18th, 2011, 09:48 AM
#8
New Member
Re: self closing message box
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
-
Nov 9th, 2018, 09:27 AM
#9
New Member
Re: self closing message box
 Originally Posted by .paul.
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
hi paul.
awesome code,
but its possible set it only auto close for any error message box pop up .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|