home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / WRTLSRC.RAR / COMMDLG.PAS next >
Pascal/Delphi Source File  |  2000-08-15  |  17KB  |  506 lines

  1. //█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  2. //█                                                      █
  3. //█     Virtual Pascal Runtime Library.  Version 2.1     █
  4. //█     Common Dialog API interface unit                 █
  5. //█     ─────────────────────────────────────────────────█
  6. //█     Copyright (C) 192000 vpascal.com                 █
  7. //█                                                      █
  8. //▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  9.  
  10. unit CommDlg;
  11.  
  12. {&AlignRec+,StdCall+,SmartLink+,OrgName+}
  13.  
  14. interface
  15.  
  16. uses Windows;
  17.  
  18. const
  19. { TOpenFileName record flags }
  20.   ofn_ReadOnly                  = $00000001;
  21.   ofn_OverwritePrompt           = $00000002;
  22.   ofn_HideReadOnly              = $00000004;
  23.   ofn_NoChangeDir               = $00000008;
  24.   ofn_ShowHelp                  = $00000010;
  25.   ofn_EnableHook                = $00000020;
  26.   ofn_EnableTemplate            = $00000040;
  27.   ofn_EnableTemplateHandle      = $00000080;
  28.   ofn_NoValidate                = $00000100;
  29.   ofn_AllowMultiSelect          = $00000200;
  30.   ofn_ExtensionDifferent        = $00000400;
  31.   ofn_PathMustExist             = $00000800;
  32.   ofn_FileMustExist             = $00001000;
  33.   ofn_CreatePrompt              = $00002000;
  34.   ofn_ShareAware                = $00004000;
  35.   ofn_NoReadOnlyReturn          = $00008000;
  36.   ofn_NoTestFileCreate          = $00010000;
  37.   ofn_NoNetworkButton           = $00020000;
  38.   ofn_NoLongNames               = $00040000;
  39.  
  40. { SHAREVISTRING Return Values }
  41.  
  42.   ofn_ShareWarn                 = 0;
  43.   ofn_ShareNoWarn               = 1;
  44.   ofn_ShareFallThrough          = 2;
  45.  
  46. { ChooseColor flag definitions }
  47.  
  48.   cc_RgbInit                    = $00000001;
  49.   cc_FullOpen                   = $00000002;
  50.   cc_PreventFullOpen            = $00000004;
  51.   cc_ShowHelp                   = $00000008;
  52.   cc_EnableHook                 = $00000010;
  53.   cc_EnableTemplate             = $00000020;
  54.   cc_EnableTemplateHandle       = $00000040;
  55.  
  56. { FindText and ReplaceText flag definitions }
  57.  
  58.   fr_Down                       = $00000001;
  59.   fr_WholeWord                  = $00000002;
  60.   fr_MatchCase                  = $00000004;
  61.   fr_FindNext                   = $00000008;
  62.   fr_Replace                    = $00000010;
  63.   fr_ReplaceAll                 = $00000020;
  64.   fr_DialogTerm                 = $00000040;
  65.   fr_ShowHelp                   = $00000080;
  66.   fr_EnableHook                 = $00000100;
  67.   fr_EnableTemplate             = $00000200;
  68.   fr_NoUpDown                   = $00000400;
  69.   fr_NoMatchCase                = $00000800;
  70.   fr_NoWholeWord                = $00001000;
  71.   fr_EnableTemplateHandle       = $00002000;
  72.   fr_HideUpDown                 = $00004000;
  73.   fr_HideMatchCase              = $00008000;
  74.   fr_HideWholeWord              = $00010000;
  75.  
  76. { ChooseFont flags }
  77.  
  78.   cf_ScreenFonts                = $00000001;
  79.   cf_PrinterFonts               = $00000002;
  80.   cf_ShowHelp                   = $00000004;
  81.   cf_EnableHook                 = $00000008;
  82.   cf_EnableTemplate             = $00000010;
  83.   cf_EnableTemplateHandle       = $00000020;
  84.   cf_InitToLogFontStruct        = $00000040;
  85.   cf_UseStyle                   = $00000080;
  86.   cf_Effects                    = $00000100;
  87.   cf_Apply                      = $00000200;
  88.   cf_AnsiOnly                   = $00000400;
  89.   cf_NoVectorFonts              = $00000800;
  90.   cf_NoSimulations              = $00001000;
  91.   cf_LimitSize                  = $00002000;
  92.   cf_FixedPitchOnly             = $00004000;
  93.   cf_Wysiwyg                    = $00008000;
  94.   cf_ForceFontExist             = $00010000;
  95.   cf_ScalableOnly               = $00020000;
  96.   cf_TtOnly                     = $00040000;
  97.   cf_NoFaceSel                  = $00080000;
  98.   cf_NoStyleSel                 = $00100000;
  99.   cf_NoSizeSel                  = $00200000;
  100.   cf_Both                       = cf_ScreenFonts or cf_PrinterFonts;
  101.   cf_NoOemFonts                 = cf_NoVectorFonts;
  102.  
  103. { Font types }
  104.  
  105.   Simulated_FontType            = $8000;
  106.   Printer_FontType              = $4000;
  107.   Screen_FontType               = $2000;
  108.   Bold_FontType                 = $0100;
  109.   Italic_FontType               = $0200;
  110.   Regular_FontType              = $0400;
  111.  
  112.   wm_ChooseFont_GetLogFont      = wm_User + 1;
  113.  
  114. { Common Dialog User Registered Messages }
  115.  
  116.   ColorOkString                 = 'commdlg_ColorOK';
  117.   FileOkString                  = 'commdlg_FileNameOK';
  118.   FindMsgString                 = 'commdlg_FindReplace';
  119.   HelpMsgString                 = 'commdlg_help';
  120.   LbSelChString                 = 'commdlg_LBSelChangedNotify';
  121.   SetRgbString                  = 'commdlg_SetRGBColor';
  122.   ShareViString                 = 'commdlg_ShareViolation';
  123.  
  124. { Values for high word of lparam of LbSelChString messages }
  125.  
  126.   cd_LbSelNoItems               = -1;
  127.   cd_LbSelChange                = 0;
  128.   cd_LbSelSub                   = 1;
  129.   cd_LbSelAdd                   = 2;
  130.  
  131. { PrintDlg options }
  132.  
  133.   pd_AllPages                   = $00000000;
  134.   pd_Selection                  = $00000001;
  135.   pd_PageNums                   = $00000002;
  136.   pd_NoSelection                = $00000004;
  137.   pd_NoPageNums                 = $00000008;
  138.   pd_Collate                    = $00000010;
  139.   pd_PrintToFile                = $00000020;
  140.   pd_PrintSetup                 = $00000040;
  141.   pd_NoWarning                  = $00000080;
  142.   pd_ReturnDC                   = $00000100;
  143.   pd_ReturnIC                   = $00000200;
  144.   pd_ReturnDefault              = $00000400;
  145.   pd_ShowHelp                   = $00000800;
  146.   pd_EnablePrintHook            = $00001000;
  147.   pd_EnableSetupHook            = $00002000;
  148.   pd_EnablePrintTemplate        = $00004000;
  149.   pd_EnableSetupTemplate        = $00008000;
  150.   pd_EnablePrintTemplateHandle  = $00010000;
  151.   pd_EnableSetupTemplateHandle  = $00020000;
  152.   pd_UseDevModeCopies           = $00040000;
  153.   pd_DisablePrintToFile         = $00080000;
  154.   pd_HidePrintToFile            = $00100000;
  155.   pd_NoNetworkButton            = $00200000;
  156.   pd_PageSetup                  = $00400000;
  157.  
  158. { Common Dialog Error Codes }
  159.  
  160.   cderr_GeneralCodes            = $0000;
  161.   cderr_StructSize              = $0001;
  162.   cderr_Initialization          = $0002;
  163.   cderr_NoTemplate              = $0003;
  164.   cderr_NoHInstance             = $0004;
  165.   cderr_LoadStrFailure          = $0005;
  166.   cderr_FindResFailure          = $0006;
  167.   cderr_LoadResFailure          = $0007;
  168.   cderr_LockResFailure          = $0008;
  169.   cderr_MemAllocFailure         = $0009;
  170.   cderr_MemLockFailure          = $000A;
  171.   cderr_NoHook                  = $000B;
  172.   cderr_RegisterMsgFail         = $000C;
  173.   pderr_PrinterCodes            = $1000;
  174.   pderr_SetupFailure            = $1001;
  175.   pderr_ParseFailure            = $1002;
  176.   pderr_RetDefFailure           = $1003;
  177.   pderr_LoadDrvFailure          = $1004;
  178.   pderr_GetDevModeFail          = $1005;
  179.   pderr_InitFailure             = $1006;
  180.   pderr_NoDevices               = $1007;
  181.   pderr_NoDefaultPrn            = $1008;
  182.   pderr_DndmMismatch            = $1009;
  183.   pderr_CreateIcFailure         = $100A;
  184.   pderr_PrinterNotFound         = $100B;
  185.   pderr_DefaultDifferent        = $100C;
  186.   cferr_ChooseFontCodes         = $2000;
  187.   cferr_NoFonts                 = $2001;
  188.   cferr_MaxLessThanMin          = $2002;
  189.   fnerr_FileNameCodes           = $3000;
  190.   fnerr_SubClassFailure         = $3001;
  191.   fnerr_InvalidFileName         = $3002;
  192.   fnerr_BufferTooSmall          = $3003;
  193.   frerr_FindReplaceCodes        = $4000;
  194.   frerr_BufferLengthZero        = $4001;
  195.   frerr_ChooseColorCodes        = $5000;
  196.   cderr_DialogFailure           = $FFFF;
  197.  
  198. type
  199.   POpenFileName = ^TOpenFileName;
  200.   TOpenFileName = packed record
  201.     lStructSize:        DWord;
  202.     hwndOwner:          HWnd;
  203.     hInstance:          HInst;
  204.     lpstrFilter:        PChar;
  205.     lpstrCustomFilter:  PChar;
  206.     nMaxCustFilter:     DWord;
  207.     nFilterIndex:       DWord;
  208.     lpstrFile:          PChar;
  209.     nMaxFile:           DWord;
  210.     lpstrFileTitle:     PChar;
  211.     nMaxFileTitle:      DWord;
  212.     lpstrInitialDir:    PChar;
  213.     lpstrTitle:         PChar;
  214.     Flags:              DWord;
  215.     nFileOffset:        SmallWord;
  216.     nFileExtension:     SmallWord;
  217.     lpstrDefExt:        PChar;
  218.     lCustData:          DWord;
  219.     lpfnHook:           TOFNHookProc;
  220.     lpTemplateName:     PChar;
  221.   end;
  222.  
  223. type
  224.   PChooseColor = ^TChooseColor;
  225.   TChooseColor = packed record
  226.     lStructSize:    DWord;
  227.     hwndOwner:      HWnd;
  228.     hInstance:      HWnd;
  229.     rgbResult:      TColorRef;
  230.     lpCustColors:   ^TColorRef;
  231.     Flags:          DWord;
  232.     lCustData:      LParam;
  233.     lpfnHook:       TCCHookProc;
  234.     lpTemplateName: PChar;
  235.   end;
  236.  
  237.   PChooseFont = ^TChooseFont;
  238.   TChooseFont = packed record
  239.     lStructSize:        DWord;
  240.     hwndOwner:          HWnd;
  241.     hDC:                HDC;
  242.     lpLogFont:          PLogFont;
  243.     iPointSize:         Integer;
  244.     Flags:              DWord;
  245.     rgbColors:          TColorRef;
  246.     lCustData:          LParam;
  247.     lpfnHook:           TCFHookProc;
  248.     lpTemplateName:     PChar;
  249.     hInstance:          HInst;
  250.     lpszStyle:          PChar;
  251.     nFontType:          SmallWord;
  252.     __MISSING_ALIGNMENT__: SmallWord;
  253.     nSizeMin:           Integer;
  254.     nSizeMax:           Integer;
  255.   end;
  256.  
  257.   PFindReplace = ^TFindReplace;
  258.   TFindReplace = packed record
  259.     lStructSize:        DWord;
  260.     hwndOwner:          HWnd;
  261.     hInstance:          HInst;
  262.     Flags:              DWord;
  263.     lpstrFindWhat:      PChar;
  264.     lpstrReplaceWith:   PChar;
  265.     wFindWhatLen:       SmallWord;
  266.     wReplaceWithLen:    SmallWord;
  267.     lCustData:          LParam;
  268.     lpfnHook:           TFRHookProc;
  269.     lpTemplateName:     PChar;
  270.   end;
  271.  
  272.   PPrintDlg = ^TPrintDlg;
  273.   TPrintDlg = packed record
  274.     lStructSize:         DWord;
  275.     hwndOwner:           HWnd;
  276.     hDevMode:            HGlobal;
  277.     hDevNames:           HGlobal;
  278.     hDC:                 HDC;
  279.     Flags:               DWord;
  280.     nFromPage:           SmallWord;
  281.     nToPage:             SmallWord;
  282.     nMinPage:            SmallWord;
  283.     nMaxPage:            SmallWord;
  284.     nCopies:             SmallWord;
  285.     hInstance:           HInst;
  286.     lCustData:           LParam;
  287.     lpfnPrintHook:       TPrintHookProc;
  288.     lpfnSetupHook:       TSetupHookProc;
  289.     lpPrintTemplateName: PChar;
  290.     lpSetupTemplateName: PChar;
  291.     hPrintTemplate:      HGlobal;
  292.     hSetupTemplate:      HGlobal;
  293.   end;
  294.  
  295.   PDevNames = ^TDevNames;
  296.   TDevNames = packed record
  297.     wDriverOffset: SmallWord;
  298.     wDeviceOffset: SmallWord;
  299.     wOutputOffset: SmallWord;
  300.     wDefault:      SmallWord;
  301.   end;
  302.  
  303. function ChooseColor(var CC: TChooseColor): Bool;
  304. function ChooseFont(var ChooseFont: TChooseFont): Bool;
  305. function CommDlgExtendedError: DWord;
  306. function FindText(var FindReplace: TFindReplace): HWnd;
  307. function GetFileTitle(FileName,Title: PChar; TitleSize: SmallWord): SmallInt;
  308. function GetOpenFileName(var OpenFile: TOpenFilename): Bool;
  309. function GetSaveFileName(var SaveFile: TOpenFilename): Bool;
  310. function PrintDlg(var PrintDlg: TPrintDlg): Bool;
  311. function ReplaceText(var FindReplace: TFindReplace): HWnd;
  312.  
  313. { What is not supported by Open32 }
  314.  
  315. const
  316.   ofn_Explorer                  = $00080000;
  317.   ofn_NoDereferenceLinks        = $00100000;
  318.  
  319.   cc_SolidColor                 = $00000080;
  320.   cc_AnyColor                   = $00000100;
  321.  
  322. {$IFNDEF Open32}
  323.  
  324. type // function used for callback hooks
  325.   TMessageHookFn = function(Wnd: HWnd; Message: UInt; wParam: WParam; lParam: LParam): UInt;
  326.  
  327. const
  328.   ofn_LongNames = $00200000;
  329.  
  330. // Return values for the registered message sent to the hook function
  331. // when a sharing violation occurs.  ofn_ShareFallThrough allows the
  332. // filename to be accepted, ofn_ShareNoWarn rejects the name but puts
  333. // up no warning (returned when the app has already put up a warning
  334. // message), and ofn_ShareWarn puts up the default warning message
  335. // for sharing violations.
  336.  
  337. //  Note:  Undefined return values map to ofn_ShareWarn, but are
  338. //         reserved for future use.
  339.  
  340.  
  341. type
  342.   POFNotify = ^TOFNotify;
  343.   TOFNotify = packed record
  344.     hdr: TNMHdr;
  345.     lpOFN: POpenFilename;
  346.     pszFile: PChar;
  347.   end;
  348.  
  349. const
  350.   cdn_First = -601;
  351.   cdn_Last = -699;
  352.  
  353. // Notifications when Open or Save dialog status changes
  354.  
  355.   cdn_InitDone = cdn_First - 0;
  356.   cdn_SelChange = cdn_First - 1;
  357.   cdn_FolderChange = cdn_First - 2;
  358.   cdn_ShareViolation = cdn_First - 3;
  359.   cdn_Help = cdn_First - 4;
  360.   cdn_FileOk = cdn_First - 5;
  361.   cdn_TypeChange = cdn_First - 6;
  362.  
  363.   cdm_First = WM_User + 100;
  364.   cdm_Last = WM_User + 200;
  365.  
  366. // Messages to query information from the Open or Save dialogs
  367.  
  368. // lParam = pointer to text buffer that gets filled in
  369. // wParam = max number of characters of the text buffer (including NULL)
  370. // return = < 0 if error; number of characters needed (including NULL)
  371.  
  372.   cdm_GetSpec = cdm_First + 0;
  373.  
  374. // lParam = pointer to text buffer that gets filled in
  375. // wParam = max number of characters of the text buffer (including NULL)
  376. // return = < 0 if error; number of characters needed (including NULL)
  377.  
  378.   cdm_GetFilePath = cdm_First + 1;
  379.  
  380. // lParam = pointer to text buffer that gets filled in
  381. // wParam = max number of characters of the text buffer (including NULL)
  382. // return = < 0 if error; number of characters needed (including NULL)
  383.  
  384.   cdm_GetFolderPath = cdm_First + 2;
  385.  
  386. // lParam = pointer to ItemIdList buffer that gets filled in
  387. // wParam = size of the ItemIdList buffer
  388. // return = < 0 if error; length of buffer needed
  389.  
  390.   cdm_GetFolderIdList = cdm_First + 3;
  391.  
  392. // lParam = pointer to a string
  393. // wParam = ID of control to change
  394. // return = not used
  395.  
  396.   cdm_SetControlText = cdm_First + 4;
  397.  
  398. // lParam = not used
  399. // wParam = ID of control to change
  400. // return = not used
  401.  
  402.   cdm_HideControl = cdm_First + 5;
  403.  
  404. // lParam = pointer to default extension (no dot)
  405. // wParam = not used
  406. // return = not used
  407.  
  408.   cdm_SetDefExt = cdm_First + 6;
  409.  
  410. const
  411.   cf_ScriptsOnly = cf_ANSIOnly;
  412.   cf_SelectScript = $00400000;
  413.   cf_NoScriptSel = $00800000;
  414.   cf_NoVertFonts = $01000000;
  415.  
  416. // these are extra nFontType bits that are added to what is returned to the
  417. // EnumFonts callback routine
  418.  
  419.   wm_ChooseFont_SetLogFont = WM_User + 101;
  420.   wm_ChooseFont_SetFlags = WM_User + 102;
  421.  
  422. // HiWord values for lParam of commdlg_LBSelChangeNotify message
  423.  
  424. const
  425.   pd_UseDevModeCopiesAndCollate = $00040000;
  426.  
  427. const
  428.   dn_DefaultPrn = $0001;
  429.  
  430. const
  431.   wm_psd_PageSetupDlg     = WM_User;
  432.   wm_psd_FullPageRect     = WM_User + 1;
  433.   wm_psd_MinMarginRect    = WM_User + 2;
  434.   wm_psd_MarginRect       = WM_User + 3;
  435.   wm_psd_GreekTextRect    = WM_User + 4;
  436.   wm_psd_EnvStampRect     = WM_User + 5;
  437.   wm_psd_YaFullPageRect   = WM_User + 6;
  438.  
  439. type
  440.   PPageSetupDlg = ^TPageSetupDlg;
  441.   TPageSetupDlg = packed record
  442.     lStructSize: DWord;
  443.     hwndOwner: HWnd;
  444.     hDevMode: HGlobal;
  445.     hDevNames: HGlobal;
  446.     Flags: DWord;
  447.     ptPaperSize: TPoint;
  448.     rtMinMargin: TRect;
  449.     rtMargin: TRect;
  450.     hInstance: HInst;
  451.     lCustData: LParam;
  452.     lpfnPageSetupHook: TMessageHookFn;
  453.     lpfnPagePaintHook: TMessageHookFn;
  454.     lpPageSetupTemplateName: PChar;
  455.     hPageSetupTemplate: HGlobal;
  456.   end;
  457.  
  458. function PageSetupDlg(var PgSetupDialog: TPageSetupDlg): Bool;
  459.  
  460. const
  461.   psd_DefaultMinMargins             = $00000000; // default (printer's)
  462.   psd_InWinIniIntlMeasure           = $00000000; // 1st of 4 possible
  463.  
  464.   psd_MinMargins                    = $00000001; // use caller's
  465.   psd_Margins                       = $00000002; // use caller's
  466.   psd_InThousandthsOfInches         = $00000004; // 2nd of 4 possible
  467.   psd_InHundredthsOfMillimeters     = $00000008; // 3rd of 4 possible
  468.   psd_DisableMargins                = $00000010;
  469.   psd_DisablePrinter                = $00000020;
  470.   psd_NoWarning                     = $00000080; // must be same as PD_*
  471.   psd_DisableOrientation            = $00000100;
  472.   psd_ReturnDefault                 = $00000400; // must be same as PD_*
  473.   psd_DisablePaper                  = $00000200;
  474.   psd_ShowHelp                      = $00000800; // must be same as PD_*
  475.   psd_EnablePageSetupHook           = $00002000; // must be same as PD_*
  476.   psd_EnablePageSetupTemplate       = $00008000; // must be same as PD_*
  477.   psd_EnablePageSetupTemplateHandle = $00020000; // must be same as PD_*
  478.   psd_EnablePagePaintHook           = $00040000;
  479.   psd_DisablePagePainting           = $00080000;
  480.  
  481.  
  482. // Common dialog error return codes
  483.  
  484. const
  485.   CcErr_ChooseColorCodes = $5000;
  486.  
  487. {$ENDIF Open32}
  488.  
  489. implementation
  490.  
  491. function GetOpenFileName;       external;
  492. function GetSaveFileName;       external;
  493. function GetFileTitle;          external;
  494. function ChooseColor;           external;
  495. function FindText;              external;
  496. function ReplaceText;           external;
  497. function ChooseFont;            external;
  498. function PrintDlg;              external;
  499. function CommDlgExtendedError;  external;
  500.  
  501. {$IFNDEF Open32}
  502. function PageSetupDlg;          external;
  503. {$ENDIF  Open32}
  504.  
  505. end.
  506.