//ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
//Û                                                      Û
//Û     Virtual Pascal Runtime Library.  Version 2.1     Û
//Û     Common Dialog API interface unit                 Û
//Û     ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÛ
//Û     Copyright (C) 2000 vpascal.com                   Û
//Û                                                      Û
//ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß

unit CommDlg;

{&AlignRec+,StdCall+,SmartLink+,OrgName+}

interface

uses Windows;

const
{ TOpenFileName record flags }
  ofn_ReadOnly                  = $00000001;
  ofn_OverwritePrompt           = $00000002;
  ofn_HideReadOnly              = $00000004;
  ofn_NoChangeDir               = $00000008;
  ofn_ShowHelp                  = $00000010;
  ofn_EnableHook                = $00000020;
  ofn_EnableTemplate            = $00000040;
  ofn_EnableTemplateHandle      = $00000080;
  ofn_NoValidate                = $00000100;
  ofn_AllowMultiSelect          = $00000200;
  ofn_ExtensionDifferent        = $00000400;
  ofn_PathMustExist             = $00000800;
  ofn_FileMustExist             = $00001000;
  ofn_CreatePrompt              = $00002000;
  ofn_ShareAware                = $00004000;
  ofn_NoReadOnlyReturn          = $00008000;
  ofn_NoTestFileCreate          = $00010000;
  ofn_NoNetworkButton           = $00020000;
  ofn_NoLongNames               = $00040000;

{ SHAREVISTRING Return Values }

  ofn_ShareWarn                 = 0;
  ofn_ShareNoWarn               = 1;
  ofn_ShareFallThrough          = 2;

{ ChooseColor flag definitions }

  cc_RgbInit                    = $00000001;
  cc_FullOpen                   = $00000002;
  cc_PreventFullOpen            = $00000004;
  cc_ShowHelp                   = $00000008;
  cc_EnableHook                 = $00000010;
  cc_EnableTemplate             = $00000020;
  cc_EnableTemplateHandle       = $00000040;

{ FindText and ReplaceText flag definitions }

  fr_Down                       = $00000001;
  fr_WholeWord                  = $00000002;
  fr_MatchCase                  = $00000004;
  fr_FindNext                   = $00000008;
  fr_Replace                    = $00000010;
  fr_ReplaceAll                 = $00000020;
  fr_DialogTerm                 = $00000040;
  fr_ShowHelp                   = $00000080;
  fr_EnableHook                 = $00000100;
  fr_EnableTemplate             = $00000200;
  fr_NoUpDown                   = $00000400;
  fr_NoMatchCase                = $00000800;
  fr_NoWholeWord                = $00001000;
  fr_EnableTemplateHandle       = $00002000;
  fr_HideUpDown                 = $00004000;
  fr_HideMatchCase              = $00008000;
  fr_HideWholeWord              = $00010000;

{ ChooseFont flags }

  cf_ScreenFonts                = $00000001;
  cf_PrinterFonts               = $00000002;
  cf_ShowHelp                   = $00000004;
  cf_EnableHook                 = $00000008;
  cf_EnableTemplate             = $00000010;
  cf_EnableTemplateHandle       = $00000020;
  cf_InitToLogFontStruct        = $00000040;
  cf_UseStyle                   = $00000080;
  cf_Effects                    = $00000100;
  cf_Apply                      = $00000200;
  cf_AnsiOnly                   = $00000400;
  cf_NoVectorFonts              = $00000800;
  cf_NoSimulations              = $00001000;
  cf_LimitSize                  = $00002000;
  cf_FixedPitchOnly             = $00004000;
  cf_Wysiwyg                    = $00008000;
  cf_ForceFontExist             = $00010000;
  cf_ScalableOnly               = $00020000;
  cf_TtOnly                     = $00040000;
  cf_NoFaceSel                  = $00080000;
  cf_NoStyleSel                 = $00100000;
  cf_NoSizeSel                  = $00200000;
  cf_Both                       = cf_ScreenFonts or cf_PrinterFonts;
  cf_NoOemFonts                 = cf_NoVectorFonts;

{ Font types }

  Simulated_FontType            = $8000;
  Printer_FontType              = $4000;
  Screen_FontType               = $2000;
  Bold_FontType                 = $0100;
  Italic_FontType               = $0200;
  Regular_FontType              = $0400;

  wm_ChooseFont_GetLogFont      = wm_User + 1;

{ Common Dialog User Registered Messages }

  ColorOkString                 = 'commdlg_ColorOK';
  FileOkString                  = 'commdlg_FileNameOK';
  FindMsgString                 = 'commdlg_FindReplace';
  HelpMsgString                 = 'commdlg_help';
  LbSelChString                 = 'commdlg_LBSelChangedNotify';
  SetRgbString                  = 'commdlg_SetRGBColor';
  ShareViString                 = 'commdlg_ShareViolation';

