-
Sep 7th, 2021, 09:06 AM
#1
[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.
-
Sep 7th, 2021, 09:44 AM
#2
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.
-
Sep 7th, 2021, 10:31 AM
#3
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.
-
Sep 7th, 2021, 10:49 AM
#4
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.
-
Sep 7th, 2021, 12:40 PM
#5
Re: VB6 QUESTION: Non-Modal message box in its own thread
Originally Posted by yereverluvinuncleber
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.
-
Sep 7th, 2021, 12:53 PM
#6
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.
-
Sep 7th, 2021, 10:19 PM
#7
Re: VB6 QUESTION: Non-Modal message box in its own thread
Originally Posted by Eduardo-
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.
-
Sep 8th, 2021, 11:39 AM
#8
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.
-
Sep 8th, 2021, 12:02 PM
#9
Re: VB6 QUESTION: Non-Modal message box in its own thread
Originally Posted by dilettante
... is a lit exploding cigar, just waiting to blow up in your face. Instead:
kkkkkkkkkk
Edit: what mood
-
Sep 8th, 2021, 12:03 PM
#10
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.
Last edited by Eduardo-; Sep 8th, 2021 at 07:24 PM.
-
Sep 8th, 2021, 12:05 PM
#11
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.
-
Sep 8th, 2021, 12:33 PM
#12
Re: VB6 QUESTION: Non-Modal message box in its own thread
Originally Posted by dilettante
This is provided only for comparibility with Win 3.x and VB6 is old but not that old so dont’t use it.
-
Sep 8th, 2021, 08:30 PM
#13
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.
-
Sep 9th, 2021, 04:42 AM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|