Results 1 to 9 of 9

Thread: self closing message box

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    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

  2. #2
    Addicted Member Spirited Machine's Avatar
    Join Date
    May 2009
    Posts
    215

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: self closing message box

    that the only way?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: self closing message box

    No... clearly there's another way... but as you pointed out... that's a lot of code.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: self closing message box

    here's a simple example:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Sub keybd_event Lib "user32" _
    4.                       (ByVal bVk As Byte, _
    5.                        ByVal bScan As Byte, _
    6.                        ByVal dwFlags As Byte, _
    7.                        ByVal dwExtraInfo As Byte)
    8.  
    9.     Private Const VK_RETURN As Byte = &HD
    10.     Private Const KEYEVENTF_KEYDOWN As Byte = &H0
    11.     Private Const KEYEVENTF_KEYUP As Byte = &H2
    12.  
    13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    14.         Dim t As New Threading.Thread(AddressOf closeMsgbox)
    15.         t.Start(10) '10 second delay
    16.         MsgBox("message")
    17.     End Sub
    18.  
    19.     Private Sub closeMsgbox(ByVal delay As Object)
    20.         Threading.Thread.Sleep(CInt(delay) * 1000)
    21.         AppActivate(Me.Text)
    22.         keybd_event(VK_RETURN, 0, KEYEVENTF_KEYDOWN, 0)
    23.         keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)
    24.     End Sub
    25.  
    26. End Class

  6. #6
    Lively Member eatmycode's Avatar
    Join Date
    Mar 2010
    Location
    Kingston upon Hull
    Posts
    74

    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

  7. #7
    Member
    Join Date
    Apr 2008
    Posts
    39

    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.

  8. #8
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Thumbs up 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

  9. #9
    New Member
    Join Date
    Oct 2018
    Posts
    10

    Re: self closing message box

    Quote Originally Posted by .paul. View Post
    here's a simple example:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Sub keybd_event Lib "user32" _
    4.                       (ByVal bVk As Byte, _
    5.                        ByVal bScan As Byte, _
    6.                        ByVal dwFlags As Byte, _
    7.                        ByVal dwExtraInfo As Byte)
    8.  
    9.     Private Const VK_RETURN As Byte = &HD
    10.     Private Const KEYEVENTF_KEYDOWN As Byte = &H0
    11.     Private Const KEYEVENTF_KEYUP As Byte = &H2
    12.  
    13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    14.         Dim t As New Threading.Thread(AddressOf closeMsgbox)
    15.         t.Start(10) '10 second delay
    16.         MsgBox("message")
    17.     End Sub
    18.  
    19.     Private Sub closeMsgbox(ByVal delay As Object)
    20.         Threading.Thread.Sleep(CInt(delay) * 1000)
    21.         AppActivate(Me.Text)
    22.         keybd_event(VK_RETURN, 0, KEYEVENTF_KEYDOWN, 0)
    23.         keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)
    24.     End Sub
    25.  
    26. 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
  •  



Click Here to Expand Forum to Full Width