Announcement

Collapse
No announcement yet.

DDT and GDImage

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

  • Patrice Terrier
    replied
    Chris,

    Thank you for taking the time to write these GDImage/DDT examples.

    ...

    Leave a comment:


  • Chris Boss
    replied
    Here is another version which is DDT code without any library support code so it can be compiled. It is as minimal amount of code it can be.
    This was not done with my Utility Designer, but was originally created using my freeware designer and then I removed all unnecessary code.
    I then hand coded what I needed for GDImage.

    The control is very easy to use.

    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL          '  This is helpful to prevent errors in coding
    #INCLUDE "win32api.inc"   ' Must come first before other include files !
    #INCLUDE  "c:\gdimagetest\gdimage.inc"
    '
    ' *************************************************************
    '              Application Constants and Declares
    ' *************************************************************
    %FORM1_GDIMAGE2           = 100
    %FORM1_GDIMAGE1           = 105
    %FORM1_BUTTON1            = 110
    ' --------------------------------------------------
    DECLARE SUB ShowDialog_Form1(BYVAL hParent&)
    DECLARE CALLBACK FUNCTION Form1_DLGPROC
    ' --------------------------------------------------
    ' ------------------------------------------------
    DECLARE CALLBACK FUNCTION CBF_FORM1_BUTTON1()
    '
    GLOBAL hForm1&
    '
    GLOBAL ImageFolder$
    '
    SUB GetAppPath()
         LOCAL P AS ASCIIZ*265, L&, F$
         L&=GetModuleFileName(BYVAL %NULL, P, 260)
         ImageFolder$=LEFT$(P,L&)
         L&=INSTR(-1, ImageFolder$,"\")
         ImageFolder$=LEFT$(P,L&-1)+"\graphics\"
    END SUB
    '
    FUNCTION PBMAIN
        LOCAL Count&
        GetAppPath
        RegisterGDImageClass
        ShowDialog_Form1 0
        DO
            DIALOG DOEVENTS TO Count&
        LOOP UNTIL Count&=0
    END FUNCTION
    '
    SUB ShowDialog_Form1(BYVAL hParent&)
        LOCAL Style&, ExStyle&, hCtrl&
        LOCAL N&, CT&        '  Variables used for Reading Data in Arrays for Listbox and Combobox
        '   hParent& = 0 if no parent Dialog
        Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER
        ExStyle& = 0
        DIALOG NEW hParent&, "Your Dialog", 0, 0,  448,  276, Style&, ExStyle& TO hForm1&
        ' Layer # 0
        CONTROL ADD "ZIMAGECTRL", hForm1&,  %FORM1_GDIMAGE2, ImageFolder$+"heart1.gif", 27, 194, 69, 52, _
            %WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP OR %SS_NOTIFY
        CONTROL HANDLE hForm1&, %FORM1_GDIMAGE2  TO hCtrl&
        ZI_SetProperty hCtrl&, %ZI_GradientTop, RGB(240,240,240)
        ZI_SetProperty hCtrl&, %ZI_GradientBottom, RGB(240,240,240)
        ZI_SetAnchorMode hCtrl&, %ANCHOR_BOTTOM
         '
        CONTROL ADD "ZIMAGECTRL", hForm1&,  %FORM1_GDIMAGE1, ImageFolder$+"image.jpg", 141, 25, 283, 224, _
            %WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP OR %SS_NOTIFY
        CONTROL HANDLE hForm1&, %FORM1_GDIMAGE1  TO hCtrl&
        ZI_SetAnchorMode hCtrl&, %ANCHOR_HEIGHT_WIDTH
        '
        hCtrl& = zClockCtrl(hForm1,ImageFolder$+"SmallClock.png", 10,10, 0, 0, %FORM1_GDIMAGE2+1, ZD_ColorARGB(255, RGB(25,48,4)), ZD_ColorARGB(255, RGB(192,0,0)))
        '
        CONTROL ADD "Button", hForm1&,  %FORM1_BUTTON1,  "Select new Image", 19, 116, 96, 30, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_FORM1_BUTTON1
        DIALOG SHOW MODELESS hForm1& , CALL Form1_DLGPROC
    END SUB
    '
    CALLBACK FUNCTION Form1_DLGPROC
        SELECT CASE CBMSG
            CASE ELSE
        END SELECT
    END FUNCTION
    '
    CALLBACK FUNCTION CBF_FORM1_BUTTON1
        IF CBCTLMSG=%BN_CLICKED THEN
             LOCAL F$, hCtrl&
             CONTROL HANDLE hForm1&, %FORM1_GDIMAGE1 TO hCtrl&
             ZI_SetSaveDialogMsg "Select picture", "Save picture", "GDImage"
             F$ = ZI_LoadDialog(hForm1)
             IF F$<>"" THEN ZI_SetFromFile hCtrl&, (F$)
        END IF
    END FUNCTION
    The application is 26 KB in size.
    Last edited by Chris Boss; 29 May 2008, 03:02 PM.

    Leave a comment:


  • Chris Boss
    started a topic DDT and GDImage

    DDT and GDImage

    I was intrigued by Patrices GDImage demo, so I decided to try my hand using my EZGUI utility dialog designer to recreate the demo using GDImage. I am impressed with GDImage and my designer supports using it visually.

    Here is a screenshot:




    The clock works, the heart animations works and the select image dialog works. I didn't have time to tweak it as far as proportions or adding a manifest though.

    The compiled EXE is 39 KB in size.

    Here is the source code (does not include the dialog designers library code include file):

    Code:
    ' *************************************************************************************
    '             Code Generated by EZGUI Utility Dialog Designer 4.010
    '             Portions: Copyright Christopher R. Boss, 2003 to 2008
    '                              All Rights Reserved !
    ' Registered EZGUI Utility Dialog Designer 4.010 users may use this code Royalty Free !
    ' *************************************************************************************
    '
    ' --------------------------------------------------------
    ' WARNING ! Do Not Modify any code WITHIN Protected Sections !
    ' You can add code (Sub,Function,etc.) BEFORE any Protected Routine
    ' by using the following CODE TAGS:        '<<SAVE>>      '<<END>>
    ' and the Designer will not remove it.
    ' --------------------------------------------------------
    '
    ' ======================================
    ' [PROTECTED CODE]         Do NOT Edit !
    ' ======================================
    
    '
    #COMPILE EXE
    #DIM ALL        '   This is helpful to prevent errors in coding
    ' ---------------------
    %EZLIB_UseFonts    = 0
    %EZLIB_UseColors   = 0
    %EZLIB_UseRegions  = 0
    %EZLIB_UseNotify   = 0
    %EZLIB_UseScroll   = 0
    %EZLIB_UseLoading  = 1
    %EZLIB_UseAdjust   = 0
    %EZLIB_UserEvents  = 0
    ' ---------------------
    ' --------------------
    DECLARE SUB EZ_AppCleanUp()
    #INCLUDE "C:\ezgui40dlg\includes\ezlib4ut.inc"
    ' --------------------
    #RESOURCE ".\rcdata\gdimage.pbr"
    #INCLUDE  "c:\gdimagetest\gdimage.inc"
    ' *************************************************************************************
     
    ' *************************************************************************************
    '                   Code Generator Defined Constants and Declares
    ' *************************************************************************************
    DECLARE FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG
    DECLARE FUNCTION PreProcess_Events(BYVAL FormName$, BYVAL hDlg&, BYVAL CID&, CMsg&, CVal&, Cancel&) AS LONG
    DECLARE SUB EZ_FORM1_Display(BYVAL hParent&)
    DECLARE SUB EZ_FORM1_Design(BYVAL hDlg&)
    DECLARE SUB EZ_FORM1_ParseEvents(BYVAL hDlg&, BYVAL CID&, CMsg&, CVal&, Cancel&)
    DECLARE SUB FORM1_Events(BYVAL hDlg&, BYVAL CID&, CMsg&, CVal&, Cancel&)
    ' ------------------------------------------------
    %FORM1_GDIMAGE2           = 100
    %FORM1_PLACEHOLDER        = 105
    %FORM1_BUTTON1            = 110
    %FORM1_GDIMAGE1           = 115
    DECLARE CALLBACK FUNCTION FORM1_DlgProc
    DECLARE SUB FORM1_GDIMAGE2_Events(MyID&, CMsg&, CVal&, Cancel&)
    DECLARE SUB FORM1_PLACEHOLDER_Events(MyID&, CMsg&, CVal&, Cancel&)
    DECLARE SUB FORM1_BUTTON1_Events(MyID&, CMsg&, CVal&, Cancel&)
    DECLARE SUB FORM1_GDIMAGE1_Events(MyID&, CMsg&, CVal&, Cancel&)
     
    ' *************************************************************************************
    '                 Code Generator Defined Global Variables and Types
    ' *************************************************************************************
    ' --- Form: FORM1 ---
    GLOBAL hFORM1 AS LONG     ' Dialog Handle
     
    ' --------------------
    %EZDlgStdVersion   =  4010
    DECLARE SUB EZ_Main(BYVAL VerNum&)
    #INCLUDE "C:\ezgui40dlg\includes\dlgmain.inc"                          ' Include file for PBMain code
    ' --------------------
     
    ' *************************************************************************************
    '                       User Defined Global Variables and Types
    '         (Put code in CODE TAGS! to protect from deletion by Code Generator !)
    ' *************************************************************************************
    SUB EZ_Main(BYVAL VerNum&)     ' (PROTECTED)
         DIALOG FONT "SYSTEM", 10
         EZ_DefImageFolder "Graphics"
         RegisterGDImageClass
         IF Main_Initialize(VerNum&) THEN
              EZ_FORM1_Display 0
         END IF
    END SUB
    
    ' ======================================
    ' [USER ACCESSABLE CODE]  You may Edit !
    ' ======================================
    
    FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG
         LOCAL RV&
         RV&=1
         FUNCTION=RV&
    END FUNCTION
    SUB EZ_AppCleanUp() ' Last Sub called when app terminates
         ' Call Form _FreeRes routines here if not called in Forms WM_DESTROY message
    END SUB
     
    
    ' *************************************************************************************
    '                                Applications FORM Code
    ' *************************************************************************************
    FUNCTION PreProcess_Events(BYVAL FormName$, BYVAL hDlg&, BYVAL CID&, CMsg&, CVal&, Cancel&) AS LONG
         LOCAL RV&
         RV&=0
         FUNCTION=RV&
    END FUNCTION
    
    '<<BEGINFORM>> "FORM1"
    
    ' ======================================
    ' [PROTECTED CODE]         Do NOT Edit !
    ' ======================================
    SUB EZ_FORM1_Display(BYVAL hParent&)     ' (PROTECTED)
         LOCAL T$, X&, Y&, W&, H&, WS&, EWS&, hDlg&, EVAdd AS DWORD
         T$ = "GDImage demo"
         X& = EZLIB_GetNextDlgX
         Y& = EZLIB_GetNextDlgY
         W& =  332
         H& =  256
         WS& =%WS_POPUP OR %WS_CAPTION OR %WS_SYSMENU OR %WS_DLGFRAME OR %DS_CENTER
         EWS& =0
         EVAdd = CODEPTR(EZ_FORM1_ParseEvents)
         IF EZLIB_LoadingEvent(0, T$, X&, Y&, W&, H&, WS&, EWS&, EVAdd) THEN EXIT SUB
         DIALOG NEW UNITS,  hParent&, T$, X&, Y&, W&, H&, WS&, EWS&, TO hDlg&
         hFORM1 = hDlg&
         EZ_FORM1_Design hDlg&
         DIALOG SHOW MODELESS hDlg&, CALL FORM1_DlgProc
    END SUB
    SUB EZ_FORM1_Design(BYVAL hDlg&)     ' (PROTECTED)
         LOCAL WS&, EWS&, hCtrl&, hTemp&, EVAdd AS DWORD, AW&, AH&, CText$
         EVAdd = CODEPTR(EZ_FORM1_ParseEvents)
         ' [Zap Image Control]
         WS&  = %WS_CHILD OR %WS_VISIBLE
         EWS& = 0
         hCtrl&=EZLIB_AddControl("ZIMAGECTRL", hDlg&,  %FORM1_GDIMAGE2,  "c:\gdimage\sample.png<fit>", 16, 160, 60, 56, WS&, EWS&, 1, EVAdd, 1, 0)
         ' -----------------------------------------------
         ' [Label]
         WS& =  %SS_CENTER OR %SS_NOPREFIX OR %WS_BORDER OR %WS_CHILD OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN
         EWS& = 0
         hCtrl&=EZLIB_AddControl("STATIC", hDlg&,  %FORM1_PLACEHOLDER,  "place holder", 16, 24, 64, 48, WS&, EWS&, 0, EVAdd, 1, 0)
         ' -----------------------------------------------
         ' [Button]
         WS& =  %BS_PUSHBUTTON OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_CHILD OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN
         EWS& = 0
         hCtrl&=EZLIB_AddControl("BUTTON", hDlg&,  %FORM1_BUTTON1,  "Select New Image", 12, 96, 76, 24, WS&, EWS&, 0, EVAdd, 1, 0)
         ' -----------------------------------------------
         ' [Zap Image Control]
         WS&  = %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN
         EWS& = %WS_EX_CLIENTEDGE
         hCtrl&=EZLIB_AddControl("ZIMAGECTRL", hDlg&,  %FORM1_GDIMAGE1,  "c:\gdimage\sample.png<fit>", 112, 24, 204, 192, WS&, EWS&, 1, EVAdd, 1, 0)
         ' -----------------------------------------------
    END SUB
    
    SUB EZ_FORM1_ParseEvents(BYVAL hDlg&, BYVAL CID&, CMsg&, CVal&, Cancel&)     ' (PROTECTED)
         IF PreProcess_Events("FORM1", hDlg&, CID&, CMsg&, CVal&, Cancel&) THEN EXIT SUB
         SELECT CASE CID&
              CASE %EZ_Window
                   FORM1_Events hDlg&, CID&, CMsg&, CVal&, Cancel&
              CASE  %FORM1_GDIMAGE2
                   FORM1_GDIMAGE2_Events CID&, CMsg&, CVal&, Cancel&
              CASE  %FORM1_PLACEHOLDER
                   FORM1_PLACEHOLDER_Events CID&, CMsg&, CVal&, Cancel&
              CASE  %FORM1_BUTTON1
                   FORM1_BUTTON1_Events CID&, CMsg&, CVal&, Cancel&
              CASE  %FORM1_GDIMAGE1
                   FORM1_GDIMAGE1_Events CID&, CMsg&, CVal&, Cancel&
              CASE ELSE
                   FORM1_Events hDlg&, CID&, CMsg&, CVal&, Cancel&
         END SELECT
    END SUB
    ' ======================================
    ' [USER ACCESSABLE CODE]  You may Edit !
    ' ======================================
    SUB FORM1_Events(BYVAL hDlg&, BYVAL CID&, CMsg&, CVal&, Cancel&)
         SELECT CASE CID&
              CASE %EZ_Window
                   SELECT CASE CMsg&
                        CASE %EZ_Loading
                        CASE %EZ_Loaded
                        CASE %EZ_Started
                        CASE %EZ_Close
                        CASE %EZ_FreeNow
                             ' Form FreeRes routine can be called here!
                        CASE %EZ_Maximize
                        CASE %EZ_Minimize
                        CASE %EZ_Restore
                        CASE ELSE
                   END SELECT
              CASE ELSE
         END SELECT
    END SUB
    ' #################################################################
    '              Dialog Procedure for FORM1
    ' #################################################################
    CALLBACK FUNCTION FORM1_DlgProc
         SELECT CASE CBMSG
              CASE %WM_DESTROY
              CASE ELSE
         END SELECT
         ' Pass Messages to EZGUI Default Event Generator
         ' make sure CODEPTR parameter points to _ParseEvents routine for this form
         FUNCTION=EZLIB_DLGEvents(CBHNDL, CBMSG, CBWPARAM, CBLPARAM, CODEPTR(EZ_FORM1_ParseEvents))
    END FUNCTION
    SUB FORM1_GDIMAGE2_Events( MyID&, CMsg&, CVal&, Cancel&)
         LOCAL hCtrl&
         CONTROL HANDLE hForm1, MyID& TO hCtrl&
         SELECT CASE CMsg&
              CASE %EZ_Click
              CASE %EZ_Loaded
                   ZI_SetProperty hCtrl&, %ZI_GradientTop, RGB(240,240,240)
                   ZI_SetProperty hCtrl&, %ZI_GradientBottom, RGB(240,240,240)
                   ZI_SetAnchorMode hCtrl&, %ANCHOR_BOTTOM
              CASE %EZ_Loading
                   EZ_SetLoadText EZLIB_ImageFolder$+"heart1.gif"
              CASE ELSE
         END SELECT
    END SUB
    SUB FORM1_PLACEHOLDER_Events( MyID&, CMsg&, CVal&, Cancel&)
         LOCAL hCtrl&
         SELECT CASE CMsg&
              CASE %EZ_Click
              CASE %EZ_Loaded
                   hCtrl& = zClockCtrl(hForm1,EZLIB_ImageFolder$+"SmallClock.png", 10,10, 0, 0, MyID&+1, ZD_ColorARGB(255, RGB(25,48,4)), ZD_ColorARGB(255, RGB(192,0,0)))
              CASE ELSE
         END SELECT
    END SUB
    SUB FORM1_BUTTON1_Events( MyID&, CMsg&, CVal&, Cancel&)
         SELECT CASE CMsg&
              CASE %EZ_Click
                   LOCAL F$, hCtrl&
                   CONTROL HANDLE hForm1, %FORM1_GDIMAGE1 TO hCtrl&
                   ZI_SetSaveDialogMsg "Select picture", "Save picture", "GDImage"
                   F$ = ZI_LoadDialog(hForm1)
                   IF F$<>"" THEN ZI_SetFromFile hCtrl&, (F$)
              CASE ELSE
         END SELECT
    END SUB
    SUB FORM1_GDIMAGE1_Events( MyID&, CMsg&, CVal&, Cancel&)
         LOCAL hCtrl&
         CONTROL HANDLE hForm1, MyID& TO hCtrl&
         SELECT CASE CMsg&
              CASE %EZ_Click
              CASE %EZ_Loaded
                   ZI_SetAnchorMode hCtrl&, %ANCHOR_HEIGHT_WIDTH
              CASE %EZ_Loading
                   EZ_SetLoadText EZLIB_ImageFolder$+"image.jpg"
              CASE ELSE
         END SELECT
    END SUB
     
    '<<END ALL FORMS>>    UnKnown Routines follow:
    #IF %EZ_NOSKIPCODE
    #ENDIF 'PARSE END

    Nice work Patrice!

    If you want great graphics consider using GDImage.
Working...
X