{ Values for high word of lparam of LbSelChString messages }

  cd_LbSelNoItems               = -1;
  cd_LbSelChange                = 0;
  cd_LbSelSub                   = 1;
  cd_LbSelAdd                   = 2;

{ PrintDlg options }

  pd_AllPages                   = $00000000;
  pd_Selection                  = $00000001;
  pd_PageNums                   = $00000002;
  pd_NoSelection                = $00000004;
  pd_NoPageNums                 = $00000008;
  pd_Collate                    = $00000010;
  pd_PrintToFile                = $00000020;
  pd_PrintSetup                 = $00000040;
  pd_NoWarning                  = $00000080;
  pd_ReturnDC                   = $00000100;
  pd_ReturnIC                   = $00000200;
  pd_ReturnDefault              = $00000400;
  pd_ShowHelp                   = $00000800;
  pd_EnablePrintHook            = $00001000;
  pd_EnableSetupHook            = $00002000;
  pd_EnablePrintTemplate        = $00004000;
  pd_EnableSetupTemplate        = $00008000;
  pd_EnablePrintTemplateHandle  = $00010000;
  pd_EnableSetupTemplateHandle  = $00020000;
  pd_UseDevModeCopies           = $00040000;
  pd_DisablePrintToFile         = $00080000;
  pd_HidePrintToFile            = $00100000;
  pd_NoNetworkButton            = $00200000;
  pd_PageSetup                  = $00400000;

{ Common Dialog Error Codes }

  cderr_GeneralCodes            = $0000;
  cderr_StructSize              = $0001;
  cderr_Initialization          = $0002;
  cderr_NoTemplate              = $0003;
  cderr_NoHInstance             = $0004;
  cderr_LoadStrFailure          = $0005;
  cderr_FindResFailure          = $0006;
  cderr_LoadResFailure          = $0007;
  cderr_LockResFailure          = $0008;
  cderr_MemAllocFailure         = $0009;
  cderr_MemLockFailure          = $000A;
  cderr_NoHook                  = $000B;
  cderr_RegisterMsgFail         = $000C;
  pderr_PrinterCodes            = $1000;
  pderr_SetupFailure            = $1001;
  pderr_ParseFailure            = $1002;
  pderr_RetDefFailure           = $1003;
  pderr_LoadDrvFailure          = $1004;
  pderr_GetDevModeFail          = $1005;
  pderr_InitFailure             = $1006;
  pderr_NoDevices               = $1007;
  pderr_NoDefaultPrn            = $1008;
  pderr_DndmMismatch            = $1009;
  pderr_CreateIcFailure         = $100A;
  pderr_PrinterNotFound         = $100B;
  pderr_DefaultDifferent        = $100C;
  cferr_ChooseFontCodes         = $2000;
  cferr_NoFonts                 = $2001;
  cferr_MaxLessThanMin          = $2002;
  fnerr_FileNameCodes           = $3000;
  fnerr_SubClassFailure         = $3001;
  fnerr_InvalidFileName         = $3002;
  fnerr_BufferTooSmall          = $3003;
  frerr_FindReplaceCodes        = $4000;
  frerr_BufferLengthZero        = $4001;
  frerr_ChooseColorCodes        = $5000;
  cderr_DialogFailure           = $FFFF;

type
  POpenFileName = ^TOpenFileName;
  TOpenFileName = packed record
    lStructSize:        DWord;
    hwndOwner:          HWnd;
    hInstance:          HInst;
    lpstrFilter:        PChar;
    lpstrCustomFilter:  PChar;
    nMaxCustFilter:     DWord;
    nFilterIndex:       DWord;
    lpstrFile:          PChar;
    nMaxFile:           DWord;
    lpstrFileTitle:     PChar;
    nMaxFileTitle:      DWord;
    lpstrInitialDir:    PChar;
    lpstrTitle:         PChar;
    Flags:              DWord;
    nFileOffset:        SmallWord;
    nFileExtension:     SmallWord;
    lpstrDefExt:        PChar;
    lCustData:          DWord;
    lpfnHook:           TOFNHookProc;
    lpTemplateName:     PChar;
  end;

type
  PChooseColor = ^TChooseColor;
  TChooseColor = packed record
    lStructSize:    DWord;
    hwndOwner:      HWnd;
    hInstance:      HWnd;
    rgbResult:      TColorRef;
    lpCustColors:   ^TColorRef;
    Flags:          DWord;
    lCustData:      LParam;
    lpfnHook:       TCCHookProc;
    lpTemplateName: PChar;
  end;

  PChooseFont = ^TChooseFont;
  TChooseFont = packed record
    lStructSize:        DWord;
    hwndOwner:          HWnd;
    hDC:                HDC;
    lpLogFont:          PLogFont;
    iPointSize:         Integer;
    Flags:              DWord;
    rgbColors:          TColorRef;
    lCustData:          LParam;
    lpfnHook:           TCFHookProc;
    lpTemplateName:     PChar;
    hInstance:          HInst;
    lpszStyle:          PChar;
    nFontType:          SmallWord;
    __MISSING_ALIGNMENT__: SmallWord;
    nSizeMin:           Integer;
    nSizeMax:           Integer;
  end;

  PFindReplace = ^TFindReplace;
  TFindReplace = packed record
    lStructSize:        DWord;
    hwndOwner:          HWnd;
    hInstance:          HInst;
    Flags:              DWord;
    lpstrFindWhat:      PChar;
    lpstrReplaceWith:   PChar;
    wFindWhatLen:       SmallWord;
    wReplaceWithLen:    SmallWord;
    lCustData:          LParam;
    lpfnHook:           TFRHookProc;
    lpTemplateName:     PChar;
  end;

  PPrintDlg = ^TPrintDlg;
  TPrintDlg = packed record
    lStructSize:         DWord;
    hwndOwner:           HWnd;
    hDevMode:            HGlobal;
    hDevNames:           HGlobal;
    hDC:                 HDC;
    Flags:               DWord;
    nFromPage:           SmallWord;
    nToPage:             SmallWord;
    nMinPage:            SmallWord;
    nMaxPage:            SmallWord;
    nCopies:             SmallWord;
    hInstance:           HInst;
    lCustData:           LParam;
    lpfnPrintHook:       TPrintHookProc;
    lpfnSetupHook:       TSetupHookProc;
    lpPrintTemplateName: PChar;
    lpSetupTemplateName: PChar;
    hPrintTemplate:      HGlobal;
    hSetupTemplate:      HGlobal;
  end;

  PDevNames = ^TDevNames;
  TDevNames = packed record
    wDriverOffset: SmallWord;
    wDeviceOffset: SmallWord;
    wOutputOffset: SmallWord;
    wDefault:      SmallWord;
  end;

function ChooseColor(var CC: TChooseColor): Bool;
function ChooseFont(var ChooseFont: TChooseFont): Bool;
function CommDlgExtendedError: DWord;
function FindText(var FindReplace: TFindReplace): HWnd;
function GetFileTitle(FileName,Title: PChar; TitleSize: SmallWord): SmallInt;
function GetOpenFileName(var OpenFile: TOpenFilename): Bool;
function GetSaveFileName(var SaveFile: TOpenFilename): Bool;
function PrintDlg(var PrintDlg: TPrintDlg): Bool;
function ReplaceText(var FindReplace: TFindReplace): HWnd;

{ What is not supported by Open32 }

const
  ofn_Explorer                  = $00080000;
  ofn_NoDereferenceLinks        = $00100000;

  cc_SolidColor                 = $00000080;
  cc_AnyColor                   = $00000100;

{$IFNDEF Open32}

type // function used for callback hooks
  TMessageHookFn = function(Wnd: HWnd; Message: UInt; wParam: WParam; lParam: LParam): UInt;

const
  ofn_LongNames = $00200000;

// Return values for the registered message sent to the hook function
// when a sharing violation occurs.  ofn_ShareFallThrough allows the
// filename to be accepted, ofn_ShareNoWarn rejects the name but puts
// up no warning (returned when the app has already put up a warning
// message), and ofn_ShareWarn puts up the default warning message
// for sharing violations.

//  Note:  Undefined return values map to ofn_ShareWarn, but are
//         reserved for future use.


type
  POFNotify = ^TOFNotify;
  TOFNotify = packed record
    hdr: TNMHdr;
    lpOFN: POpenFilename;
    pszFile: PChar;
  end;

const
  cdn_First = -601;
  cdn_Last = -699;

// Notifications when Open or Save dialog status changes

  cdn_InitDone = cdn_First - 0;
  cdn_SelChange = cdn_First - 1;
  cdn_FolderChange = cdn_First - 2;
  cdn_ShareViolation = cdn_First - 3;
  cdn_Help = cdn_First - 4;
  cdn_FileOk = cdn_First - 5;
  cdn_TypeChange = cdn_First - 6;

  cdm_First = WM_User + 100;
  cdm_Last = WM_User + 200;

// Messages to query information from the Open or Save dialogs

