This implies that synchronisation techniques are required at all times [in multi-thread programs]
Thank you for letting me know.
MCM
DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" _ (BYVAL hWnd AS DWORD, _ lpText AS ASCIIZ, _ lpCaption AS ASCIIZ, _ BYVAL dwType AS DWORD) AS LONG TYPE MyUDT hWnd AS DWORD lpText AS ASCIIZ * 128 lpCaption AS ASCIIZ * 128 dwType AS DWORD END TYPE FUNCTION PBMAIN& mb 0,"How now brown cow","Title", %MB_ICONERROR ? "Click to exit" END FUNCTION SUB MB(hWnd AS DWORD, lpText AS ASCIIZ,lpCaption AS ASCIIZ,dwType AS DWORD) LOCAL x AS MyUDT, hThread AS DWORD x.hWnd = hWnd x.lpText = lpText x.lpCaption = lpCaption x.dwType = dwType THREAD CREATE MessageBoxThread(VARPTR(x)) TO hThread??? SLEEP 50 THREAD CLOSE hThread??? TO hThread??? END SUB THREAD FUNCTION MessageBoxThread(BYVAL y AS DWORD) AS DWORD LOCAL x AS MyUDT POINTER LOCAL hWnd AS DWORD LOCAL lpText AS ASCIIZ * 128 LOCAL lpCaption AS ASCIIZ * 128 LOCAL dwType AS DWORD x = y MessageBox @x.hWnd,@x.lpText,@x.lpCaption,@x.dwType END FUNCTION
TYPE MyUDT txt AS STRING * 128 MyStyle AS INTEGER title AS STRING * 128 END TYPE FUNCTION PBMAIN& LOCAL z AS ASCIIZ * 128 LOCAL x AS LONG mb "How now brown cow", %MB_ICONERROR, "Title" ? "Click to exit" END FUNCTION SUB MB(txt AS STRING, STYLE AS INTEGER, Title AS STRING) LOCAL x AS MyUDT, hThread AS DWORD x.txt = txt x.MyStyle = STYLE x.Title = Title THREAD CREATE MessageBoxThread(VARPTR(x)) TO hThread??? SLEEP 50 THREAD CLOSE hThread??? TO hThread??? END SUB THREAD FUNCTION MessageBoxThread(BYVAL y AS DWORD) AS DWORD LOCAL x AS MyUDT POINTER x = y LOCAL txt AS STRING LOCAL MyStyle AS INTEGER LOCAL Title AS STRING txt = @x.txt MyStyle = @x.MyStyle title = @x.title ? txt,MyStyle,title END FUNCTION
FUNCTION PBMAIN& LOCAL z AS ASCIIZ * 128 MB "No global" SLEEP 3000 END FUNCTION SUB MB(z AS ASCIIZ) LOCAL x AS DWORD, hThread AS DWORD x = VARPTR(z) THREAD CREATE MessageBoxThread(x) TO hThread SLEEP 50 THREAD CLOSE hThread TO hThread END SUB THREAD FUNCTION MessageBoxThread(BYVAL y AS DWORD) AS DWORD LOCAL z AS ASCIIZ * 128 ? PEEK$(y,128) END FUNCTION
InterlockedExchange g_intvar, g_intVar + 10
GLOBAL gs AS STRING FUNCTION PBMAIN& MB "one" MB "two SLEEP 2000 END FUNCTION SUB MB(s AS STRING) gs=s THREAD CREATE MessageBoxThread(x???) TO hThread??? SLEEP 50 THREAD CLOSE hThread??? TO hThread??? END SUB THREAD FUNCTION MessageBoxThread(BYVAL y AS DWORD) AS DWORD ? gs END FUNCTION
#Console Off ' Remove for PBWIN #Include "win32api.inc" Function PBMain () As Long Dim MsgText As Global Asciiz*60 Dim Response As Global Long Local hThread As Dword Local ThreadVar As Dword Local hWnd As Dword Local FontHndl As Dword Local I,J,K,L As Long Local ThreadStatus As Long Local ThreadStarted As Long '------------------------------------------------------------- ' Set up graphic window Graphic Window "Messagebox in thread", 100,100,300,200 To hWnd Graphic Attach hWnd,0 Graphic Color %White,%Black Graphic Clear Font New "Courier New",12 To FontHndl Graphic Set Font FontHndl '------------------------------------------------------------- MsgText = "Just say so if you want to stop when this set is finished" ThreadStarted = 0 Do For J = 2 To 9 For I = 1 To 10 K = I * J Graphic Print Using$( Space$(8) + "## x # = ##",I,J,K) Sleep 100 Next Sleep 1000 Graphic Clear If IsWindow(hWnd) = 0 Then Exit Function ' End program if window was closed Next Incr L '---------------------------------------------------------------------------------- If L = 1 Then ' Show message box Thread Create Message (ThreadVar) To hThread Threadstarted = -1 ' Set flag that messagebox thread was started End If '---------------------------------------------------------------------------------- ' This is to test if thread is still running or has finished If ThreadStarted Then ' Test if thread has finished Thread Status hThread To ThreadStatus If ThreadStatus = 259 Then Iterate Loop ' 259 corresponds to running thread End If '---------------------------------------------------------------------------------- Loop Until Response = 6 End Function '------------------------------------------------------------------------------------------ ' Message box thread function Thread Function Message (ByVal ThreadVar As Dword) ' ThreadVar is a dummy variable MessageBox 0, MsgText, "Test Message Box" , 4 To Response End Function '------------------------------------------------------------------------------------------
' I had to use a string ptr here instead of CONTROL GET TEXT because the calling thread was in a wait ' state (WaitForSingleObject) and apparently (undocumented but not reasonably) CONTROL GET TEXT does ' "something" which must execute in the context of the same thread (suspended) as the dialog. ' Apparently (that means also not documented), DIALOG GET USER does not need to execute anything in the ' context of the thread in which the dialog was created.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: