Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes you want to pop up a message for the user, and want your app
'to continue to go about it's business. You can create a modeless dialog but
'there's a much simple way to do it - by using a messagebox in a thread
'of its own!
'Primary Code:
'Credit: Arie Verheul
'Just create a thread function like this, and call it whenever you need it.
Thread Function ModelessMsgBox (ByVal arg As Long) As Long
MsgBox gTxt$, gStyle%, gTitle$
End Function
'You can put the MsgBox$ variable within the thread, if the values are
'fixed. If you want the function to be more generic, you can use Global
'variables - as in the example below.
'Compilable Example: (Jose Includes)
'This example sets Global variables before each call of the function.
'If the program closes before the user shuts down the messagebox,
'Windws will close the messagebox.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword, gtxt$, gStyle%, gtitle As AsciiZ * 256, hThread As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Control Add Label, hDlg, 200,"<count>", 50,40,100,20
Control Add Button, hDlg, 300,"Close MsgBox", 50,70,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local i As Long
gTxt$ = "Am I holding things up? I hope not!"
gStyle% = %MB_Ok + %MB_IconExclamation
gTitle = "Modeless MessageBox"
Thread Create ModelessMsgBox(0) To hThread
For i = 0 To 50
Control Set Text hDlg, 200, Str$(i)
Sleep 50
Next i
End If
If CB.Msg = %WM_Command AND CB.Ctl = 300 AND CB.Ctlmsg = %BN_Clicked Then
Local Z as AsciiZ*200
Z = gtitle$
SendMessage FindWindow("", Z), %WM_CLOSE, 0, 0
'PostMessage FindWindow("", Z), %BM_Click, 0, 0
End If
End Function
Thread Function ModelessMsgBox (ByVal arg As Long) As Long
MsgBox gTxt$, gStyle%, gTitle$
End Function
'gbs_00337
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm