You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
I would disable the buttons as soon as I created the worker thread
Code:
CASE %WM_COMMAND
IF CBTL = %ID_BUTTON1 THEN
THREAD CREATE ThreadOne (CBHNDL) TO hThread
ELSEIF CBCTL = %ID_BUTTON2 THEN
THREAD CREATE ThreadTwo (CBHNDL) TO hThread
END IF
' disable the button we just used. WIll be re-enabled when thread function completes.
CONTROL DISABLE CBHNDL, CBTL
..
I'm fairly new to DDT and such, I'm therefore seeking someone with a little more experience in that field to overlook what I've done.
Code:
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"
#INCLUDE "COMMCTRL.INC"
%IDC_PROGRESSBAR1 = 1001
%IDC_BUTTON1 = 1002
%IDC_BUTTON2 = 1003
CALLBACK FUNCTION MainDialogProc()
LOCAL hThread AS DWORD
SELECT CASE CBMSG
CASE %WM_INITDIALOG
DIALOG POST CBHNDL, %WM_USER + 500, 0, 0
CASE %WM_USER + 500
CASE %WM_USER + 501
'CONTROL DISABLE CBHNDL, %IDC_BUTTON1
'CONTROL DISABLE CBHNDL, %IDC_BUTTON2
CASE %WM_USER + 502
'CONTROL ENABLE CBHNDL, %IDC_BUTTON1
'CONTROL ENABLE CBHNDL, %IDC_BUTTON2
CASE %WM_COMMAND
SELECT CASE LOWRD(CBWPARAM)
CASE %IDC_BUTTON1
IF CBCTLMSG = %BN_CLICKED THEN
THREAD CREATE ThreadOne(CBHNDL) TO hThread
END IF
CASE %IDC_BUTTON2
IF CBCTLMSG = %BN_CLICKED THEN
THREAD CREATE ThreadTwo(CBHNDL) TO hThread
END IF
END SELECT
END SELECT
END FUNCTION
SUB MainDialog()
LOCAL hDlg AS DWORD
DIALOG NEW %HWND_DESKTOP, "Dialog Button and Progress", , , 135, 30, %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_TOOLWINDOW OR %WS_EX_APPWINDOW TO hDlg
CONTROL ADD "msctls_progress32", hDlg, %IDC_PROGRESSBAR1, "ProgressbarOne", 5, 5, 125, 5, %WS_CHILD OR %WS_VISIBLE OR %PBS_SMOOTH
CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button One", 5, 15, 60, 12, %WS_CHILD OR %BS_FLAT OR %WS_TABSTOP
CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Button Two", 70, 15, 60, 12, %WS_CHILD OR %BS_FLAT OR %WS_TABSTOP
DIALOG SHOW MODAL hDlg CALL MainDialogProc()
END SUB
FUNCTION ThreadOne( BYVAL hDlg AS DWORD ) AS LONG
DIALOG POST hDlg, %WM_USER + 501, 0, 0
CONTROL SEND hDlg, %IDC_PROGRESSBAR1, %PBM_SETRANGE, 0, MAKLNG(0, 100)
CONTROL SEND hDlg, %IDC_PROGRESSBAR1, %PBM_SETPOS, 0, 0
CONTROL SEND hDlg, %IDC_PROGRESSBAR1, %PBM_SETSTEP, 1, 0
LOCAL i AS BYTE
FOR i = 1 TO 100 STEP 1
SLEEP 10
CONTROL SEND hDlg, %IDC_PROGRESSBAR1, %PBM_STEPIT, 0, 1
NEXT i
DIALOG POST hDlg, %WM_USER + 502, 0, 0
END FUNCTION
FUNCTION ThreadTwo( BYVAL hDlg AS DWORD ) AS LONG
DIALOG POST hDlg, %WM_USER + 501, 0, 0
CONTROL SEND hDlg, %IDC_PROGRESSBAR1, %PBM_SETRANGE, 0, MAKLNG(0, 100)
CONTROL SEND hDlg, %IDC_PROGRESSBAR1, %PBM_SETPOS, 50, 0
SLEEP 500
DIALOG POST hDlg, %WM_USER + 502, 0, 0
END FUNCTION
FUNCTION PBMAIN() AS LONG
CALL MainDialog
END FUNCTION
What I'm especially interested in is;
Is there any critical mistakes in my code and what should I do differently.
How I pass the handlers around and in general how I've constructed it.
How I use the control styles both on the buttons and the dialog.
I've only used a few styles, what's the consequence of only using a few, are there any dependencies on styles.
At last, the way I enable and disable the two buttons seems to be a bit buggy for me, when they are enabled again the ws_tabstop stops working and they act weird.
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: