home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / WRTLSRC.RAR / SHELLAPI.PAS < prev    next >
Pascal/Delphi Source File  |  2000-09-07  |  11KB  |  317 lines

  1. //█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  2. //█                                                      █
  3. //█     Virtual Pascal Runtime Library.  Version 2.1     █
  4. //█     Windows Shell API interface unit                 █
  5. //█     ─────────────────────────────────────────────────█
  6. //█     Copyright (C) 1998-2000 vpascal.com              █
  7. //█                                                      █
  8. //▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  9.  
  10.  
  11. unit ShellAPI;
  12.  
  13. {&AlignRec+,StdCall+,SmartLink+,OrgName+,Use32-}
  14.  
  15. interface
  16.  
  17. uses Windows;
  18.  
  19. type
  20.   HDrop = Longint;
  21.  
  22. function DragQueryFile(Drop: HDrop; FileIndex: UInt; FileName: PChar; cb: UInt): UInt;
  23. function DragQueryPoint(Drop: HDrop; var Point: TPoint): Bool;
  24. procedure DragFinish(Drop: HDrop);
  25. procedure DragAcceptFiles(Wnd: HWnd; Accept: Bool);
  26. function ShellExecute(HWnd: HWnd; Operation, FileName, Parameters,
  27.   Directory: PChar; ShowCmd: Integer): HInst;
  28. function FindExecutable(FileName, Directory: PChar; Result: PChar): HInst;
  29. function CommandLineToArgvW(lpCmdLine: LPCWSTR; var pNumArgs: Integer): Pointer;
  30. function ShellAbout(Wnd: HWnd; szApp, szOtherStuff: PChar; Icon: HIcon): Integer;
  31. function DuplicateIcon(hInst: HInst; Icon: HIcon): HIcon;
  32. function ExtractAssociatedIcon(hInst: HInst; lpIconPath: PChar;
  33.   var lpiIcon: Word): HIcon;
  34. function ExtractIcon(hInst: HInst; lpszExeFileName: PChar;
  35.   nIconIndex: UInt): HIcon;
  36.  
  37. type
  38.   PDragInfo = ^TDragInfo;
  39.   TDragInfo = record
  40.     uSize:       UInt;    // init with SizeOf(TDragInfo)
  41.     pt:          TPoint;
  42.     fNC:         Bool;
  43.     lpFileList:  PChar;
  44.     grfKeyState: DWord;
  45.   end;
  46.  
  47. const
  48. // AppBar stuff
  49.   abm_New               = $00000000;
  50.   abm_Remove            = $00000001;
  51.   abm_QueryPos          = $00000002;
  52.   abm_SetPos            = $00000003;
  53.   abm_GetState          = $00000004;
  54.   abm_GetTaskBarPos     = $00000005;
  55.   abm_Activate          = $00000006;  // lParam = True/False means activate/deactivate
  56.   abm_GetAutoHideBar    = $00000007;
  57.   abm_SetAutoHideBar    = $00000008;  // this can fail at any time.  MUST check the result lParam = TRUE/FALSE Set/Unset uEdge = what edge
  58.   abm_WindowPosChanged  = $00000009;
  59.  
  60. // these are put in the wparam of callback messages
  61.  
  62.   abn_StateChange       = $00000000;
  63.   abn_PosChanged        = $00000001;
  64.   abn_FullScreenApp     = $00000002;
  65.   abn_WindowArrange     = $00000003; // lParam = True means hide
  66.  
  67. // flags for get state
  68.  
  69.   abs_AutoHide          = $00000001;
  70.   abs_AlwaysOnTop       = $00000002;
  71.  
  72.   abe_Left              = 0;
  73.   abe_Top               = 1;
  74.   abe_Right             = 2;
  75.   abe_Bottom            = 3;
  76.  
  77. type
  78.   PAppBarData = ^TAppBarData;
  79.   TAppBarData = record
  80.     cbSize:           DWord;
  81.     HWnd:             HWnd;
  82.     uCallbackMessage: UInt;
  83.     uEdge:            UInt;
  84.     rc:               TRect;
  85.     lParam:           LParam; // message specific
  86.   end;
  87.  
  88. function SHAppBarMessage(dwMessage: DWord; var pData: TAppBarData): UInt;
  89.  
  90.  
  91. function DoEnvironmentSubst(szString: PChar; cbString: UInt): DWord;
  92. function ExtractIconEx(lpszFile: PChar; nIconIndex: Integer; var phiconLarge, phiconSmall: HIcon; nIcons: UInt): UInt;
  93.  
  94.  
  95. // Shell File Operations
  96.  
  97. const
  98.   fo_Move               = $0001;
  99.   fo_Copy               = $0002;
  100.   fo_Delete             = $0003;
  101.   fo_Rename             = $0004;
  102.  
  103.   fof_MultiDestFiles    = $0001;
  104.   fof_ConfirmMouse      = $0002;
  105.   fof_Silent            = $0004;  // don't create progress/report
  106.   fof_RenameOnCollision = $0008;
  107.   fof_NoConfirmation    = $0010;  // Don't prompt the user.
  108.   fof_WantMappingHandle = $0020;  // Fill in SHFILEOPSTRUCT.hNameMappings Must be freed using SHFreeNameMappings
  109.   fof_AllowUndo         = $0040;
  110.   fof_FilesOnly         = $0080;  // on *.*, do only files
  111.   fof_SimpleProgress    = $0100;  // means don't show names of files
  112.   fof_NoConfirmMkdir    = $0200;  // don't confirm making any needed dirs
  113.  
  114. type
  115.   fileop_Flags = Word;
  116.  
  117. const
  118.   po_Delete             = $0013;  // printer is being deleted
  119.   po_Rename             = $0014;  // printer is being renamed
  120.   po_PortChange         = $0020;  // port this printer connected to is being changed if this id is set, the strings received by the copyhook are a doubly-null terminated list of strings. The first is the printer name and the second is the printer port.
  121.   po_Ren_Port           = $0034;  // po_Rename and po_PortChange at same time.
  122.  
  123. // no pof_ flags currently defined
  124.  
  125. type
  126.   printerOp_Flags = Word;
  127.  
  128. // implicit parameters are:
  129. //    if pFrom or pTo are unqualified names the current directories are
  130. //    taken from the global current drive/directory settings managed
  131. //    by Get/SetCurrentDrive/Directory
  132. //
  133. //    the global confirmation settings
  134.  
  135.   PSHFileOpStruct = ^TSHFileOpStruct;
  136.   TSHFileOpStruct = record
  137.     Wnd:                   HWnd;
  138.     wFunc:                 UInt;
  139.     pFrom:                 PChar;
  140.     pTo:                   PChar;
  141.     fFlags:                fileop_Flags;
  142.     fAnyOperationsAborted: Bool;
  143.     hNameMappings:         Pointer;
  144.     lpszProgressTitle:     PChar; // only used if fof_SimpleProgress
  145.   end;
  146.  
  147. function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer;
  148. procedure SHFreeNameMappings(hNameMappings: THandle);
  149.  
  150. type
  151.   PSHNameMapping = ^TSHNameMapping;
  152.   TSHNameMapping = record
  153.     pszOldPath: PChar;
  154.     pszNewPath: PChar;
  155.     cchOldPath: Integer;
  156.     cchNewPath: Integer;
  157.   end;
  158.  
  159. // ShellExecute() and ShellExecuteEx() error codes
  160. const
  161. // regular WinExec() codes
  162.   se_err_FNF            = 2;   // file not found
  163.   se_err_PNF            = 3;   // path not found
  164.   se_err_AccessDenied   = 5;   // access denied
  165.   se_err_OOM            = 8;   // out of memory
  166.   se_err_DLLNotFound    = 32;
  167.  
  168. // error values for ShellExecute() beyond the regular WinExec() codes
  169.   se_err_Share          = 26;
  170.   se_err_AssocIncomplete= 27;
  171.   se_err_DDETimeout     = 28;
  172.   se_err_DDEFail        = 29;
  173.   se_err_DDEBusy        = 30;
  174.   se_err_NoAssoc        = 31;
  175.  
  176. // Note CLASSKEY overrides CLASSNAME
  177.   see_mask_ClassName    = $00000001;
  178.   see_mask_ClassKey     = $00000003;
  179. // Note INVOKEIDLIST overrides IDLIST
  180.   see_mask_IdList       = $00000004;
  181.   see_mask_InvokeIdList = $0000000c;
  182.   see_mask_Icon         = $00000010;
  183.   see_mask_HotKey       = $00000020;
  184.   see_mask_NoCloseProcess = $00000040;
  185.   see_mask_ConnectNetDrv= $00000080;
  186.   see_mask_Flag_DDEWait = $00000100;
  187.   see_mask_DoEnvSubst   = $00000200;
  188.   see_mask_Flag_No_UI   = $00000400;
  189.   see_mask_Unicode      = $00010000;
  190.  
  191. type
  192.   PShellExecuteInfo = ^TShellExecuteInfo;
  193.   TShellExecuteInfo = record
  194.     cbSize:         DWord;
  195.     fMask:          ULong;
  196.     Wnd:            HWnd;
  197.     lpVerb:         PChar;
  198.     lpFile:         PChar;
  199.     lpParameters:   PChar;
  200.     lpDirectory:    PChar;
  201.     nShow:          Integer;
  202.     hInstApp:       HInst;
  203.     // Optional fields
  204.     lpIDList:       Pointer;
  205.     lpClass:        PChar;
  206.     hkeyClass:      HKey;
  207.     dwHotKey:       DWord;
  208.     hIcon:          THandle;
  209.     hProcess:       THandle;
  210.   end;
  211.  
  212. function ShellExecuteEx(lpExecInfo: PShellExecuteInfo):Bool;
  213.  
  214. // Tray notification definitions
  215.  
  216. type
  217.   PNotifyIconData = ^TNotifyIconData;
  218.   TNotifyIconData = record
  219.     cbSize:           DWord;
  220.     Wnd:              HWnd;
  221.     uID:              UInt;
  222.     uFlags:           UInt;
  223.     uCallbackMessage: UInt;
  224.     hIcon:            HIcon;
  225.     szTip: array [0..63] of Char;
  226.   end;
  227.  
  228. const
  229.   nim_Add               = $00000000;
  230.   nim_Modify            = $00000001;
  231.   nim_Delete            = $00000002;
  232.  
  233.   nif_Message           = $00000001;
  234.   nif_Icon              = $00000002;
  235.   nif_Tip               = $00000004;
  236.  
  237. function Shell_NotifyIcon(dwMessage: DWord; lpData: PNotifyIconData): Bool;
  238.  
  239. // Begin SHGetFileInfo
  240.  
  241. // The SHGetFileInfo API provides an easy way to get attributes
  242. // for a file given a pathname.
  243. //
  244. //   PARAMETERS
  245. //
  246. //     pszPath              file name to get info about
  247. //     dwFileAttributes     file attribs, only used with SHGFI_USEFILEATTRIBUTES
  248. //     psfi                 place to return file info
  249. //     cbFileInfo           size of structure
  250. //     uFlags               flags
  251. //
  252. //   RETURN
  253. //     TRUE if things worked
  254.  
  255. type
  256.   PSHFileInfo = ^TSHFileInfo;
  257.   TSHFileInfo = record
  258.     hIcon:          HIcon;                         // out: icon
  259.     iIcon:          Integer;                       // out: icon index
  260.     dwAttributes:   DWord;                         // out: SFGAO_ flags
  261.     szDisplayName:  array [0..max_Path-1] of Char; // out: display name (or path)
  262.     szTypeName:     array [0..79] of Char;         // out: type name
  263.   end;
  264.  
  265. const
  266.   shgfi_Icon            = $000000100;   // get icon
  267.   shgfi_DisplayName     = $000000200;   // get display name
  268.   shgfi_TypeName        = $000000400;   // get type name
  269.   shgfi_Attributes      = $000000800;   // get attributes
  270.   shgfi_IconLocation    = $000001000;   // get icon location
  271.   shgfi_ExeType         = $000002000;   // return exe type
  272.   shgfi_SysIconIndex    = $000004000;   // get system icon index
  273.   shgfi_LinkOverlay     = $000008000;   // put a link overlay on icon
  274.   shgfi_Selected        = $000010000;   // show icon in selected state
  275.   shgfi_LargeIcon       = $000000000;   // get large icon
  276.   shgfi_SmallIcon       = $000000001;   // get small icon
  277.   shgfi_OpenIcon        = $000000002;   // get open icon
  278.   shgfi_ShellIconsize   = $000000004;   // get shell size icon
  279.   shgfi_Pidl            = $000000008;   // pszPath is a pidl
  280.   shgfi_UseFileAttributes = $000000010; // use passed dwFileAttribute
  281.  
  282. function SHGetFileInfo(pszPath: PChar; dwFileAttributes: DWord;
  283.   var psfi: TSHFileInfo; cbFileInfo, uFlags: UInt): DWord;
  284. function SHGetNewLinkInfo(pszLinkTo, pszDir: PChar; pszName: PChar;
  285.   var pfMustCopy: Bool; uFlags: UInt): Bool;
  286.  
  287. const
  288.   shgnli_Pidl           = $000000001;  // pszLinkTo is a pidl
  289.   shgnli_PrefixName     = $000000002;  // Make name "Shortcut to xxx"
  290.  
  291.   shell32 = 'shell32.dll';
  292.  
  293. implementation
  294.  
  295. function CommandLineToArgvW;    external;
  296. function DoEnvironmentSubst;    external;
  297. procedure DragAcceptFiles;      external;
  298. procedure DragFinish;           external;
  299. function DragQueryFile;         external;
  300. function DragQueryPoint;        external;
  301. function DuplicateIcon;         external;
  302. function ExtractAssociatedIcon; external;
  303. function ExtractIcon;           external;
  304. function ExtractIconEx;         external;
  305. function FindExecutable;        external;
  306. function SHAppBarMessage;       external;
  307. function SHFileOperation;       external;
  308. procedure SHFreeNameMappings;   external;
  309. function SHGetFileInfo;         external;
  310. function SHGetNewLinkInfo;      external;
  311. function ShellAbout;            external;
  312. function ShellExecute;          external;
  313. function ShellExecuteEx;        external;
  314. function Shell_NotifyIcon;      external;
  315.  
  316. end.
  317.