This includes the complete cgdTypes.pas file to ease copy/pasting of function definitions, types, etc.

    You can find a briefing of CGD types here.

(*  -----------------------------------------------------------------------------------------------------------
    Title   : Basic Windows '95 API: Compiled Generic Dialog (CGD)  T y p e s
    Version : 2.0 (release 2006)
---------------------------------------------------------------------------------------------------------------
    Created : 14/02/2001                (Adapted from the 16/03/99-20/01/2000 Version 1)
    Finished: 26/04/2001                (Compiler v2.0 & DLL v2.0 finished)
    Version : 2006 (01/11/2003)

        Last updated:

        23/01/2002  Bug fix: Measuring correct dialog size with a button inside folder (No new version created)
        26/01/2002  Bug fix: AutoAdjustLength() modified to adjust existing types only
        29/01/2002  Bug fix: cgdModelessGetClientX() did not set cgdOptions correctly
        19/02/2002  DoPreview(prPaintedByWindows); added to paint method to preview immediately.
        05/03/2002  AutoShiftX added to automatically scroll small modeless dialogs
        05/03/2002  New method cgdInternalRelease() added to help setup programs (returns 1)
        05/03/2002  All methods renamed to lower case CGD
        08/05/2002  Bug fix: Modeless dialogs did not properly check structure size
        08/05/2002  Bug fix: Random data interpreted as strings (length > SizeOf) produced dramatic crashes
        08/05/2002  Application owned bitmaps, done via cgdSetAppOwnedBmpHandle
        08/05/2002  cgdModelessDlgSetData() added.
        08/05/2002  Bug fix: EditChangeCallback wasn´t called if record was changed by button (files, colors, etc.)
        08/05/2002  EditChangeCallback is now called after redo & paste. (pItem=nil in this case.)
        08/05/2002  cgdInternalRelease now returns 2
        30/05/2002  ParentClick now also sends <Ctrl>-<Tab> to the parent for coherent MAI behavior.
        12/06/2002  Bug fix: If first line after tab btn was private, the btn did not deploy/retract correctly. (see isDeployed
        12/06/2002  cgdInternalRelease now returns 3
        09/07/2002  Bug fix: cgdModelessGetClientX could produce an error not releasing the handle
        09/07/2002  Colors adapted to match the user's GetSysColor(Color_BtnFace, Color_BtnShadow .. )
        09/07/2002  cgdInternalRelease now returns 4
        09/09/2002  CGD MAI environment finished with HTML doc
        09/09/2002  Binary CGD file adjusted to support {<COPYRIGHT>}{>(c)Author}{<PRIVATE>}
        09/09/2002  hasThickFolders (Small GDI drawing adjustment done concerning left border of folders)
        09/09/2002  cgdRuntimeVersion now returns 2003
        09/09/2002  cgdInternalRelease now returns 5
        31/01/2003  License system changed to shareware, 2 licenses
        31/01/2003  Timer scale changed from 250 ms to 200 ms
        31/01/2003  Help message window changed to an autoscrolling type
        31/01/2003  Warning about not registered CGD via help message window
        31/01/2003  cgdInternalRelease now returns 6
        19/05/2003  Double monitor support: Modal dialogs show up in the same monitor as their aParent window
        19/05/2003  Library update: The linked WinObj32.pas library is now the base of the 16/05/2003 MAI 2 release
        19/05/2003  cgdInternalRelease now returns 7
        01/11/2003  Compiled with the 2004 release of TWindow objects
        01/11/2003  Bug fix: cgdrun20.dll help message displaying over other help messages
        01/11/2003  Major code improvements for Pentium IV
        01/11/2003  The CGD environment now includes the new WebBuild-compatible HTML browser to view the doc
        01/11/2003  CGD help has been improved, including a direct link to predefined types and to cgdTypes.pas for copy/paste
        01/11/2003  This CGD version is referred to as CGD 2004
        01/11/2003  cgdRuntimeVersion now returns 2004
        01/11/2003  cgdInternalRelease now returns 8
        10/11/2005  cgdRuntimeVersion now returns 2006
        10/11/2005  cgdInternalRelease now returns 9


    Author  : Jacques Basaldúa  (jacques@dybot.com)
-----------------------------------------------------------------------------------------------------------  *)

{$ALIGN ON}             {Use packed for compatibility of typed files}
{$IMPORTEDDATA OFF}
{$B-}{$X+}{$V-}
{$LONGSTRINGS OFF}      {Use the type AnsiString for non-pascal strings.}
{$OPENSTRINGS ON}
{$MINENUMSIZE 1}
{$OPTIMIZATION ON}
{$SAFEDIVIDE OFF}       {Already corrected by Windows 95}
{$TYPEDADDRESS OFF}
{$WRITEABLECONST ON}

{$IFDEF PASO}
    {$ASSERTIONS ON}    {$HINTS ON}     {$WARNINGS ON}
    {$D+}   {$L+}   {$Y+}   {$I+}
    {$Q+}   {$R+}   {$S+}   {$W+}
{$ELSE}
    {$ASSERTIONS OFF}   {$HINTS OFF}    {$WARNINGS OFF}
    {$D-}   {$L-}   {$Y-}   {$I-}
    {$Q-}   {$R-}   {$S-}   {$W-}
{$ENDIF}

{$E-}   {$F-}   {$K-}   {$M-}   {$N+}

UNIT    cgdTypes;

INTERFACE   (*  ------------------------------------------------------------------------------------------  *)

USES    Windows;


CONST   cgdMaxPathLen       = 211;

        // cgdDialog return codes:

        cgdRunCancel        =  2;
        cgdRunOk            =  1;

        cgdInitOk           =  0;       // No error, but not complete (modeless dialogs)

        cgdFileNotFound     = -1;
        cgdDescrNotFound    = -2;
        cgdNotEnoughRAM     = -3;
        cgdWrongSize        = -4;
        cgdInvalidHandle    = -5;
        cgdDecryptFailed    = -6;

        // Toolbar button options:

        tbNoToolbar         =  0;
        tbOk                =  1;       // Ok button only.
        tbOEsc              =  2;       // " Esc
        tbOEUndo            =  3;       // "  "  Undo
        tbOEUDeplRetr       =  5;       // "  "   "   Deploy, Retract
        tbOEUDRCopyPaste    =  7;       // "  "   "     "        "   Copy, Paste
        tbOEUDRCPPreview    =  8;       // "  "   "     "        "     "     "   Preview

        // Preview window position options:

        pvNoPreview         = 0;
        pvPreviewOnTop      = 1;
        pvPreviewToRight    = 2;

        // For options not using dialog handles

        dlhModalDialog      = 0;

        // Possible values of pReason. Who called the paint method.

        prPaintedByWindows  = 1;
        prPaintedByBtnClick = 2;
        prPaintedByEdChange = 3;
        prPaintedByTimer    = 4;

        // Value returned in any cgdFileName record is the dialog button is not pressed

        uSelNoSelection     = -1;

        // ForceScrollbar (cgdOptions) values

        fsUseDefault        = 0;
        fsShowAlways        = 1;
        fsNeverShow         = 2;


TYPE    { Assumed types: This header must be included in all files using this library }

// All the following types are assumed by the compiler to be as they are declared here, regardless of how
// you define them in your software.

        boolean         = ByteBool;
        integer         = SmallInt;
        real            = single;
        Int64           = Comp;             { Not implemented until version 4.0 of Delphi }
{       string          = ShortString;      $LONGSTRINGS OFF    $OPENSTRINGS ON}

        cBool           = LongBool;         { Like boolean, but 4 bytes:    Is a checkbox }

        pPoint2         = ^Point2;
        Point2          = packed record
            x,y         : single
        end;

        pPoint3         = ^Point3;
        Point3          = packed record
            x,y,z       : single
        end;

        pDate           = ^Date;
        Date            = packed record
            yy,mm,dd    : integer
        end;

        pTime           = ^Time;
        Time            = packed record
            hh,mm,ss    : integer
        end;

        pCgdFileName    = ^cgdFileName;
        cgdFileName     = packed record
            name,
            DefDir,
            ExtDescr    : string [cgdMaxPathLen];
            fOpen,cOver : boolean;
            uSelFmt     : integer
        end;

        pCgdListBox     = ^cgdListBox;
        cgdListBox      = packed record
            opt         : byte;
            TextList    : string [254]
        end;

        pCgdPath        = ^cgdPath;
        cgdPath         = packed record
            name,
            Caption     : string [cgdMaxPathLen]
        end;

        pCgdColor       = ^cgdColor;
        cgdColor        = packed record
            rgb         : longint
        end;
(*
    Primitive types are: (all other types are packed records of these)

  boolean types:
    boolean         (size= 1)       // True = 255,          false = 0
    cBool           (size= 4)       // !! True = 255 !!     false = 0   (ONLY ONE BYTE MODIFIED !)

  integer types:
    byte            (size= 1)
    word            (size= 2)
    integer         (size= 2)
    longint         (size= 4)

  real types:
    single          (size= 4)
    real            (size= 4)       // same as single
    double          (size= 8)

  string types:
    char            (size= 1)
    string          (size depends on [])

  sets/Enumerations:
    (   )       (size= 1)       as COMBOBOX
    (   )       (size= 1)       as RADIOBUTTONS
    same        (size= 4)       as COMBOBOX         DECLARE {<EXTENDTO32>} before
    same        (size= 4)       as RADIOBUTTONS     DECLARE {<EXTENDTO32>} before

  primitive records:
    point2      (size= 8)
    point3      (size=12)
    date        (size= 6)
    time        (size= 6)
    cgdFileName (only name is edited)
    cgdPath     (only name is edited)
    cgdColor    (size= 4)


    Type limitations:
    -----------------

    Boolean     description         127 chars

    File        name                211 chars
                default path        211 chars
                format description  211 chars                   212 x 3 = 636 bytes

    Path        name                211 chars
                Caption             211 chars

    Combo       item list           32 names of 19 chars each   32 x 20 = 640 bytes

    Combo (user defined)            254 chars description separated by #0 and finished by #0,#0

    Radio       item list           20 names of 31 chars each   20 x 32 = 640 bytes

    Strings     contents            as defined, up to 255 chars
*)

    // Types used to define cgdOptions

    FontDefinition      = packed record                             // Size = 36
        name                                : string [31];
        size                                : integer;
        Bold,Italic                         : boolean
    end;

    PreviewWin          = packed record                             // Size = 8
        doPreview                           : word;
        pvOnTimer,pvOnEdChng                : boolean;
        pvX,pvY                             : integer
    end;

    pCgdOptions         = ^cgdOptions;
    cgdOptions          = packed record                             // Size = 328
        OpeningLevel,tbButtons                  : integer;          //   4
        isMetric,hasDlgFrame,hasThickFolders    : boolean;          // + 4
        HelpTimeout                             : byte;                         // In 1/4 second units
        txColor,bkColor,ColorLighter,
        ComboTxColor,ComboBkColor,
        EditTxColor,EditBkColor                 : longint;          // +28
        StaticN,StaticBd,StaticIt,StaticBI,
        RadioFnt,ComboFnt,EditFnt               : FontDefinition;   // +(7 x 36)
        PreV                                    : PreviewWin;       // + 8
        BoolMinX,BoolMinY,RadioMinX,RadioMinY,
        ComboMinX,EdStringX,EdNumberX,EdFnamX,
        EdPathX,EdPntCellX,EdColCellX,EdDTBoxX,
        EdMinY,ColorSampX                       : integer;          // +28
        fullReadOnly,autoAdjLength,ParentClick  : boolean;
        ForceScrollbar                          : byte              // +4
    end;

    bmpHandleDef        = packed record     // The application calls cgdSetAppOwnedBmpHandle()
        appID           : longint;          // Before cgdDialog or from an evaluation callback procedure.
        winH            : THandle;
        dlh             : THandle           // Internal use: Set by cgdSetAppOwnedBmpHandle
    end;

    // Multilingual support:

    cgdLexical          = packed record
        invNum  : string [47];  //  'Warning : Invalid number format or range'
        noSuch  : string [47];  //  'Failed : No such record in the clipboard'
        AnyFil  : string [47];  //  'Any file'
        RidNly  : string [47];  //  'Record is read only!';
        OkButt  : string [47];  //  'Accept current values = <Enter>'
        EscBtn  : string [47];  //  'Escape without modifying = <Esc>'
        UndoBt  : string [47];  //  'Undo all changes'
        DeplBt  : string [47];  //  'Deploy all'
        RetrBt  : string [47];  //  'Retract all'
        CopyBt  : string [47];  //  'Copy full record'
        PasteB  : string [47];  //  'Paste full record'
        PreviB  : string [47]   //  'Preview with current values'
    end;

    // This type belongs to ctPrivat.pas, it is included to warn users about Name Length.
    // The compiler allows long name but considers 19 chars only.

    // I.e.  My_Pretty_Long_Type_Name_1  =  My_Pretty_Long_Type_Name_2  =   My_Pretty_Long_Type

    TypeName            = string [19];      // Maximum length of a name for cgdDialog() stNam


TYPE    // Procedural interface: (All are applicable to both modal and modeless dialogs)

    // pWinObject is intended to support a MODELESS dialog object interface.
    // When used in modal dialogs, pWinObject will be nil.
    // When used in modeless dialogs, pWinObject will be the value passed by the app at cgdModelessDlgShow().

    EvaluateCallback    = function (    pStruc      : pointer;                          // Full record
                                    var Help        : string;                           // Help<>'' will be displayed
                                        pWinObject  : pointer)  : boolean;  StdCall;

    EditChangeCallback  = procedure(    pStruc      : pointer;                          // Full record
                                        pItem       : pointer;                          // Offset to last change (pItem=nil if
                                    var Help        : string;                           // Help<>'' will be displayed
                                        pWinObject  : pointer);             StdCall;

    TimerCallback       = procedure(    pStruc      : pointer;                          // Full record
                                    var Help        : string;                           // Help<>'' will be displayed
                                        pWinObject  : pointer);             StdCall;

    PreviewCallback     = procedure(    pStruc      : pointer;                          // Full record
                                        pReason     : longint;                          // prPaintedByDlgRegen or
                                                                                        // prPaintedByWindows
                                    const drs       : TDrawItemStruct;                  // from wm_Paint
                                    var Help        : string;                           // Help<>'' will be displayed
                                        pWinObject  : pointer);             StdCall;

    MlOkEscCallback     = procedure(    btCode      : longint;                          // either cgdRunOk or cgdRunCancel
                                        pWinObject  : pointer);             StdCall;

{$IFNDEF TheDLL}

    // Version ID (should return 2002)

    Function  cgdRuntimeVersion                                             : longint;  StdCall;

{   This function was not included in the original 2002 spec.
    At the same time, the CGDxxx prefix of the methods was renamed to lowercase.
    Therefore, if your app links lowercase cgdXXX methods i.o. CGDxxx, you can use
    this method safely.

    Setup programs (which list and/or override the dll dynamically) should be the only
    applications caring about this method.
}
    Function  cgdInternalRelease                                            : longint;  StdCall;

    // Options setting/reading, cgd filename setting/reading.

    Function  cgdSetOptions            (const Opts      : cgdOptions;
                                            dlh         : THandle)          : longint;  StdCall;
    Procedure cgdGetDefaultOptions     (var Opts        : cgdOptions)                   StdCall;
    Procedure cgdSetCGDFileName        (    fnam        : pChar);                       StdCall;
    Function  cgdGetCGDFileName        (    fnam        : pChar)            : longint;  StdCall;
    Procedure cgdSetBitmapsHInstance   (    hInstance   : THandle);                     StdCall;
    Function  cgdSetDialogDataDirectly (    pCgd        : pointer;
                                            cgSiz       : longint;
                                            stNam       : pChar)            : longint;  StdCall;
    // Built-in message translation

    Procedure cgdTranslateBuiltInMsgs  (const Msgs      : cgdLexical);                  StdCall;
    Procedure MakeTranslationPermanent;                                                 StdCall;

    // Advanced options: Callback procedures

    Function  cgdSetViewerCallback     (    Method      : PreviewCallback;
                                            dlh         : THandle)          : longint;  StdCall;
    Function  cgdSetEvaluationCallback (    Method      : EvaluateCallback;
                                            dlh         : THandle)          : longint;  StdCall;
    Function  cgdSetEditChangeCallback (    Method      : EditChangeCallback;
                                            dlh         : THandle)          : longint;  StdCall;
    Function  cgdSetTimerCallback      (    Method      : TimerCallback;
                                            dlh         : THandle)          : longint;  StdCall;
    Function  cgdModelessOkEscCallback (    Method      : MlOkEscCallback;
                                            dlh         : THandle)          : longint;  StdCall;
    // Modal dialog running

    Function  cgdDialog                (    aParent     : hWnd;
                                            Caption,
                                            stNam       : pChar;
                                            stSize      : longint;
                                            stAddr      : pointer)          : longint;  StdCall;
    // Modeless dialog running

    Function  cgdModelessGetClientX    (    stNam       : pChar;
                                        const Opts      : cgdOptions;
                                        var ClientX     : longint)          : longint;  StdCall;
    Function  cgdInitModelessDlg       (    stNam       : pChar;
                                            stSize      : longint;
                                        var dlh         : THandle)          : longint;  StdCall;
    Function  cgdModelessDlgShow       (    aClient     : hWnd;
                                            ox,oy,dx,dy : longint;
                                            stAddr      : pointer;
                                            stSize      : longint;
                                            dlh         : THandle;
                                        var ChildWin    : hWnd;
                                            pWinObject  : pointer)          : longint;  StdCall;
    Function  cgdModelessDlgResize     (    dlh         : THandle;
                                            ox,oy,dx,dy : longint)          : longint;  StdCall;
    Function  cgdModelessDlgGetData    (    dlh         : THandle;
                                            stAddr      : pointer)          : longint;  StdCall;
    Function  cgdModelessDlgSetData    (    dlh         : THandle;
                                            stAddr      : pointer)          : longint;  StdCall;
    Function  cgdModelessDlgClose      (    dlh         : THandle;
                                            retOk       : boolean)          : longint;  StdCall;

    // cgdInternalRelease 2 extension. Applicable to both modal & modeless. Support for app. owned bitmaps.

    Function  cgdSetAppOwnedBmpHandle  (    dlh         : THandle;
                                            bmpEq       : bmpHandleDef)     : longint;  StdCall;

{$ENDIF}

    // Modeless dialog running : Utility
(*
    Procedure cgdGossipPeekMsgLoop     (const msg       : TMsg;
                                            hChildWnd   : hWnd;
                                        var censored    : boolean);     // StdCall not required
*)
IMPLEMENTATION

{$IFNDEF TheDLL}

CONST   DllName = 'CgdRun20.dll';


    Function  cgdRuntimeVersion;        external DllName    name 'cgdRuntimeVersion';
    Function  cgdInternalRelease;       external DllName    name 'cgdInternalRelease';

    Function  cgdSetOptions;            external DllName    name 'cgdSetOptions';
    Procedure cgdGetDefaultOptions;     external DllName    name 'cgdGetDefaultOptions';
    Procedure cgdSetCGDFileName;        external DllName    name 'cgdSetCGDFileName';
    Function  cgdGetCGDFileName;        external DllName    name 'cgdGetCGDFileName';
    Procedure cgdSetBitmapsHInstance;   external DllName    name 'cgdSetBitmapsHInstance';
    Function  cgdSetDialogDataDirectly; external DllName    name 'cgdSetDialogDataDirectly';

    Procedure cgdTranslateBuiltInMsgs;  external DllName    name 'cgdTranslateBuiltInMsgs';
    Procedure MakeTranslationPermanent; external DllName    name 'MakeTranslationPermanent';

    Function  cgdSetViewerCallback;     external DllName    name 'cgdSetViewerCallback';
    Function  cgdSetEvaluationCallback; external DllName    name 'cgdSetEvaluationCallback';
    Function  cgdSetEditChangeCallback; external DllName    name 'cgdSetEditChangeCallback';
    Function  cgdSetTimerCallback;      external DllName    name 'cgdSetTimerCallback';
    Function  cgdModelessOkEscCallback; external DllName    name 'cgdModelessOkEscCallback';

    Function  cgdDialog;                external DllName    name 'cgdDialog';

    Function  cgdModelessGetClientX;    external DllName    name 'cgdModelessGetClientX';
    Function  cgdInitModelessDlg;       external DllName    name 'cgdInitModelessDlg';
    Function  cgdModelessDlgShow;       external DllName    name 'cgdModelessDlgShow';
    Function  cgdModelessDlgResize;     external DllName    name 'cgdModelessDlgResize';
    Function  cgdModelessDlgGetData;    external DllName    name 'cgdModelessDlgGetData';
    Function  cgdModelessDlgSetData;    external DllName    name 'cgdModelessDlgSetData';
    Function  cgdModelessDlgClose;      external DllName    name 'cgdModelessDlgClose';
    Function  cgdSetAppOwnedBmpHandle;  external DllName    name 'cgdSetAppOwnedBmpHandle';

{$ENDIF}

    // Modeless dialog running : Utility

(*
Procedure cgdGossipPeekMsgLoop     (const msg       : TMsg;
                                        hChildWnd   : hWnd;
                                    var censored    : boolean);     // StdCall not required. Register is faster.
{
    This utility is provided as source code, because it may need modification to suit your
    application's requirements. If modified, do not change its behavior seen by the user.


    Typical use of this utility:
    ----------------------------

    An application owning modeless CGD dialogs requires this change to its PeekMessage() loop:


var msg         : TMsg;
    censored    : boolean;

    // Typical PeekMessage loop without accelerators,  or ..

    while GetMessage(msg,0,0,0) do begin
        TranslateMessage(msg);
        censored := false;
        if hChildCGDialog <> 0 then cgdGossipPeekMsgLoop(msg,hChildCGDialog,censored);
        if not censored then DispatchMessage (msg)
    end

    // .. Typical PeekMessage loop with accelerators

    while GetMessage(msg,0,0,0) do begin
        if TranslateAccelerator(pAppWin^.hWindow,AccTable,msg) = 0 then begin
            TranslateMessage(msg);
            censored := false;
            if hChildCGDialog <> 0 then cgdGossipPeekMsgLoop(msg,hChildCGDialog,censored);
            if not censored then DispatchMessage (msg)
        end
    end


    1.  hChildCGDialog if the hWnd returned by cgdModelessDlgShow()

    2.  In case of more than one modeless dialog areas, hChildCGDialog is the hWnd of the
        ACTIVE dialog area. Your application must provide a mechanism to let the user switch
        between different dialog areas.
}
begin
    Censored := (msg.hwnd <> hChildWnd)                         // If message is for a control, it must
    and (   (   (msg.message = wm_KeyDown)                      // be censored in order to let the dialog
            and (   (msg.wParam = vk_Up)                        // work like a usual cgdDialog.
                or  (msg.wParam = vk_Down)
                or  (msg.wParam = vk_tab)
                )
            )
        or  (   (msg.message = wm_Char)                         // Don't send tabs to edit ctrls.
            and (   ((msg.wParam AND $FF)=9)
                )
            )
        );

    if  (msg.message = wm_KeyDown)                              // Avoid sending it twice.
    and (msg.hwnd <> hChildWnd) then begin
        SendMessage(hChildWnd, wm_KeyDown, msg.wParam, msg.lParam)
    end
end;
*)

END.