CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2001
    Posts
    27

    Buttonless, timed message box?

    Hello!

    At some point in my program, I would like to pop up a message box, have it buttonless and only displayed for say one second. Is this possible? I've thought about creating another form and timing its life, but I was hoping for something more seemless.

    Thanks and any code examples would be great!
    Dubz


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Buttonless, timed message box?

    'add reference to Windows Scripting host Object model

    Dim wshShell As New IWshShell_Class
    Dim lngReturn As Long
    Dim intSeconds2Wait As Integer
    intSeconds2Wait = 1
    lngReturn = wshShell.Popup("Place Your Text Here", intSeconds2Wait)



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jan 2001
    Posts
    27

    Re: Buttonless, timed message box?

    Hmm I think I am unfamiliar with IWshShell_Class. Is this something I create or that already exsits? Either way what is the declaration?

    Sorry for the hand holding. Just trying to learn =)

    Dubz


  4. #4
    Join Date
    Apr 2000
    Posts
    737

    Re: Buttonless, timed message box?

    maybe you can consider a modeless dialog box.

    cksiow
    http://vblib.virtualave.net - share our codes


  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Buttonless, timed message box?

    Any way to get rid of the OK button?

    John G

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Buttonless, timed message box?

    Go to Project\References and select
    "Windows Script Host Object Model"

    John G

  7. #7
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Buttonless, timed message box?

    Another way is to create your own form in VB that has a timer (timer control). Check out the code below (i've not tested it out - just from my head):

    FORM1:
    1. The main form

    FORM2:
    1. The message box
    2. Has a label called Label1
    3. Has a timer control called Timer1

    In Form2:

    public sub PopupMessage(szMsg as string, nSecsToWait as integer, frmMaster as form)
    ' note that we allow max wait to 60secs
    if ((nSecsToWait < 1) or (nSecsToWait > 60)) then
    nSecsToWait = 60
    end if

    ' set the label
    Label1.Caption = szMsg

    ' set the timer
    Timer1.Interval = nSecsToWait * 1000
    Timer1.Enabled = true

    ' show the form modal
    me.show 1, frmMaster

    ' unload the form
    Unload me
    end sub

    private Sub Timer1_Timer()
    ' disable timer and then hide the form
    Timer1.Enabled = false
    me.Hide
    End Sub




    In Form2:

    private sub Command1_Click()
    call Form1.PopupMessage("Critical error!", 5, me)
    end sub




    -Cool Bizs

    Good Luck,
    -Cool Bizs

  8. #8
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Buttonless, timed message box?

    Another way to create msgbox which will close by itself

    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hWnd As Long, ByVal _
    wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Private Const WM_CLOSE = &H10

    Private Const MsgTitle As String = "Test Message"

    Private Sub Command1_Click()
    With Timer1
    .Interval = 2000
    .Enabled = True
    End With
    MsgBox "I should disappear in two seconds.", , MsgTitle
    End Sub

    Private Sub Timer1_Timer()
    Dim hWnd As Long
    Timer1.Enabled = False

    hWnd = FindWindow(vbNullString, MsgTitle)
    Call SendMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
    End Sub


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured