Click to See Complete Forum and Search --> : Buttonless, timed message box?
Dubz
April 13th, 2001, 03:39 PM
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
Iouri
April 13th, 2001, 03:49 PM
'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
iouri@hotsheet.com
Dubz
April 13th, 2001, 03:59 PM
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
cksiow
April 13th, 2001, 07:50 PM
maybe you can consider a modeless dialog box.
cksiow
http://vblib.virtualave.net - share our codes
John G Duffy
April 14th, 2001, 08:17 AM
Any way to get rid of the OK button?
John G
John G Duffy
April 14th, 2001, 01:28 PM
Go to Project\References and select
"Windows Script Host Object Model"
John G
coolbiz
April 15th, 2001, 11:31 AM
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
Iouri
April 16th, 2001, 07:08 AM
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
iouri@hotsheet.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.