Results 1 to 14 of 14

Thread: [RESOLVED] VB6 QUESTION: Non-Modal message box in its own thread

  1. #1

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Resolved [RESOLVED] VB6 QUESTION: Non-Modal message box in its own thread

    Chaps,

    My application connects two users. The app can be shutdown by a remote user sending a correct code. Housekeeping. That's all working fine.

    If the user has left his station and the the shutdown has occurred in his absence I'd like to leave a message box on the screen saying the app has been fully shutdown - with an OK to close the message box.

    Clearly, if I have a modal message box in the app it means that it has not completely closed down.

    Can I initiate a WINAPI via a callback or similar to create a message box in its own thread that allows the main process to die but leaving a separate message box on the screen? Can you advise if this is an advisable approach or whether there would be untoward implications.

    Is my idea feasible? I know I could always just initiate another binary on form close using shellexecute, an app with just the message box in it but that seems a bit shoddy.

    Your thoughts please.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Depending on your user's OS https://docs.microsoft.com/en-us/win...ification-area might be an option. https://www.dreamincode.net/forums/t...y-icon-in-vb6/ might be a useful sample.

    That should allow you to raise the notification and have it remain available even after the app has exited.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    If you want your program to be "fully shut down" then an extra thread isn't of any use. You'd need a new process.

  4. #4

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    So, I really might need a small binary with no visible form and just a modal pop up that has a line of text and a OK button.

    I could call that with a final shellExecute and then unload the main form afterwards.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Quote Originally Posted by yereverluvinuncleber View Post
    Is my idea feasible? I know I could always just initiate another binary on form close using shellexecute, an app with just the message box in it but that seems a bit shoddy.

    Your thoughts please.
    You could do it with the same exe:

    In bas a module
    Code:
    Public Sub Main()
        If Command$ = "/Msg" Then
            MsgBox "The program has been closed", vbInformation
        Else
            Form1.Show
        End If
    End Sub
    In a Form
    Code:
    Private Sub Form_Unload(Cancel As Integer)
        Shell App.Path & "\" & App.EXEName & ".exe /Msg"
    End Sub
    But I'm not sure about the point of not showing the message from the same process.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Er, why not just use a small Form? MsgBox is not magical.

    Neither is ShellExecute() the way most people use it. Just use VB's Shell() function. Gratuitous API calls don't make your back spout wings, quite the contrary.

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Quote Originally Posted by Eduardo- View Post
    You could do it with the same exe:

    In bas a module
    Code:
    Public Sub Main()
        If Command$ = "/Msg" Then
            MsgBox "The program has been closed", vbInformation
        Else
            Form1.Show
        End If
    End Sub
    In a Form
    Code:
    Private Sub Form_Unload(Cancel As Integer)
        Shell App.Path & "\" & App.EXEName & ".exe /Msg"
    End Sub
    But I'm not sure about the point of not showing the message from the same process.
    This method is the best method in my opinion. You get to free all the resources used by your application while still being able to show your close message without any added complexity.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Code:
    Shell App.Path & "\" & App.EXEName & ".exe /Msg"
    ... is a lit exploding cigar, just waiting to blow up in your face. Instead:

    Code:
    Shell """" & App.EXEName & ".exe"" " & MsgText, vbNormalFocus
    You need to quote the name of the program, then have a separating space, then your message text can follow. It isn't a switch, so why even add any "/" or "-" at all? That will just be more to parse when you don't have to.


    Shell() calls WinExec(), which documents things like the search path priority list and the need to quote the program file name.

    Failure to understand these fundamentals has led to numerous threads asking the same "Shell be broked" question over and over.

  9. #9
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Quote Originally Posted by dilettante View Post
    ... is a lit exploding cigar, just waiting to blow up in your face. Instead:

    kkkkkkkkkk

    Edit: what mood

  10. #10
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    I think that without giving the full path, it could fail when the CurDir is set to somewhere else (I don't have time now to test it).
    Also, mine was a simplified example, you also need to take into account that App.Path could already have the \ at the end, and that it won't work in IDE.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    WinExec function

    If the name of the executable file in the lpCmdLine parameter does not contain a directory path, the system searches for the executable file in this sequence:

    The directory from which the application loaded.
    The current directory.
    The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
    The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
    The directories listed in the PATH environment variable.

  12. #12
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Quote Originally Posted by dilettante View Post
    This is provided only for comparibility with Win 3.x and VB6 is old but not that old so dont’t use it.

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    Sure, it's been deprecated for 25 years. But it is still fully supported and used by lots of software including VB6.

    You can say the same thing about other Win32 API calls like LoadIcon(), GetVersion(), or some options of the Escape() function but they are still there, supported, and widely used.

  14. #14
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: VB6 QUESTION: Non-Modal message box in its own thread

    MSDN says flat out right that WinExec is left only for compatibility with source codes for 16-bit apps.

    It does not mention that LoadIcon comes from 16-bit ages (though it could be).

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