Results 1 to 3 of 3

Thread: Keep Your Background Processes Running When Displaying Message Box

  1. #1

    Thread Starter
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    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:
    1. Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As _
    2. Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As _
    3. Long) As Long
    4.  
    5. Private Sub Command1_Click()
    6.     MsgBox "The Timer STOPS!"
    7. End Sub
    8.  
    9. Private Sub Command2_Click()
    10.     MessageBox Me.hwnd, "Notice the timer does not stop!", "API Call", _
    11. vbOKOnly + vbExclamation
    12. End Sub
    13.  
    14. Private Sub Timer1_Timer()
    15.     Label1.Caption = Time
    16. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    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
  •  



Click Here to Expand Forum to Full Width