Announcement

Collapse
No announcement yet.

Demo FlexGrid using PB COM

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

  • Demo FlexGrid using PB COM

    Code:
    '
    '   Demo of Philippe Monteil's
    '   JA COM/PB 2.0 USING the Hierarchical FlexGrid
    '
    '   OCX used C:\WINDOWS\SYSTEM\MSHFLXGD.OCX
    '
    '   http://www.jazzagesoft.com 
    '
    '   You will have to contact Philippe via Email
    '   to receive his beta in order to have
    '   all you need to run this demo program
    '
    '   From Philippe's Post :
    '
    '   "SEND us an email AT [email protected] TO receive the
    '   NEW free AND full featured JA COM/PB 2.0 OpenBeta4"
    '
    '   Using his code generator, create a file "mshFlxGd.bas"
    '   from the MSHFLXGD.OCX to add to this project.
    '
    '   "JACOMPB.bas" and "JAOCX20.inc" are a part of JA COM
    '
    '   I have zero financial interest with Philippe.
    '   I did purchase JA COM/PB 1.0 and have followed
    '   the progress of this tool closely.
    '
    '   I often see post about tab's, grid's, etc..
    '   and most of us already own OCX's that we can use
    '   if we also have this tool. Hence the purpose of this
    '   code/demo.
    '
    '   I currently use the VideoSoft Tab, Awk and Elastic
    '   OCX's and a few others which I had purchased for VB.
    '   I have work in progress using the VideoSoft 7.0
    '   Hierarchical FlexGrid with ADO and the ADO Data Control
    '   with Access Databases.
    '
    '   I have experimented using the above with SQL-Server also.
    '
    '   Note that I have discovered that all OCX's are not "subject"
    '   to being used by the code generator. I don't know why.
    '   It may be because this is BETA or they may be hidden
    '   and not available.
    '
    '   I guess that all OCX's are not created equal :-))
    '
    '   Jim Huguley
    '   [email protected]
    '   feel free to email with questions
    '
    '----------------------------------------------------------------------------
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.inc"
    #INCLUDE "COMMCTRL.INC
    #INCLUDE "JACOMPB.bas"
    #INCLUDE "JAOCX20.inc"
    '----------------------------------------------------------------------------
    ' Please uncomment the following declaration to
    ' activate the IMSHFlexGrid interface.
    %Compile_mshFlxGdIMSHFlexGrid=1
    #INCLUDE "mshFlxGd.bas"
    '----------------------------------------------------------------------------
    %ID_TIMER  = 1
    %ID_STATUS = 2
    '----------------------------------------------------------------------------
    '----------------------------------------------------------------------------
    GLOBAL g_hDlg       AS LONG
    GLOBAL g_WithColor  AS LONG
    GLOBAL g_pGrid      AS DWORD
    '----------------------------------------------------------------------------
    '----------------------------------------------------------------------------
    ' PB Callback attached to the events fired by the Grid OCX events
    FUNCTION JAGridEventCallBack SDECL(BYVAL dwCookie AS DWORD,BYVAL hEvent AS DWORD,BYVAL dwCustData AS DWORD) AS DWORD
        '
        'These are the same events that you are use
        'to in VB.. Retrieving the parameter is
        'demonstrated below
        '
        LOCAL sTxt          AS STRING
        LOCAL var           AS VARIANT
        LOCAL szEventName   AS ASCIIZ * 256
        '
        ' Initialize the VARIANT local variable to receive the various
        ' parameter values
        '
        VariantInit var
        '
        JAGetEventName hEvent, szEventName, 256
        '
        SELECT CASE szEventName
        CASE "Click"
            'HRESULT Click()
            sTxt = "Click"
            CALL PrintStatus (sTxt)
        CASE "MouseMove"
            'HRESULT MouseMove( I2 BUTTON, _
            '                   I2 SHIFT,
            '                   OLE_XPOS_PIXELS x, _
            '                   OLE_YPOS_PIXELS y)
            LOCAL iBUTTON   AS INTEGER
            LOCAL iShift    AS INTEGER
            LOCAL x         AS LONG
            LOCAL y         AS LONG
            '
            'Retrieve the four parameters of the event
            '
            'First Parameter 0 (Zero Based)
            JAGetEventParameterValue hEvent, 0, var
            iButton = VAL(JAGetVariantTextContent(Var))
            '
            JAGetEventParameterValue hEvent, 1, var
            iShift = VAL(JAGetVariantTextContent(Var))
            '
            JAGetEventParameterValue hEvent, 2, var
            x = VAL(JAGetVariantTextContent(Var))
            '
            JAGetEventParameterValue hEvent, 3, var
            y = VAL(JAGetVariantTextContent(Var))
            '
            sTxt = "MouseMove - Button:" & STR$(iButton) & " iShift:" & STR$(iShift) & " x:" & STR$(x) & " y:" & STR$(y)
            CALL PrintStatus (sTxt)
        END SELECT
        VariantClear var
    END FUNCTION
    '----------------------------------------------------------------------------
    CALLBACK FUNCTION Dialog_Callback() AS LONG
    
        LOCAL lCol      AS LONG
        LOCAL lRow      AS LONG
        LOCAL lNumber   AS LONG
        LOCAL lCase     AS LONG
        LOCAL lfColor   AS LONG
        LOCAL lbColor   AS LONG
        LOCAL hString   AS DWORD
        LOCAL szTxt     AS ASCIIZ * 25
    
        SELECT CASE CBMSG
        CASE %WM_TIMER
            lNumber = INT((100000 * RND) + 1)
            szTxt = STR$(lNumber)
            hString = JAAllocString(szTxt)
            lRow = INT((50 * RND) + 1)
            '
            IF ISTRUE g_WithColor THEN
                lCase = INT((8 * RND))
                SELECT CASE lCase
                CASE 0
                    lfColor = %Black
                CASE 1
                    lfColor = %Blue
                CASE 2
                    lfColor = %Green
                CASE 3
                    lfColor = %Cyan
                CASE 4
                    lfColor = %Red
                CASE 5
                    lfColor = %Magenta
                CASE 6
                    lfColor = %Yellow
                CASE 7
                    lfColor = %White
                CASE ELSE
                    lfColor = %Gray
                END SELECT
                '
                lCase = INT((8 * RND))
                SELECT CASE lCase
                CASE 0
                    lbColor = %Black
                CASE 1
                    lbColor = %Blue
                CASE 2
                    lbColor = %Green
                CASE 3
                    lbColor = %Cyan
                CASE 4
                    lbColor = %Red
                CASE 5
                    lbColor = %Magenta
                CASE 6
                    lbColor = %Yellow
                CASE 7
                    lbColor = %White
                CASE ELSE
                    lbColor = %Gray
                END SELECT
                IF lbColor = lfColor THEN
                   lbColor = %Magenta
                   lfColor = %Yellow
                END IF
                IMSHFlexGrid_PutRow g_pGrid, lRow
                FOR lCol = 0 TO 14
                    IMSHFlexGrid_PutCol g_pGrid, lCol
                    IMSHFlexGrid_PutCellForeColor g_pGrid, lfColor
                    IMSHFlexGrid_PutCellBackColor g_pGrid, lbColor
                    IMSHFlexGrid_PutText g_pGrid, hString
                NEXT
    
            ELSE
                'Note this is faster
                IMSHFlexGrid_PutRow g_pGrid, lRow
                FOR lCol = 0 TO 14
                    IMSHFlexGrid_PutTextMatrix g_pGrid, lRow, lCol, hString
                NEXT
            END IF
            JAFreeString hString
        CASE %WM_INITDIALOG
            SetTimer  CBHNDL, %ID_TIMER, 100, BYVAL %NULL
        CASE %WM_SIZE
            'size Status Bar
            CONTROL SEND CBHNDL, %ID_STATUS, CBMSG , CBWPARAM , CBLPARAM
        CASE %WM_DESTROY
            KillTimer CBHNDL, %ID_TIMER
        END SELECT
    
    END FUNCTION
    '----------------------------------------------------------------------------
    '----------------------------------------------------------------------------
    FUNCTION PBMAIN () AS LONG
    
        #REGISTER NONE
    
        LOCAL hDlg      AS LONG
        LOCAL lLoop     AS LONG
        LOCAL result    AS LONG
        LOCAL x         AS LONG
        LOCAL y         AS LONG
        LOCAL xx        AS LONG
        LOCAL yy        AS LONG
        LOCAL Par0      AS LONG
        LOCAL hString   AS DWORD
        LOCAL szTxt     AS ASCIIZ * 512
    
        DIM sbParts(0)  AS LONG
    
        InitMSHIERARCHICALFLEXGRIDLIBGUIDs
        InitCommonControls
    
        DIALOG NEW 0, "Hello Grid",,, 330, 240, _
                      %WS_SYSMENU OR %WS_CAPTION OR _
                      %WS_THICKFRAME OR %WS_OVERLAPPEDWINDOW OR _
                      %WS_VISIBLE , 0 TO hDlg
        g_hDlg = hDlg
    
        'Add a status bar
        CONTROL ADD "msctls_statusbar32", hDlg, %ID_STATUS,"" ,0 , 0 , 0, 16, _
                      %WS_CHILD OR _
                      %WS_BORDER OR _
                      %WS_VISIBLE OR _
                      %SBS_SIZEGRIP
    
        sbParts(0) = -1
        CONTROL SEND hDlg, %ID_STATUS, %SB_SETPARTS,1, VARPTR(sbParts(0))
    
        ' Translate himetrics coordinates into pixels, as required by JACreateControl
        DIALOG UNITS hDlg, 10, 10 TO PIXELS x, y
        DIALOG UNITS hDlg, 310, 210 TO PIXELS xx, yy
    
        ' Assign the ambient properties of the dialogbox
        JASetAmbientFont hDlg, "Arial", 10, %JAFONT_BOLD, 700
        JASetAmbientBackColor hDlg, &HC0C0C0
    
        ' Create a new OCX in the hDlg dialogbox, given:
        JACreateControl hDlg,"mshFlexGrid", _
                        x, _
                        y, _
                        xx, _
                        yy, _
                        "ProgID:MSHierarchicalFlexGridLib.MSHFlexGrid", _
                        1, _
                        g_pGrid
    
        'This will resize the Grid to the Dialog
        'when resizing, max, min.. etc..
    
        JASetControlResizeStyle g_pGrid, %JAHANDLE_PUNK, _
                                %JARESIZESTYLE_X2RIGHT OR %JARESIZESTYLE_Y2BOTTOM
    
        ' Add 15 Cols
        Par0 = 15
        IMSHFlexGrid_PutCols g_pGrid, 0, Par0
    
        ' Add 50 Rows
        Par0 = 50
        IMSHFlexGrid_PutRows g_pGrid, Par0
    
        ' 1 Fixed Row ( for Column headers )
        Par0 = 1
        IMSHFlexGrid_PutFixedRows g_pGrid, Par0
    
        ' 0 Fixed Cols ( no Row headers )
        Par0 = 0
        IMSHFlexGrid_PutFixedCols g_pGrid, Par0
    
        ' Set to Row 0
        Par0 = 0
        IMSHFlexGrid_PutRow g_pGrid, Par0
    
        FOR lLoop = 0 TO 14
            'Center Data in Cols
            IMSHFlexGrid_PutColAlignment g_pGrid, lLoop, %AlignmentSettings_flexAlignCenterCenter
            IMSHFlexGrid_PutCol g_pGrid, lLoop
            szTxt = "Col-" & LTRIM$(STR$(lLoop))
            hString = JAAllocString(szTxt)
            IMSHFlexGrid_PutClip g_pGrid, hString
            JAFreeString hString
        NEXT
    
        ' Set to Row 1
        Par0 = 1
        IMSHFlexGrid_PutRow g_pGrid, Par0
    
        ' Set to Col 0
        Par0 = 0
        IMSHFlexGrid_PutCol g_pGrid, Par0
    
        'Set scroll to move with mouse
        IMSHFlexGrid_PutScrollTrack g_pGrid, -1%
    
        'Un-Rem for color demo
        g_WithColor = %TRUE
        JASubscribeEvents g_pGrid,CODEPTR(JAGridEventCallBack),1
    
        DIALOG SHOW MODAL hDlg, CALL Dialog_Callback TO result
    
        ' Release the COM interface
        IF g_pGrid THEN
            JAReleaseDispatch g_pGrid
        END IF
    
    END FUNCTION
    '----------------------------------------------------------------------------
    SUB PrintStatus (sTxt AS STRING)
        CONTROL SEND g_hDlg, %ID_STATUS, %SB_SETTEXT, 0, STRPTR(sTxt)
    END SUB
    '----------------------------------------------------------------------------
    -------------
    Jim..
    [email protected]
    Jim..

  • #2
    Jim,

    thanks for the upload, I will give it a try!

    <<' Note that I have discovered that all OCX's are <<not "subject"' to being used by the code generator. I don't <<know why.' It may be because this is BETA or they may be <<hidden' and not available.'' I guess that all OCX's are <<not created equal :-))
    You are right: JA COM/PB 2.0 only supports OCXs exposing
    their functionalities in the form of 'dual interfaces'
    which is now true for the vast majority of them. VB, VC++,
    Delphi will let you create such OCXs.

    COM dual interfaces are tables of pointers to the methods
    exposed by a component. Invoking such exposed functionalities
    only takes a function call and is therefore much faster than doing so through a SendMessage call as with the old style Windows standard/custom controls.

    Philippe


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

    Comment


    • #3
      Jim

      Do you have a version that works with the final JA COM/PB 2.0?

      Regards
      Peter



      ------------------
      [email protected]
      [email protected]
      www.dreammodel.dk

      Comment


      • #4
        Peter.....

        I'm not certain what you are asking. If you are having a particular
        problem would you be more specific. I have the original code,
        a complied .exe and as an owner of JA/COM I have all of the versions
        that I am aware of and the code compiles and works correctly, at
        least on my computer. I'm currently running Win2000 but may have
        developed this on Win98 or NT.


        ------------------
        Jim..
        [email protected]
        Jim..

        Comment


        • #5
          Jim,

          I had to add JAInitializePBClient. Thanks for the very nice code!

          Regards
          Peter

          ------------------
          [email protected]
          [email protected]
          www.dreammodel.dk

          Comment

          Working...
          X