home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol11n19.zip / COMMDLG.PAS < prev    next >
Pascal/Delphi Source File  |  1992-06-30  |  12KB  |  357 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal for Windows                        }
  5. {       Windows 3.1 API Interface Unit                  }
  6. {                                                       }
  7. {       Copyright (c) 1992 Borland International        }
  8. {                                                       }
  9. {    Used by PC Magazine with permission of Borland     }
  10. {                                                       }
  11. {*******************************************************}
  12.  
  13. unit CommDlg;
  14.  
  15. interface
  16.  
  17. uses WinTypes;
  18.  
  19. type
  20.   POpenFilename = ^TOpenFilename;
  21.   TOpenFilename = record
  22.     lStructSize: Longint;
  23.     hWndOwner: HWnd;
  24.     hInstance: THandle;
  25.     lpstrFilter: PChar;
  26.     lpstrCustomFilter: PChar;
  27.     nMaxCustFilter: Longint;
  28.     nFilterIndex: Longint;
  29.     lpstrFile: PChar;
  30.     nMaxFile: Longint;
  31.     lpstrFileTitle: PChar;
  32.     nMaxFileTitle: Longint;
  33.     lpstrInitialDir: PChar;
  34.     lpstrTitle: PChar;
  35.     Flags: Longint;
  36.     nFileOffset: Word;
  37.     nFileExtension: Word;
  38.     lpstrDefExt: PChar;
  39.     lCustData: Longint;
  40.     lpfnHook: function (Wnd: HWnd; Msg, wParam: Word; lParam: Longint): Word;
  41.     lpTemplateName: PChar;
  42.   end;
  43.  
  44. function GetOpenFileName(var OpenFile: TOpenFilename): Bool;
  45. function GetSaveFileName(var OpenFile: TOpenFilename): Bool;
  46. function GetFileTitle(FileName, Title: PChar; TitleSize: Word): Integer;
  47.  
  48. const
  49.   ofn_ReadOnly = $00000001;
  50.   ofn_OverWritePrompt = $00000002;
  51.   ofn_HideReadOnly = $00000004;
  52.   ofn_NoChangeDir = $00000008;
  53.   ofn_ShowHelp = $00000010;
  54.   ofn_EnableHook = $00000020;
  55.   ofn_EnableTemplate = $00000040;
  56.   ofn_EnableTemplateHandle = $00000080;
  57.   ofn_NoValidate = $00000100;
  58.   ofn_AllowMultiSelect = $00000200;
  59.   ofn_ExtentionDifferent = $00000400;
  60.   ofn_PathMustExist = $00000800;
  61.   ofn_FileMustExist = $00001000;
  62.   ofn_CreatePrompt = $00002000;
  63.   ofn_ShareAware = $00004000;
  64.   ofn_NoReadOnlyReturn = $00008000;
  65.   ofn_NoTextFileCreate = $00010000;
  66.  
  67. { Return values for the registered message sent to the hook function
  68.   when a sharing violation occurs.  ofn_ShareFallThrough allows the
  69.   filename to be accepted, ofn_ShareNoWarn rejects the name but puts
  70.   up no warning (returned when the app has already put up a warning
  71.   message), and ofn_ShareWarn puts up the default warning message
  72.   for sharing violations.
  73.  
  74.   Note:  Undefined return values map to ofn_ShareWarn. }
  75.  
  76.   ofn_ShareFallThrough = 2;
  77.   ofn_ShareNoWarn = 1;
  78.   ofn_ShareWarn = 0;
  79.  
  80. type
  81.   PChooseColor = ^TChooseColor;
  82.   TChooseColor = record
  83.     lStructSize: Longint;
  84.     hWndOwner: HWnd;
  85.     hInstance: HWnd;
  86.     rgbResult: Longint;
  87.     lpCustColors: PLongint;
  88.     Flags: Longint;
  89.     lCustData: Longint;
  90.     lpfnHook: function (Wnd: HWnd; Message, wParam: Word;
  91.      lParam: Longint): Word;
  92.     lpTemplateName: PChar;
  93.   end;
  94.  
  95. function ChooseColor(var CC: TChooseColor): Bool;
  96.  
  97. const
  98.   cc_RGBInit = $00000001;
  99.   cc_FullOpen = $00000002;
  100.   cc_PreventFullOpen = $00000004;
  101.   cc_ShowHelp = $00000008;
  102.   cc_EnableHook = $00000010;
  103.   cc_EnableTemplate = $00000020;
  104.   cc_EnableTemplateHandle = $00000040;
  105.  
  106. type
  107.   PFindReplace = ^TFindReplace;
  108.   TFindReplace = record
  109.     lStructSize: Longint;        { size of this struct $20 }
  110.     hWndOwner: HWnd;              { handle to owner's window }
  111.     hInstance: THandle;           { instance handle of.EXE that
  112.                                    contains cust. dlg. template }
  113.     Flags: Longint;              { one or more of the fr_?? }
  114.     lpstrFindWhat: PChar;        { ptr. to search string    }
  115.     lpstrReplaceWith: PChar;     { ptr. to replace string   }
  116.     wFindWhatLen: Word;          { size of find buffer      }
  117.     wReplaceWithLen: Word;       { size of replace buffer   }
  118.     lCustData: Longint;          { data passed to hook fn.  }
  119.     lpfnHook: function (Wnd: HWnd; Msg, wParam: Word; lParam: Longint): Word;
  120.                                  { ptr. to hook fn. or nil }
  121.     lpTemplateName: PChar;       { custom template name     }
  122.   end;
  123.  
  124. const
  125.   fr_Down = $00000001;
  126.   fr_WholeWord = $00000002;
  127.   fr_MatchCase = $00000004;
  128.   fr_FindNext = $00000008;
  129.   fr_Replace = $00000010;
  130.   fr_ReplaceAll = $00000020;
  131.   fr_DialogTerm = $00000040;
  132.   fr_ShowHelp = $00000080;
  133.   fr_EnableHook = $00000100;
  134.   fr_EnableTemplate = $00000200;
  135.   fr_NoUpDown = $00000400;
  136.   fr_NoMatchCase = $00000800;
  137.   fr_NoWholeWord = $00001000;
  138.   fr_EnableTemplateHandle = $00002000;
  139.   fr_HideUpDown = $00004000;
  140.   fr_HideMatchCase = $00008000;
  141.   fr_HideWholeWord = $00010000;
  142.  
  143. function FindText(var FindReplace: TFindReplace): HWnd;
  144. function ReplaceText(var FindReplace: TFindReplace): HWnd;
  145.  
  146. type
  147.   PChooseFont = ^TChooseFont;
  148.   TChooseFont = record
  149.     lStructSize: Longint;       { }
  150.     hWndOwner: HWnd;             { caller's window handle   }
  151.     hDC: HDC;                    { printer DC/IC or nil    }
  152.     lpLogFont: PLogFont;        { ptr. to a LOGFONT struct }
  153.     iPointSize: Integer;                { 10 * size in points of selected font }
  154.     Flags: Longint;             { enum. type flags          }
  155.     rgbColors: Longint;         { returned text color       }
  156.     lCustData: Longint;         { data passed to hook fn.  }
  157.     lpfnHook: function (Wnd: HWnd; Msg, wParam: Word; lParam: Longint): Word;
  158.                                 { ptr. to hook function    }
  159.     lpTemplateName: PChar;      { custom template name     }
  160.     hInstance: THandle;          { instance handle of.EXE that
  161.                                   contains cust. dlg. template }
  162.     lpszStyle: PChar;           { return the style field here
  163.                                   must be lf_FaceSize or bigger }
  164.     nFontType: Word;            { same value reported to the EnumFonts
  165.                                   call back with the extra fonttype_
  166.                                   bits added }
  167.     nSizeMin: Integer;          { minimum pt size allowed & }
  168.     nSizeMax: Integer;          { max pt size allowed if
  169.                                   cf_LimitSize is used      }
  170.   end;
  171.  
  172. function ChooseFont(var ChooseFond: TChooseFont): Bool;
  173.  
  174. const
  175.   cf_ScreenFonts = $00000001;
  176.   cf_PrinterFonts = $00000002;
  177.   cf_Both = cf_ScreenFonts or cf_PrinterFonts;
  178.   cf_ShowHelp = $00000004;
  179.   cf_EnableHook = $00000008;
  180.   cf_EnableTemplate = $00000010;
  181.   cf_EnableTemplateHandle = $00000020;
  182.   cf_InitToLogfontStruct = $00000040;
  183.   cf_UseStyle = $00000080;
  184.   cf_Effects = $00000100;
  185.   cf_Apply = $00000200;
  186.   cf_AnsiOnly = $00000400;
  187.   cf_NoVectorFonts = $00000800;
  188.   cf_NoOEMFonts = cf_NoVectorFonts;
  189.   cf_NoSimulations = $00001000;
  190.   cf_LimitSize = $00002000;
  191.   cf_FixedPitchOnly = $00004000;
  192.   cf_WYSIWYG = $00008000; { must also have cf_ScreenFonts & cf_PrinterFonts }
  193.   cf_ForceFontExist = $00010000;
  194.   cf_ScalableOnly = $00020000;
  195.   cf_TTOnly = $00040000;
  196.   cf_NoFaceSel = $00080000;
  197.   cf_NoStyleSel = $00100000;
  198.   cf_NoSizeSel = $00200000;
  199.  
  200. { these are extra nFontType bits that are added to what is returned to the
  201.   EnumFonts callback routine }
  202.  
  203.   Simulated_FontType = $8000;
  204.   Printer_FontType = $4000;
  205.   Screen_FontType = $2000;
  206.   Bold_FontType = $0100;
  207.   Italic_FontType = $0200;
  208.   Regular_FontType = $0400;
  209.  
  210.   wm_ChooseFont_GetLogfont = wm_User + 1;
  211.  
  212.  
  213. { strings used to obtain unique window message for communication
  214.   between dialog and caller }
  215.  
  216.   LBSelChString = 'commdlg_LBSelChangedNotify';
  217.   ShareViString = 'commdlg_ShareViolation';
  218.   FileOKString = 'commdlg_FileNameOK';
  219.   ColorOKString = 'commdlg_ColorOK';
  220.   SetRGBString = 'commdlg_SetRGBColor';
  221.   FindMsgString = 'commdlg_FindReplace';
  222.   HelpMsgString = 'commdlg_help';
  223.  
  224. { HIWORD values for lParam of commdlg_LBSelChangeNotify message }
  225.  
  226. const
  227.   cd_LBSelNoItems = -1;
  228.   cd_LBSelChange  = 0;
  229.   cd_LBSELSUB     = 1;
  230.   cd_LBSelAdd     = 2;
  231.  
  232. type
  233.   PPrintDlg = ^TPrintDlg;
  234.   TPrintDlg = record
  235.     lStructSize: Longint;
  236.     hWndOwner: HWnd;
  237.     hDevMode: THandle;
  238.     hDevNames: THandle;
  239.     hDC: HDC;
  240.     Flags: Longint;
  241.     nFromPage: Word;
  242.     nToPage: Word;
  243.     nMinPage: Word;
  244.     nMaxPage: Word;
  245.     nCopies: Word;
  246.     hInstance: THandle;
  247.     lCustData: Longint;
  248.     lpfnPrintHook: function (Wnd: HWnd; Msg, wParam: Word;
  249.       lParam: Longint): Integer;
  250.     lpfnSetupHook: function (Wnd: HWnd; Msg, wParam: Word;
  251.       lParam: Longint): Integer;
  252.     lpPrintTemplateName: PChar;
  253.     lpSetupTemplateName: PChar;
  254.     hPrintTemplate: THandle;
  255.     hSetupTemplate: THandle;
  256.   end;
  257.  
  258. function PrintDlg(var PrintDlg: TPrintDlg): Bool;
  259.  
  260. const
  261.   pd_AllPages = $00000000;
  262.   pd_Selection = $00000001;
  263.   pd_PageNums = $00000002;
  264.   pd_NoSelection = $00000004;
  265.   pd_NoPageNums = $00000008;
  266.   pd_Collate = $00000010;
  267.   pd_PrintToFile = $00000020;
  268.   pd_PrintSetup = $00000040;
  269.   pd_NoWarning = $00000080;
  270.   pd_ReturnDC = $00000100;
  271.   pd_ReturnIC = $00000200;
  272.   pd_ReturnDefault = $00000400;
  273.   pd_ShowHelp = $00000800;
  274.   pd_EnablePrintHook = $00001000;
  275.   pd_EnableSetupHook = $00002000;
  276.   pd_EnablePrintTemplate = $00004000;
  277.   pd_EnableSetupTemplate = $00008000;
  278.   pd_EnablePrintTemplateTHandle = $00010000;
  279.   pd_EnableSetupTemplateTHandle = $00020000;
  280.   pd_UseDevModeCopies = $00040000;
  281.   pd_DisablePrintToFile = $00080000;
  282.   pd_HidePrintToFile = $00100000;
  283.  
  284. type
  285.   PDevNames = ^TDevNames;
  286.   TDevNames = record
  287.     wDriverOffset: Word;
  288.     wDeviceOffset: Word;
  289.     wOutputOffset: Word;
  290.     wDefault: Word;
  291.   end;
  292.  
  293. const
  294.   dn_DefaultPrn = $0001;
  295.  
  296. function CommDlgExtendedError: Longint;
  297.  
  298. const
  299.   cderr_DialogFailure    = $FFFF;
  300.  
  301.   cderr_GeneralCodes     = $0000;
  302.   cderr_StructSize       = $0001;
  303.   cderr_Initialization   = $0002;
  304.   cderr_NoTemplate       = $0003;
  305.   cderr_NoHInstance      = $0004;
  306.   cderr_LoadStrFailure   = $0005;
  307.   cderr_FindResFailure   = $0006;
  308.   cderr_LoadResFailure   = $0007;
  309.   cderr_LockResFailure   = $0008;
  310.   cderr_MemAllocFailure  = $0009;
  311.   cderr_MemLockFailure   = $000A;
  312.   cderr_NoHook           = $000B;
  313.   cderr_RegisterMsgFail  = $000C;
  314.  
  315.   pderr_PrinterCodes     = $1000;
  316.   pderr_SetupFailure     = $1001;
  317.   pderr_ParseFailure     = $1002;
  318.   pderr_RetDefFailure    = $1003;
  319.   pderr_LoadDrvFailure   = $1004;
  320.   pderr_GetDevModeFail   = $1005;
  321.   pderr_InitFailure      = $1006;
  322.   pderr_NoDevices        = $1007;
  323.   pderr_NoDefaultPrn     = $1008;
  324.   pderr_DNDMMismatch     = $1009;
  325.   pderr_CreateICFailure  = $100A;
  326.   pderr_PrinterNotFound  = $100B;
  327.   pderr_DefaultDifferent = $100C;
  328.  
  329.   cferr_ChooseFontCodes  = $2000;
  330.   cferr_NoFonts          = $2001;
  331.   cferr_MaxLessThanMin   = $2002;
  332.  
  333.   fnErr_FilenameCodes    = $3000;
  334.   fnErr_SubclassFailure  = $3001;
  335.   fnErr_InvalidFilename  = $3002;
  336.   fnErr_BufferTooSmall   = $3003;
  337.  
  338.   frErr_FindReplaceCodes = $4000;
  339.   frErr_BufferLengthZero = $4001;
  340.  
  341.   ccErr_ChooseColorCodes = $5000;
  342.  
  343. implementation
  344.  
  345. function GetOpenFileName;                  external 'COMMDLG'  index 1;
  346. function GetSaveFileName;                  external 'COMMDLG'  index 2;
  347. function GetFileTitle;                     external 'COMMDLG'  index 27;
  348. function ChooseColor;                      external 'COMMDLG'  index 5;
  349. function FindText;                         external 'COMMDLG'  index 11;
  350. function ReplaceText;                      external 'COMMDLG'  index 12;
  351. function ChooseFont;                       external 'COMMDLG'  index 15;
  352. function PrintDlg;                         external 'COMMDLG'  index 20;
  353. function CommDlgExtendedError;             external 'COMMDLG'  index 26;
  354.  
  355. end.
  356.  
  357.