// lParam = pointer to text buffer that gets filled in
// wParam = max number of characters of the text buffer (including NULL)
// return = < 0 if error; number of characters needed (including NULL)

  cdm_GetSpec = cdm_First + 0;

// lParam = pointer to text buffer that gets filled in
// wParam = max number of characters of the text buffer (including NULL)
// return = < 0 if error; number of characters needed (including NULL)

  cdm_GetFilePath = cdm_First + 1;

// lParam = pointer to text buffer that gets filled in
// wParam = max number of characters of the text buffer (including NULL)
// return = < 0 if error; number of characters needed (including NULL)

  cdm_GetFolderPath = cdm_First + 2;

// lParam = pointer to ItemIdList buffer that gets filled in
// wParam = size of the ItemIdList buffer
// return = < 0 if error; length of buffer needed

  cdm_GetFolderIdList = cdm_First + 3;

// lParam = pointer to a string
// wParam = ID of control to change
// return = not used

  cdm_SetControlText = cdm_First + 4;

// lParam = not used
// wParam = ID of control to change
// return = not used

  cdm_HideControl = cdm_First + 5;

// lParam = pointer to default extension (no dot)
// wParam = not used
// return = not used

  cdm_SetDefExt = cdm_First + 6;

const
  cf_ScriptsOnly = cf_ANSIOnly;
  cf_SelectScript = $00400000;
  cf_NoScriptSel = $00800000;
  cf_NoVertFonts = $01000000;

// these are extra nFontType bits that are added to what is returned to the
// EnumFonts callback routine

  wm_ChooseFont_SetLogFont = WM_User + 101;
  wm_ChooseFont_SetFlags = WM_User + 102;

// HiWord values for lParam of commdlg_LBSelChangeNotify message

const
  pd_UseDevModeCopiesAndCollate = $00040000;

const
  dn_DefaultPrn = $0001;

const
  wm_psd_PageSetupDlg     = WM_User;
  wm_psd_FullPageRect     = WM_User + 1;
  wm_psd_MinMarginRect    = WM_User + 2;
  wm_psd_MarginRect       = WM_User + 3;
  wm_psd_GreekTextRect    = WM_User + 4;
  wm_psd_EnvStampRect     = WM_User + 5;
  wm_psd_YaFullPageRect   = WM_User + 6;

type
  PPageSetupDlg = ^TPageSetupDlg;
  TPageSetupDlg = packed record
    lStructSize: DWord;
    hwndOwner: HWnd;
    hDevMode: HGlobal;
    hDevNames: HGlobal;
    Flags: DWord;
    ptPaperSize: TPoint;
    rtMinMargin: TRect;
    rtMargin: TRect;
    hInstance: HInst;
    lCustData: LParam;
    lpfnPageSetupHook: TMessageHookFn;
    lpfnPagePaintHook: TMessageHookFn;
    lpPageSetupTemplateName: PChar;
    hPageSetupTemplate: HGlobal;
  end;

function PageSetupDlg(var PgSetupDialog: TPageSetupDlg): Bool;

const
  psd_DefaultMinMargins             = $00000000; // default (printer's)
  psd_InWinIniIntlMeasure           = $00000000; // 1st of 4 possible

  psd_MinMargins                    = $00000001; // use caller's
  psd_Margins                       = $00000002; // use caller's
  psd_InThousandthsOfInches         = $00000004; // 2nd of 4 possible
  psd_InHundredthsOfMillimeters     = $00000008; // 3rd of 4 possible
  psd_DisableMargins                = $00000010;
  psd_DisablePrinter                = $00000020;
  psd_NoWarning                     = $00000080; // must be same as PD_*
  psd_DisableOrientation            = $00000100;
  psd_ReturnDefault                 = $00000400; // must be same as PD_*
  psd_DisablePaper                  = $00000200;
  psd_ShowHelp                      = $00000800; // must be same as PD_*
  psd_EnablePageSetupHook           = $00002000; // must be same as PD_*
  psd_EnablePageSetupTemplate       = $00008000; // must be same as PD_*
  psd_EnablePageSetupTemplateHandle = $00020000; // must be same as PD_*
  psd_EnablePagePaintHook           = $00040000;
  psd_DisablePagePainting           = $00080000;


// Common dialog error return codes

const
  CcErr_ChooseColorCodes = $5000;

{$ENDIF Open32}

implementation

function GetOpenFileName;       external;
function GetSaveFileName;       external;
function GetFileTitle;          external;
function ChooseColor;           external;
function FindText;              external;
function ReplaceText;           external;
function ChooseFont;            external;
function PrintDlg;              external;
function CommDlgExtendedError;  external;

{$IFNDEF Open32}
function PageSetupDlg;          external;
{$ENDIF  Open32}

end.
