Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Transfer of dynamic string array between parent and child dialog

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

  • Transfer of dynamic string array between parent and child dialog

    ' transfer of dynamic string array between parent and child dialog
    '
    ' using such a transfer, the array needs not be global.
    '
    ' version 1
    '
    ' allows no change to be made to the array. useful to just provide the
    ' array to the child dialog. an indexed string pointer is applied to
    ' provide access to the array data in the child dialog.
    '
    ' erik christensen -------- december 27, 2006
    '
    ' please post comments here:
    ' http://www.powerbasic.com/support/pb...ad.php?t=13845
    '
    ' if you have better solutions, i would like to know.
    '
    ' p.s. here are some links on related issues:
    ' http://www.powerbasic.com/support/pb...ad.php?t=24947
    ' http://www.powerbasic.com/support/pb...ad.php?t=13169
    ' http://www.powerbasic.com/support/pb...ad.php?t=13096
    Code:
    #compile exe
    #dim all
    '
    #include "win32api.inc"
    '
    %idd_dialog1                     =  101
    %idc_button2                     = 1003
    %idc_button3                     = 1004
    %idc_button4                     = 1006
    %idc_textbox1                    = 1007
    %idc_textbox2                    = 1008
    '
    type transfer
        sptr as string pointer
        low as long
        up as long
    end type
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    callback function showchilddialogproc()
        static trp as transfer pointer
        static tr as transfer ' this must be static
        trp = varptr(tr)
        local x as long
        static t as string
        '
        select case as long cbmsg
            case %wm_initdialog             ' initialization handler
                '
                ' get data information from parent dialog
                dialog get user cbhndl, 1 to trp
                tr = @trp
                '
                ' an indexed pointer is used to access the elements of the dynamic string arrays
                t="original array:" + $crlf
                for x = tr.low to tr.up
                    t = t + tr.@sptr[x] + "   "
                next x
                control set text cbhndl, %idc_textbox2, t
                '
            case %wm_command
                ' process control notifications
                select case as long cbctl
                    case %idc_button4 ' finished
                        if cbctlmsg = %bn_clicked or cbctlmsg = 1 then
                            dialog end cbhndl
                        end if
                end select
        end select
    end function
    '
    function showchilddialog(byval hparent as dword, byref z() as string) as long
        local hdlg  as dword
        local x as long
        local trp as transfer pointer
        local tr as transfer
        trp = varptr(tr)
        tr.low = lbound(z) : tr.up = ubound(z)
        tr.sptr = varptr(z(tr.low)) ' pointer to string array referred from parent dialog
        '
        dialog new pixels, hparent, "child dialog", , , 554, 250, to hdlg
        '
        dialog set user hdlg, 1, varptr(tr) ' transfer data to user data area so that it can be obtained by the child dialog
        '
        control add textbox, hdlg, %idc_textbox2, ", 10, 10, 530, 200, %es_multiline or %ws_vscroll, %ws_ex_clientedge
        control add button,  hdlg, %idc_button4, "&finished", 300, 220, 150, 24
        '
        dialog show modal hdlg, call showchilddialogproc
        '
    end function
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    callback function showparentdialogproc()
        dim z(0 to 8) as static string
        static low as long, up as long
        static x as long
        static t as string
        '
        select case as long cbmsg
            case %wm_initdialog
                ' make array
                t = "
                low = lbound(z) : up = ubound(z)
                for x = low to up
                    z(x) = str$(x*8)
                    t = t+ z(x)+"   "
                next x
                t = "original array:" + $crlf + t
                control set text cbhndl, %idc_textbox1, t
            case %wm_command
                ' process control notifications
                select case as long cbctl
                    case %idc_button2 ' transfer data to child dialog
                        if cbctlmsg = %bn_clicked or cbctlmsg = 1 then
                            '
                            showchilddialog(cbhndl, z()) ' show z array data in child dialog
                            '
                        end if
    
                    case %idc_button3 ' end program
                        if cbctlmsg = %bn_clicked or cbctlmsg = 1 then dialog end cbhndl
                end select
        end select
    end function
    '
    function showparentdialog(byval hparent as dword) as long
        local lrslt  as long
        local hdlg   as dword
        dialog new pixels, hparent, "parent dialog ", 140, 90, 726, 530, _
            %ws_popup or %ws_border or %ws_dlgframe or %ws_sysmenu or _
            %ws_clipsiblings or %ws_visible or %ds_modalframe or %ds_3dlook or _
            %ds_nofailcreate or %ds_setfont, %ws_ex_controlparent or %ws_ex_left _
            or %ws_ex_ltrreading or %ws_ex_rightscrollbar, to hdlg
        control add textbox, hdlg, %idc_textbox1, ", 10, 10, 700, 430, %es_multiline or %ws_vscroll, %ws_ex_clientedge
        control add button,  hdlg, %idc_button2, "&transfer array data", 300, 488, 250, 24
        control add button,  hdlg, %idc_button3, "e&xit", 586, 488, 126, 24
        dialog show modal hdlg, call showparentdialogproc to lrslt
        function = lrslt
    end function
    '
    function pbmain()
        showparentdialog %hwnd_desktop
    end function
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    ------------------




    [this message has been edited by erik christensen (edited december 28, 2006).]

  • #2
    ' Transfer of dynamic string array between parent and child dialog
    '
    ' Using such a transfer, the array needs not be global.
    '
    ' Version 2
    '
    ' Allows array to be changed in the dialog. An indexed string pointer
    ' is applied to provide a copy of the array in the child dialog.
    '
    ' Erik Christensen -------- December 27, 2006
    Code:
    #COMPILE EXE
    #DIM ALL
    '
    #INCLUDE "WIN32API.INC"
    '
    %IDD_DIALOG1                     =  101
    %IDC_BUTTON1                     = 1002
    %IDC_BUTTON2                     = 1003
    %IDC_BUTTON3                     = 1004
    %IDC_BUTTON4                     = 1006
    %IDC_TEXTBOX1                    = 1007
    %IDC_TEXTBOX2                    = 1008
    '
    TYPE Transfer
        sPtr AS STRING POINTER
        low AS LONG
        up AS LONG
    END TYPE
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowChildDialogProc()
        STATIC trP AS Transfer POINTER
        STATIC tr AS Transfer ' this must be static
        trP = VARPTR(tr)
        LOCAL x AS LONG
        STATIC t AS STRING
        '
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG             ' Initialization handler
                '
                ' get data information from parent dialog
                DIALOG GET USER CBHNDL, 1 TO trP
                tr = @trP
                '
                ' dimension array for child dialog
                DIM z2(tr.low TO tr.up) AS STATIC STRING
                '
                ' Copy original array to child dialog array
                ' An Indexed pointer is used to access the elements of the dynamic string arrays
                t="Original array:" + $CRLF
                FOR x = tr.low TO tr.up
                    z2(x) = tr.@sPtr[x] : t = t + z2(x) + "   "
                NEXT x
                CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX2, t
                '
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_BUTTON1 ' modify array
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            t = t + $CRLF + "Modified array:" + $CRLF '+ $CRLF
                            FOR x = tr.low TO tr.up
                                z2(x) = z2(x) + STR$(x) : t = t + z2(x) + "   "
                            NEXT x
                            INCR tr.up ' If you use REDIM PRESERVED you can only increase or
                                        ' decrease the upper bound of the array, NOT the lower
                            REDIM PRESERVE z2(tr.low TO tr.up)
                                         ' If you need to change also the lower bound of the array
                                         ' you can use just REDIM, but you must then take provissions
                                         ' to update the whole array.
                            z2(tr.up) = "extra up" : t = t + z2(tr.up)
                            tr.sPtr = VARPTR(z2(tr.low))
                            CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX2, t
                        END IF
                    CASE %IDC_BUTTON4 ' finished
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            DIALOG END CBHNDL, trP ' transfer array information pointer trP back to ShowChildDialog
                        END IF
                END SELECT
        END SELECT
    END FUNCTION
    '
    FUNCTION ShowChildDialog(BYVAL hParent AS DWORD, BYREF z() AS STRING) AS LONG
        LOCAL hDlg  AS DWORD
        LOCAL x AS LONG
        LOCAL trP AS Transfer POINTER
        LOCAL tr AS Transfer
        trP = VARPTR(tr)
        tr.low = LBOUND(z) : tr.up = UBOUND(z)
        tr.sPtr = VARPTR(z(tr.low)) ' pointer to string array referred from parent dialog
        '
        DIALOG NEW PIXELS, hParent, "Child Dialog", , , 554, 250, TO hDlg
        '
        DIALOG SET USER hDlg, 1, VARPTR(tr) ' transfer data to user data area so that it can be obtained by the child dialog
        '
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 10, 10, 530, 200, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1, "&Modify data", 100, 220, 150, 24
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON4, "&Finished", 300, 220, 150, 24
        '
        DIALOG SHOW MODAL hDlg, CALL ShowChildDialogProc TO trP
        '
        ' now trP holds the pointer to changed transfer information from the child dialog
        tr = @trP ' now tr holds updated information about the z array from the child dialog
        '
        ' update z array referred from the parent dialog with new data from child dialog
        REDIM z(tr.low TO tr.up)
        FOR x = tr.low TO tr.up
            z(x) = tr.@sPtr[x]
        NEXT
        '
        FUNCTION = trP
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowParentDialogProc()
        DIM z(0 TO 8) AS STATIC STRING
        STATIC low AS LONG, up AS LONG
        STATIC x AS LONG
        STATIC t AS STRING
        '
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' make array
                t = ""
                low = LBOUND(z) : up = UBOUND(z)
                FOR x = low TO up
                    z(x) = STR$(x*8)
                    t = t+ z(x)+"   "
                NEXT x
                t = "Original array:" + $CRLF + t
                CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, t
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_BUTTON2 ' Transfer data to child dialog
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            '
                            ShowChildDialog(CBHNDL, z()) ' show child dialog for changing z array
                            '
                            t = t + $CRLF + $CRLF+"Modified array returned from child dialog:" + $CRLF
                            '
                            low = LBOUND(z) : up = UBOUND(z)
                            FOR x = low TO up
                                t = t + z(x) + "   "
                            NEXT x
                            CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, t
                        END IF
    
                    CASE %IDC_BUTTON3 ' end program
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN DIALOG END CBHNDL
                END SELECT
        END SELECT
    END FUNCTION
    '
    FUNCTION ShowParentDialog(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt  AS LONG
        LOCAL hDlg   AS DWORD
        DIALOG NEW PIXELS, hParent, "Parent Dialog ", 140, 90, 726, 530, _
            %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _
            %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
            %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
            OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 10, 10, 700, 430, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON2, "&Transfer array data", 300, 488, 250, 24
        CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON3, "E&xit", 586, 488, 126, 24
        DIALOG SHOW MODAL hDlg, CALL ShowParentDialogProc TO lRslt
        FUNCTION = lRslt
    END FUNCTION
    '
    FUNCTION PBMAIN()
        ShowParentDialog %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    ------------------




    [This message has been edited by Erik Christensen (edited December 28, 2006).]

    Comment


    • #3
      ' Transfer of dynamic string array between parent and child dialog
      '
      ' Using such a transfer, the array needs not be global.
      '
      ' Version 3
      '
      ' Allows array to be changed in the dialog. This version uses PARSE and JOIN$,
      ' which are extremely fast built-in PB routines. The transfer between dialogs
      ' is made using a pointer structure.
      '
      ' Erik Christensen -------- December 27, 2006
      Code:
      #COMPILE EXE
      #DIM ALL
      '
      #INCLUDE "WIN32API.INC"
      '
      %IDD_DIALOG1                     =  101
      %IDC_BUTTON1                     = 1002
      %IDC_BUTTON2                     = 1003
      %IDC_BUTTON3                     = 1004
      %IDC_BUTTON4                     = 1006
      %IDC_TEXTBOX1                    = 1007
      %IDC_TEXTBOX2                    = 1008
      '
      TYPE Transfer
          sPtr AS STRING POINTER
          low AS LONG
          up AS LONG
      END TYPE
      '------------------------------------------------------------------------------
      '------------------------------------------------------------------------------
      '------------------------------------------------------------------------------
      CALLBACK FUNCTION ShowChildDialogProc()
          STATIC trP AS Transfer POINTER
          STATIC tr AS Transfer ' this must be static
          trP = VARPTR(tr)
          STATIC s AS STRING    ' this must be static
          tr.sPtr = VARPTR(s)
          LOCAL x AS LONG
          STATIC t AS STRING
          '
          SELECT CASE AS LONG CBMSG
              CASE %WM_INITDIALOG             ' Initialization handler
                  '
                  ' get data information from parent dialog
                  DIALOG GET USER CBHNDL, 1 TO trP
                  tr = @trP
                  '
                  ' dimension array for child dialog
                  DIM z2(tr.low TO tr.up) AS STATIC STRING
                  '
                  ' Copy original array to child dialog array
                  ' An Indexed pointer is used to access the elements of the dynamic string arrays
                  t="Original array:" + $CRLF
                  PARSE tr.@sPtr, z2(), $TAB
                  FOR x = tr.low TO tr.up
                      t = t + z2(x) + "   "
                  NEXT x
                  CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX2, t
                  '
              CASE %WM_COMMAND
                  ' Process control notifications
                  SELECT CASE AS LONG CBCTL
                      CASE %IDC_BUTTON1 ' modify array
                          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              t = t + $CRLF + "Modified array:" + $CRLF '+ $CRLF
                              FOR x = tr.low TO tr.up
                                  z2(x) = z2(x) + STR$(x) : t = t + z2(x) + "   "
                              NEXT x
                              INCR tr.up ' If you use REDIM PRESERVED you can only increase or
                                          ' decrease the upper bound of the array, NOT the lower
                              REDIM PRESERVE z2(tr.low TO tr.up)
                                           ' If you need to change also the lower bound of the array
                                           ' you can use just REDIM, but you must then take provissions
                                           ' to update the whole array.
                              z2(tr.up) = "extra up" : t = t + z2(tr.up)
      
                              s = JOIN$(z2(), $TAB) : tr.sPtr = VARPTR(s)
                              CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX2, t
                          END IF
                      CASE %IDC_BUTTON4 ' finished
                          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              DIALOG END CBHNDL, trP ' transfer array information pointer trP back to ShowChildDialog
                          END IF
                  END SELECT
          END SELECT
      END FUNCTION
      '
      FUNCTION ShowChildDialog(BYVAL hParent AS DWORD, BYREF z() AS STRING) AS LONG
          LOCAL hDlg  AS DWORD
          LOCAL x AS LONG
          LOCAL trP AS Transfer POINTER
          LOCAL tr AS Transfer
          LOCAL s AS STRING
          s = JOIN$(z(), $TAB) ' transform array referred from parent dialog to a long string
          trP = VARPTR(tr)
          tr.low = LBOUND(z) : tr.up = UBOUND(z)
          tr.sPtr = VARPTR(s) ' pointer to long "array" string
          '
          DIALOG NEW PIXELS, hParent, "Child Dialog", , , 554, 250, TO hDlg
          '
          DIALOG SET USER hDlg, 1, VARPTR(tr) ' transfer pointer data so that it can be obtained by the child dialog
          '
          CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 10, 10, 530, 200, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
          CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1, "&Modify data", 100, 220, 150, 24
          CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON4, "&Finished", 300, 220, 150, 24
          '
          DIALOG SHOW MODAL hDlg, CALL ShowChildDialogProc TO trP
          '
          ' now trP holds the pointer to changed transfer information from the child dialog
          tr = @trP ' now tr holds updated information about the z array from the child dialog
          '
          ' update z array referred from the parent dialog with new data from child dialog
          REDIM z(tr.low TO tr.up)
          PARSE tr.@sPtr, z(), $TAB
          '
          FUNCTION = trP
      END FUNCTION
      '------------------------------------------------------------------------------
      '------------------------------------------------------------------------------
      '------------------------------------------------------------------------------
      CALLBACK FUNCTION ShowParentDialogProc()
          DIM z(0 TO 8) AS STATIC STRING
          STATIC low AS LONG, up AS LONG
          STATIC x AS LONG
          STATIC t AS STRING
          '
          SELECT CASE AS LONG CBMSG
              CASE %WM_INITDIALOG
                  ' make array
                  t = ""
                  low = LBOUND(z) : up = UBOUND(z)
                  FOR x = low TO up
                      z(x) = STR$(x*8)
                      t = t+ z(x)+"   "
                  NEXT x
                  t = "Original array:" + $CRLF + t
                  CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, t
              CASE %WM_COMMAND
                  ' Process control notifications
                  SELECT CASE AS LONG CBCTL
                      CASE %IDC_BUTTON2 ' Transfer data to child dialog
                          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              '
                              ShowChildDialog(CBHNDL, z()) ' show child dialog for changing z array
                              '
                              t = t + $CRLF + $CRLF+"Modified array returned from child dialog:" + $CRLF
                              '
                              low = LBOUND(z) : up = UBOUND(z)
                              FOR x = low TO up
                                  t = t + z(x) + "   "
                              NEXT x
                              CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, t
                          END IF
      
                      CASE %IDC_BUTTON3 ' end program
                          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN DIALOG END CBHNDL
                  END SELECT
          END SELECT
      END FUNCTION
      '
      FUNCTION ShowParentDialog(BYVAL hParent AS DWORD) AS LONG
          LOCAL lRslt  AS LONG
          LOCAL hDlg   AS DWORD
          DIALOG NEW PIXELS, hParent, "Parent Dialog ", 140, 90, 726, 530, _
              %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _
              %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
              %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
              OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
          CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 10, 10, 700, 430, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
          CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON2, "&Transfer array data", 300, 488, 250, 24
          CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON3, "E&xit", 586, 488, 126, 24
          DIALOG SHOW MODAL hDlg, CALL ShowParentDialogProc TO lRslt
          FUNCTION = lRslt
      END FUNCTION
      '
      FUNCTION PBMAIN()
          ShowParentDialog %HWND_DESKTOP
      END FUNCTION
      '------------------------------------------------------------------------------
      '------------------------------------------------------------------------------
      '------------------------------------------------------------------------------
      ------------------




      [This message has been edited by Erik Christensen (edited December 28, 2006).]

      Comment


      • #4
        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE "WIN32API.INC"
        %IDD_DIALOG1                     =  101
        %IDC_BUTTON2                     = 1003
        %IDC_BUTTON3                     = 1004
        %IDC_BUTTON4                     = 1006
        %IDC_TEXTBOX1                    = 1007
        %IDC_TEXTBOX2                    = 1008
        '
        ' ``````````````````````````````````````````````````
        '   array wrappers
        ' ``````````````````````````````````````````````````
        DECLARE FUNCTION PArryUBound( BYREF Arry() AS STRING ) AS LONG
        DECLARE SUB PArryReDimPresv( BYREF Arry() AS STRING, UpperBound AS LONG )
        DECLARE SUB PArrySet( BYREF Arry() AS STRING, AtHere AS LONG, ThisValue AS STRING )
        DECLARE FUNCTION PArryGet( BYREF Arry() AS STRING, AtHere AS LONG ) AS STRING
        ' ``````````````````````````````````````````````````
        GLOBAL gpArry AS STRING PTR
        ' ``````````````````````````````````````````````````
        CALLBACK FUNCTION ShowChildDialogProc()
            LOCAL i AS LONG
            LOCAL s AS STRING
            '
            SELECT CASE AS LONG CBMSG
                CASE %WM_INITDIALOG
                    'redim preserve
                    PArryReDimPresv BYVAL gpArry, 20
                    'add new data
                    FOR i=11 TO 20
                        PArrySet BYVAL gpArry, i, STR$(i)
                    NEXT i
                    s = ""
                    FOR i=1 TO PArryUBound(BYVAL gpArry)
                        s = s + PArryGet(BYVAL gpArry, i)
                    NEXT i
                    CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX2, s
                CASE %WM_COMMAND
                    SELECT CASE AS LONG CBCTL
                        CASE %IDC_BUTTON4 ' finished
                            IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                DIALOG END CBHNDL
                            END IF
                    END SELECT
            END SELECT
        END FUNCTION
        ' ``````````````````````````````````````````````````
        ' ``````````````````````````````````````````````````
        FUNCTION ShowChildDialog(BYVAL hParent AS DWORD) AS LONG
            LOCAL hDlg  AS DWORD
            DIALOG NEW PIXELS, hParent, "Child Dialog", , , 554, 250, TO hDlg
            CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 10, 10, 530, 200, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
            CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON4, "&Finished", 300, 220, 150, 24
            DIALOG SHOW MODAL hDlg, CALL ShowChildDialogProc
        END FUNCTION
        ' ``````````````````````````````````````````````````
        ' ``````````````````````````````````````````````````
        CALLBACK FUNCTION ShowParentDialogProc()
            STATIC arry() AS STRING
            LOCAL i AS LONG
            LOCAL s AS STRING
            '
            SELECT CASE AS LONG CBMSG
                CASE %WM_INITDIALOG
                    REDIM arry(1 TO 10)
                    s=""
                    FOR i=1 TO 10
                        s = s + STR$(i)
                        arry(i) = STR$(i)
                    NEXT i
                    s = "Original array:" + $CRLF + s
                    '''''''''''''''''
                    '   point to array
                    gpArry = VARPTR(arry())
                    '''''''''''''''''
                    CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, s
                CASE %WM_COMMAND
                    SELECT CASE AS LONG CBCTL
                        CASE %IDC_BUTTON2
                            IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                ShowChildDialog(CBHNDL)
                            END IF
                        CASE %IDC_BUTTON3
                            IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN DIALOG END CBHNDL
                    END SELECT
            END SELECT
        END FUNCTION
        '
        FUNCTION ShowParentDialog(BYVAL hParent AS DWORD) AS LONG
            LOCAL lRslt  AS LONG
            LOCAL hDlg   AS DWORD
            DIALOG NEW PIXELS, hParent, "Parent Dialog ", 140, 90, 726, 530, _
                %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _
                %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
            CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 10, 10, 700, 430, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
            CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON2, "&Transfer array data", 300, 488, 250, 24
            CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON3, "E&xit", 586, 488, 126, 24
            DIALOG SHOW MODAL hDlg, CALL ShowParentDialogProc TO lRslt
            FUNCTION = lRslt
        END FUNCTION
        '
        FUNCTION PBMAIN()
            ShowParentDialog %HWND_DESKTOP
        END FUNCTION
        ' ``````````````````````````````````````````````````
        ' ``````````````````````````````````````````````````
        FUNCTION PArryUBound( BYREF Arry() AS STRING ) AS LONG
            FUNCTION = UBOUND(Arry)
        END FUNCTION
        ' ``````````````````````````````````````````````````
        ' ``````````````````````````````````````````````````
        SUB PArryReDimPresv( BYREF Arry() AS STRING, UpperBound AS LONG )
            REDIM PRESERVE Arry(1 TO UpperBound)
        END SUB
        ' ``````````````````````````````````````````````````
        ' ``````````````````````````````````````````````````
        SUB PArrySet( BYREF Arry() AS STRING, AtHere AS LONG, ThisValue AS STRING )
            Arry(AtHere) = ThisValue
        END SUB
        ' ``````````````````````````````````````````````````
        ' ``````````````````````````````````````````````````
        FUNCTION PArryGet( BYREF Arry() AS STRING, AtHere AS LONG ) AS STRING
            FUNCTION = Arry(AtHere)
        END FUNCTION
        ' ``````````````````````````````````````````````````
        ------------------


        [This message has been edited by Stan Durham (edited December 27, 2006).]

        Comment


        • #5
          Code:
          #COMPILE EXE
          #DIM ALL
          #INCLUDE "WIN32API.INC"
          %IDD_DIALOG1                     =  101
          %IDC_BUTTON2                     = 1003
          %IDC_BUTTON3                     = 1004
          %IDC_BUTTON4                     = 1006
          %IDC_TEXTBOX1                    = 1007
          %IDC_TEXTBOX2                    = 1008
          ' ``````````````````````````````````````````````````
          '   send arrays in TwoArraysType TYPE vial DIALOG POST message
          '   every time Child Dialog shown, arrays are changed in Child
          '   change is reflected back in Main Dialog
          ' ``````````````````````````````````````````````````
          DECLARE FUNCTION PArryUBound( BYREF Arry() AS STRING ) AS LONG
          DECLARE SUB PArryReDimPresv( BYREF Arry() AS STRING, UpperBound AS LONG )
          DECLARE SUB PArrySet( BYREF Arry() AS STRING, AtHere AS LONG, ThisValue AS STRING )
          DECLARE FUNCTION PArryGet( BYREF Arry() AS STRING, AtHere AS LONG ) AS STRING
          ' ``````````````````````````````````````````````````
          %MSG_CHANGE_AND_DISPLAY_ARRAYS = %WM_USER + 501
          ' ``````````````````````````````````````````````````
          TYPE TwoArraysType
              psString AS STRING PTR
              psaOne AS STRING PTR
              psaTwo AS STRING PTR
          END TYPE
          ' ``````````````````````````````````````````````````
          GLOBAL ghDlgChild AS LONG
          ' ``````````````````````````````````````````````````
          CALLBACK FUNCTION ShowChildDialogProc()
              LOCAL pt AS TwoArraysType PTR
              LOCAL i AS LONG
              LOCAL s AS STRING
              '
              SELECT CASE AS LONG CBMSG
                  CASE %WM_INITDIALOG
                  CASE %MSG_CHANGE_AND_DISPLAY_ARRAYS
                      'get pointer to TwoArraysType from message
                      pt = CBWPARAM
                      '   change arrays and string passed via message
                      @pt.@psString = @pt.@psString + " Changed Arrays " + $CRLF
                      s = @pt.@psString
                      FOR i=1 TO PArryUBound(BYVAL @pt.psaOne)
                          PArrySet BYVAL @pt.psaOne, i, "Changed "+PArryGet(BYVAL @pt.psaOne,i)
                          PArrySet BYVAL @pt.psaTwo, i, "Changed "+PArryGet(BYVAL @pt.psaTwo,i)
                          s = s + PArryGet(BYVAL @pt.psaOne,i) + $TAB + PArryGet(BYVAL @pt.psaTwo,i) + $CRLF
                      NEXT i
                      CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX2, s
                  CASE %WM_COMMAND
                      SELECT CASE AS LONG CBCTL
                          CASE %IDC_BUTTON4 ' finished
                              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                  DIALOG END CBHNDL
                              END IF
                      END SELECT
              END SELECT
          END FUNCTION
          ' ``````````````````````````````````````````````````
          ' ``````````````````````````````````````````````````
          FUNCTION ShowChildDialog(BYVAL hParent AS DWORD) AS LONG
              LOCAL hDlg  AS DWORD
              DIALOG NEW PIXELS, hParent, "Child Dialog", , , 554, 250, TO hDlg
              CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 10, 10, 530, 200, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
              CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON4, "&Finished", 300, 220, 150, 24
              ghDlgChild = hDlg
              DIALOG SHOW MODELESS hDlg, CALL ShowChildDialogProc
          END FUNCTION
          ' ``````````````````````````````````````````````````
          ' ``````````````````````````````````````````````````
          CALLBACK FUNCTION ShowParentDialogProc()
              STATIC arry1() AS STRING
              STATIC arry2() AS STRING
              STATIC sStored AS STRING
              STATIC t AS TwoArraysType
              LOCAL i AS LONG
              LOCAL s AS STRING
              '
              SELECT CASE AS LONG CBMSG
                  CASE %WM_INITDIALOG
                      '''''''''''''''''
                      '   store data
                      t.psaOne = VARPTR(arry1())
                      t.psaTwo = VARPTR(arry2())
                      t.psString = VARPTR(sStored)
                      '''''''''''''''''
                      t.@psString = "Transfer arrays in message..." + $CRLF
                      REDIM arry1(1 TO 10)
                      REDIM arry2(1 TO 10)
                      s=""
                      FOR i=1 TO 10
                          arry1(i) = "One="+STR$(i)
                          arry2(i) = "Two="+STR$(i)
                          s = s + arry1(i) + $TAB + arry2(i) + $CRLF
                      NEXT i
                      CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, t.@psString + s
                  CASE %WM_COMMAND
                      SELECT CASE AS LONG CBCTL
                          CASE %IDC_BUTTON2
                              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                  ShowChildDialog(CBHNDL)
                                  FOR i=1 TO 10
                                      DIALOG DOEVENTS
                                  NEXT i
                                  'send message
                                  DIALOG SEND ghDlgChild, %MSG_CHANGE_AND_DISPLAY_ARRAYS, VARPTR(t), 0
                                  FOR i=1 TO 10
                                      DIALOG DOEVENTS
                                  NEXT i
                                  'display current array values
                                  s = t.@psString
                                  FOR i=1 TO PArryUBound(BYVAL t.psaOne)
                                      PArrySet BYVAL t.psaOne, i, "Changed "+PArryGet(BYVAL t.psaOne,i)
                                      PArrySet BYVAL t.psaTwo, i, "Changed "+PArryGet(BYVAL t.psaTwo,i)
                                      s = s + PArryGet(BYVAL t.psaOne,i) + $TAB + PArryGet(BYVAL t.psaTwo,i) + $CRLF
                                  NEXT i
                                  CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, s
                              END IF
                          CASE %IDC_BUTTON3
                              IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN DIALOG END CBHNDL
                      END SELECT
              END SELECT
          END FUNCTION
          '
          FUNCTION ShowParentDialog(BYVAL hParent AS DWORD) AS LONG
              LOCAL lRslt  AS LONG
              LOCAL hDlg   AS DWORD
              DIALOG NEW PIXELS, hParent, "Parent Dialog ", 140, 90, 726, 530, _
                  %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _
                  %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                  %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                  OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
              CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 10, 10, 700, 430, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
              CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON2, "&Transfer array data", 300, 488, 250, 24
              CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON3, "E&xit", 586, 488, 126, 24
              DIALOG SHOW MODAL hDlg, CALL ShowParentDialogProc TO lRslt
              FUNCTION = lRslt
          END FUNCTION
          '
          FUNCTION PBMAIN()
              ShowParentDialog %HWND_DESKTOP
          END FUNCTION
          ' ``````````````````````````````````````````````````
          ' ``````````````````````````````````````````````````
          FUNCTION PArryUBound( BYREF Arry() AS STRING ) AS LONG
              FUNCTION = UBOUND(Arry)
          END FUNCTION
          ' ``````````````````````````````````````````````````
          ' ``````````````````````````````````````````````````
          SUB PArryReDimPresv( BYREF Arry() AS STRING, UpperBound AS LONG )
              REDIM PRESERVE Arry(1 TO UpperBound)
          END SUB
          ' ``````````````````````````````````````````````````
          ' ``````````````````````````````````````````````````
          SUB PArrySet( BYREF Arry() AS STRING, AtHere AS LONG, ThisValue AS STRING )
              Arry(AtHere) = ThisValue
          END SUB
          ' ``````````````````````````````````````````````````
          ' ``````````````````````````````````````````````````
          FUNCTION PArryGet( BYREF Arry() AS STRING, AtHere AS LONG ) AS STRING
              FUNCTION = Arry(AtHere)
          END FUNCTION
          ' ``````````````````````````````````````````````````

          ------------------

          Comment


          • #6
            Code:
            ' Transfer of dynamic string array between parent and child dialog
            '
            ' Using such a transfer, the array needs not be global.
            '
            ' Version 1 modified to allow editing
            '
            #COMPILE EXE
            #DIM ALL
            '
            #INCLUDE "WIN32API.INC"
            '
            %IDD_DIALOG1                     =  101
            %IDC_BUTTON2                     = 1003
            %IDC_BUTTON3                     = 1004
            %IDC_BUTTON4                     = 1006
            %IDC_TEXTBOX1                    = 1007
            %IDC_TEXTBOX2                    = 1008
            %MSG_DISPLAY_ARRAY = %WM_USER + 501
            '
            TYPE Transfer
                pFirst AS STRING PTR
                LB AS LONG
                UB AS LONG
            END TYPE
            '------------------------------------------------------------------------------
            '------------------------------------------------------------------------------
            '------------------------------------------------------------------------------
            CALLBACK FUNCTION ShowChildDialogProc()
                STATIC trP AS Transfer POINTER
                LOCAL x AS LONG
                STATIC t AS STRING
                '
                SELECT CASE AS LONG CBMSG
                    CASE %WM_INITDIALOG             ' Initialization handler
                        '
                        ' get data information from parent dialog
                        DIALOG GET USER CBHNDL, 1 TO trP
                        t="Original array:" + $CRLF
                        FOR x=@trP.LB TO @trP.UB
                            @trP.@pFirst[x] = @trP.@pFirst[x] + "I Changed " + @trP.@pFirst[x] + "   "
                            t = t + @trP.@pFirst[x]
                        NEXT x
                        CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX2, t
                        '
                    CASE %WM_COMMAND
                        ' Process control notifications
                        SELECT CASE AS LONG CBCTL
                            CASE %IDC_BUTTON4 ' finished
                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                    DIALOG POST GetParent(CBHNDL), %MSG_DISPLAY_ARRAY, 0, 0
                                    DIALOG END CBHNDL
                                END IF
                        END SELECT
                END SELECT
            END FUNCTION
            '
            FUNCTION ShowChildDialog(BYVAL hParent AS DWORD, BYVAL pTransfer AS Transfer PTR ) AS LONG
                LOCAL hDlg  AS DWORD
                '
                DIALOG NEW PIXELS, hParent, "Child Dialog", , , 554, 250, TO hDlg
                '
                DIALOG SET USER hDlg, 1, pTransfer ' transfer data to user data area so that it can be obtained by the child dialog
                '
                CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 10, 10, 530, 200, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
                CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON4, "&Finished", 300, 220, 150, 24
                '
                DIALOG SHOW MODAL hDlg, CALL ShowChildDialogProc
                '
            END FUNCTION
            '------------------------------------------------------------------------------
            '------------------------------------------------------------------------------
            '------------------------------------------------------------------------------
            CALLBACK FUNCTION ShowParentDialogProc()
                STATIC saArry() AS STRING
                STATIC tTransfer AS Transfer
                STATIC x AS LONG
                STATIC t AS STRING
                '
                SELECT CASE AS LONG CBMSG
                    CASE %WM_INITDIALOG
                        ' make array
                        REDIM saArry(0 TO 8)
                        t = ""
                        FOR x=LBOUND(saArry) TO UBOUND(saArry)
                            saArry(x) = STR$(x*8)
                            t = t+ saArry(x)+"   "
                        NEXT x
                        t = "Original array:" + $CRLF + t
                        CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, t
                        '''''''''''''''''''''''''''''''''''''''''
                        tTransfer.LB = LBOUND(saArry)
                        tTransfer.UB = UBOUND(saArry)
                        tTransfer.pFirst = VARPTR( saArry(tTransfer.LB) )
                    CASE %WM_COMMAND
                        ' Process control notifications
                        SELECT CASE AS LONG CBCTL
                            CASE %IDC_BUTTON2 ' Transfer data to child dialog
                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                    ShowChildDialog(CBHNDL, VARPTR(tTransfer)) 'send pointer to child dialog
                                END IF
            
                            CASE %IDC_BUTTON3 ' end program
                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN DIALOG END CBHNDL
                        END SELECT
                    CASE %MSG_DISPLAY_ARRAY
                        t = ""
                        FOR x=0 TO UBOUND(saArry)
                            t = t + saArry(x)
                        NEXT x
                        CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX1, t
                END SELECT
            END FUNCTION
            '
            FUNCTION ShowParentDialog(BYVAL hParent AS DWORD) AS LONG
                LOCAL lRslt  AS LONG
                LOCAL hDlg   AS DWORD
                DIALOG NEW PIXELS, hParent, "Parent Dialog ", 140, 90, 726, 530, _
                    %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _
                    %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
                    %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                    OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 10, 10, 700, 430, %ES_MULTILINE OR %WS_VSCROLL, %WS_EX_CLIENTEDGE
                CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON2, "&Transfer array data", 300, 488, 250, 24
                CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON3, "E&xit", 586, 488, 126, 24
                DIALOG SHOW MODAL hDlg, CALL ShowParentDialogProc TO lRslt
                FUNCTION = lRslt
            END FUNCTION
            '
            FUNCTION PBMAIN()
                ShowParentDialog %HWND_DESKTOP
            END FUNCTION
            '------------------------------------------------------------------------------
            '------------------------------------------------------------------------------
            '------------------------------------------------------------------------------
            ------------------


            [This message has been edited by Stan Durham (edited December 31, 2006).]

            Comment

            Working...
            X