Announcement

Collapse
No announcement yet.

Dialogs, Buttons, Progressbars and DDT in general

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    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 
    ..
    FWIW, here's a fully-commented demo of what I suggest...
    GUI + Worker Thread + Abort Demo 11-24-07

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Dialogs, Buttons, Progressbars and DDT in general

    Dialogs, Buttons, Progressbars and DDT in general

    Hello,

    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;
    1. Is there any critical mistakes in my code and what should I do differently.
    2. How I pass the handlers around and in general how I've constructed it.
    3. How I use the control styles both on the buttons and the dialog.
    4. I've only used a few styles, what's the consequence of only using a few, are there any dependencies on styles.
    5. 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.


    Thanks for any constructive response =)

    Cheers
Working...
X