|
-
Sep 30th, 2004, 11:42 PM
#1
Thread Starter
PowerPoster
Keep Your Background Processes Running When Displaying Message Box
In Visual Basic, if you make a call to the MsgBox function, all other background processes that you may have running (counters, timer events, etc) are stopped until the user acknowledges the Msgbox dialog box. This can be potentially devastating if you write an application that runs unattended.
To overcome this problem, you must use the Windows API call for the MessageBox function. It looks and acts the same as the Visual Basic "msgbox" function, but does not stop the background processes from running.
The Code below show the difference between the two methods.
Press the first button to display message box with VB MsgBox function, and the second button to display it via API.
Add 2 Command Button (named Command1 and Command2)
Add 1 Label (named Label1)
Add 1 Timer Control. Set the Timer Interval property to 1
VB Code:
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As _
Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As _
Long) As Long
Private Sub Command1_Click()
MsgBox "The Timer STOPS!"
End Sub
Private Sub Command2_Click()
MessageBox Me.hwnd, "Notice the timer does not stop!", "API Call", _
vbOKOnly + vbExclamation
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Time
End Sub
-
Sep 30th, 2004, 11:46 PM
#2
Actually its a little know fact that in VB6 there is a bug in the IDE.
When you use a standard msgbox and have a timer control
enabled, it will stop the timer from processing in the IDE. But
when you compile it, the timer will continue to increment. I think it
was Wokawidget who pointed this out to me a few weeks ago.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 30th, 2004, 11:49 PM
#3
Thread Starter
PowerPoster
yeh i have seen that woka's post.
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
|