Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#COMPILE EXE '#Win 11.00#
#DIM ALL
#INCLUDE "Win32Api.inc"
GLOBAL hDlg AS DWORD
GLOBAL hMutex AS DWORD
%ButtonCreateMutex = 101
%ButtonReleaseMutex = 102
'______________________________________________________________________________
THREAD FUNCTION ThreadProc(BYVAL idThread AS DWORD) AS DWORD
LOCAL RetVal AS LONG
LOCAL szMutex AS ASCIIZ * 64
RetVal = WaitForSingleObject(hMutex, %INFINITE)
IF RetVal = %WAIT_OBJECT_0 THEN
SetWindowText(hDlg, "WAIT_OBJECT_0")
END IF
WinBeep(1500, 100)
END FUNCTION
'______________________________________________________________________________
CALLBACK FUNCTION DlgProc() AS LONG
LOCAL hThread AS DWORD
STATIC szMutex AS ASCIIZ * 64
SELECT CASE CBMSG
CASE %WM_COMMAND
SELECT CASE CBCTL
CASE %ButtonCreateMutex
hMutex = CreateMutex(BYVAL 0, %TRUE, szMutex)
THREAD CREATE ThreadProc(0) TO hThread
CASE %ButtonReleaseMutex
ReleaseMutex(hMutex)
CloseHandle(hMutex)
END SELECT
END SELECT
END FUNCTION
'______________________________________________________________________________
FUNCTION PBMAIN() AS LONG
DIALOG NEW PIXELS, %HWND_DESKTOP, "WaitForSingleObject / CreateMutex", , , 400, 100, %WS_OverlappedWindow To hDlg
CONTROL ADD BUTTON, hDlg, %ButtonCreateMutex, "Create Mutex", 150, 20, 100, 20
CONTROL ADD BUTTON, hDlg, %ButtonReleaseMutex, "Release Mutex", 150, 60, 100, 20
DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION
http://www.garybeene.com/sw/gbsnippets.htm