//ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
//Û                                                      Û
//Û     Virtual Pascal Runtime Library.  Version 2.1     Û
//Û     Windows Shell API interface unit                 Û
//Û     ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÛ
//Û     Copyright (C) 1998-2000 vpascal.com              Û
//Û                                                      Û
//ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß


unit ShellAPI;

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

interface

uses Windows;

type
  HDrop = Longint;

function DragQueryFile(Drop: HDrop; FileIndex: UInt; FileName: PChar; cb: UInt): UInt;
function DragQueryPoint(Drop: HDrop; var Point: TPoint): Bool;
procedure DragFinish(Drop: HDrop);
procedure DragAcceptFiles(Wnd: HWnd; Accept: Bool);
function ShellExecute(HWnd: HWnd; Operation, FileName, Parameters,
  Directory: PChar; ShowCmd: Integer): HInst;
function FindExecutable(FileName, Directory: PChar; Result: PChar): HInst;
function CommandLineToArgvW(lpCmdLine: LPCWSTR; var pNumArgs: Integer): Pointer;
function ShellAbout(Wnd: HWnd; szApp, szOtherStuff: PChar; Icon: HIcon): Integer;
function DuplicateIcon(hInst: HInst; Icon: HIcon): HIcon;
function ExtractAssociatedIcon(hInst: HInst; lpIconPath: PChar;
  var lpiIcon: Word): HIcon;
function ExtractIcon(hInst: HInst; lpszExeFileName: PChar;
  nIconIndex: UInt): HIcon;

type
  PDragInfo = ^TDragInfo;
  TDragInfo = record
    uSize:       UInt;    // init with SizeOf(TDragInfo)
    pt:          TPoint;
    fNC:         Bool;
    lpFileList:  PChar;
    grfKeyState: DWord;
  end;

const
// AppBar stuff
  abm_New               = $00000000;
  abm_Remove            = $00000001;
  abm_QueryPos          = $00000002;
  abm_SetPos            = $00000003;
  abm_GetState          = $00000004;
  abm_GetTaskBarPos     = $00000005;
  abm_Activate          = $00000006;  // lParam = True/False means activate/deactivate
  abm_GetAutoHideBar    = $00000007;
  abm_SetAutoHideBar    = $00000008;  // this can fail at any time.  MUST check the result lParam = TRUE/FALSE Set/Unset uEdge = what edge
  abm_WindowPosChanged  = $00000009;

// these are put in the wparam of callback messages

  abn_StateChange       = $00000000;
  abn_PosChanged        = $00000001;
  abn_FullScreenApp     = $00000002;
  abn_WindowArrange     = $00000003; // lParam = True means hide

// flags for get state

  abs_AutoHide          = $00000001;
  abs_AlwaysOnTop       = $00000002;

  abe_Left              = 0;
  abe_Top               = 1;
  abe_Right             = 2;
  abe_Bottom            = 3;

type
  PAppBarData = ^TAppBarData;
  TAppBarData = record
    cbSize:           DWord;
    HWnd:             HWnd;
    uCallbackMessage: UInt;
    uEdge:            UInt;
    rc:               TRect;
    lParam:           LParam; // message specific
  end;

function SHAppBarMessage(dwMessage: DWord; var pData: TAppBarData): UInt;


function DoEnvironmentSubst(szString: PChar; cbString: UInt): DWord;
function ExtractIconEx(lpszFile: PChar; nIconIndex: Integer; var phiconLarge, phiconSmall: HIcon; nIcons: UInt): UInt;


// Shell File Operations

const
  fo_Move               = $0001;
  fo_Copy               = $0002;
  fo_Delete             = $0003;
  fo_Rename             = $0004;

  fof_MultiDestFiles    = $0001;
  fof_ConfirmMouse      = $0002;
  fof_Silent            = $0004;  // don't create progress/report
  fof_RenameOnCollision = $0008;
  fof_NoConfirmation    = $0010;  // Don't prompt the user.
  fof_WantMappingHandle = $0020;  // Fill in SHFILEOPSTRUCT.hNameMappings Must be freed using SHFreeNameMappings
  fof_AllowUndo         = $0040;
  fof_FilesOnly         = $0080;  // on *.*, do only files
  fof_SimpleProgress    = $0100;  // means don't show names of files
  fof_NoConfirmMkdir    = $0200;  // don't confirm making any needed dirs

type
  fileop_Flags = Word;

const
  po_Delete             = $0013;  // printer is being deleted
  po_Rename             = $0014;  // printer is being renamed
  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.
  po_Ren_Port           = $0034;  // po_Rename and po_PortChange at same time.

// no pof_ flags currently defined

type
  printerOp_Flags = Word;

// implicit parameters are:
//    if pFrom or pTo are unqualified names the current directories are
//    taken from the global current drive/directory settings managed
//    by Get/SetCurrentDrive/Directory
//
//    the global confirmation settings

  PSHFileOpStruct = ^TSHFileOpStruct;
  TSHFileOpStruct = record
    Wnd:                   HWnd;
    wFunc:                 UInt;
    pFrom:                 PChar;
    pTo:                   PChar;
    fFlags:                fileop_Flags;
    fAnyOperationsAborted: Bool;
    hNameMappings:         Pointer;
    lpszProgressTitle:     PChar; // only used if fof_SimpleProgress
  end;

function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer;
procedure SHFreeNameMappings(hNameMappings: THandle);

type
  PSHNameMapping = ^TSHNameMapping;
  TSHNameMapping = record
    pszOldPath: PChar;
    pszNewPath: PChar;
    cchOldPath: Integer;
    cchNewPath: Integer;
  end;

// ShellExecute() and ShellExecuteEx() error codes
const
// regular WinExec() codes
  se_err_FNF            = 2;   // file not found
  se_err_PNF            = 3;   // path not found
  se_err_AccessDenied   = 5;   // access denied
  se_err_OOM            = 8;   // out of memory
  se_err_DLLNotFound    = 32;

// error values for ShellExecute() beyond the regular WinExec() codes
  se_err_Share          = 26;
  se_err_AssocIncomplete= 27;
  se_err_DDETimeout     = 28;
  se_err_DDEFail        = 29;
  se_err_DDEBusy        = 30;
  se_err_NoAssoc        = 31;

// Note CLASSKEY overrides CLASSNAME
  see_mask_ClassName    = $00000001;
  see_mask_ClassKey     = $00000003;
// Note INVOKEIDLIST overrides IDLIST
  see_mask_IdList       = $00000004;
  see_mask_InvokeIdList = $0000000c;
  see_mask_Icon         = $00000010;
  see_mask_HotKey       = $00000020;
  see_mask_NoCloseProcess = $00000040;
  see_mask_ConnectNetDrv= $00000080;
  see_mask_Flag_DDEWait = $00000100;
  see_mask_DoEnvSubst   = $00000200;
  see_mask_Flag_No_UI   = $00000400;
  see_mask_Unicode      = $00010000;

type
  PShellExecuteInfo = ^TShellExecuteInfo;
  TShellExecuteInfo = record
    cbSize:         DWord;
    fMask:          ULong;
    Wnd:            HWnd;
    lpVerb:         PChar;
    lpFile:         PChar;
    lpParameters:   PChar;
    lpDirectory:    PChar;
    nShow:          Integer;
    hInstApp:       HInst;
    // Optional fields
    lpIDList:       Pointer;
    lpClass:        PChar;
    hkeyClass:      HKey;
    dwHotKey:       DWord;
    hIcon:          THandle;
    hProcess:       THandle;
  end;

function ShellExecuteEx(lpExecInfo: PShellExecuteInfo):Bool;

// Tray notification definitions

type
  PNotifyIconData = ^TNotifyIconData;
  TNotifyIconData = record
    cbSize:           DWord;
    Wnd:              HWnd;
    uID:              UInt;
    uFlags:           UInt;
    uCallbackMessage: UInt;
    hIcon:            HIcon;
    szTip: array [0..63] of Char;
  end;

const
  nim_Add               = $00000000;
  nim_Modify            = $00000001;
  nim_Delete            = $00000002;

  nif_Message           = $00000001;
  nif_Icon              = $00000002;
  nif_Tip               = $00000004;

function Shell_NotifyIcon(dwMessage: DWord; lpData: PNotifyIconData): Bool;

// Begin SHGetFileInfo

// The SHGetFileInfo API provides an easy way to get attributes
// for a file given a pathname.
//
//   PARAMETERS
//
//     pszPath              file name to get info about
//     dwFileAttributes     file attribs, only used with SHGFI_USEFILEATTRIBUTES
//     psfi                 place to return file info
//     cbFileInfo           size of structure
//     uFlags               flags
//
//   RETURN
//     TRUE if things worked

type
  PSHFileInfo = ^TSHFileInfo;
  TSHFileInfo = record
    hIcon:          HIcon;                         // out: icon
    iIcon:          Integer;                       // out: icon index
    dwAttributes:   DWord;                         // out: SFGAO_ flags
    szDisplayName:  array [0..max_Path-1] of Char; // out: display name (or path)
    szTypeName:     array [0..79] of Char;         // out: type name
  end;

const
  shgfi_Icon            = $000000100;   // get icon
  shgfi_DisplayName     = $000000200;   // get display name
  shgfi_TypeName        = $000000400;   // get type name
  shgfi_Attributes      = $000000800;   // get attributes
  shgfi_IconLocation    = $000001000;   // get icon location
  shgfi_ExeType         = $000002000;   // return exe type
  shgfi_SysIconIndex    = $000004000;   // get system icon index
  shgfi_LinkOverlay     = $000008000;   // put a link overlay on icon
  shgfi_Selected        = $000010000;   // show icon in selected state
  shgfi_LargeIcon       = $000000000;   // get large icon
  shgfi_SmallIcon       = $000000001;   // get small icon
  shgfi_OpenIcon        = $000000002;   // get open icon
  shgfi_ShellIconsize   = $000000004;   // get shell size icon
  shgfi_Pidl            = $000000008;   // pszPath is a pidl
  shgfi_UseFileAttributes = $000000010; // use passed dwFileAttribute

function SHGetFileInfo(pszPath: PChar; dwFileAttributes: DWord;
  var psfi: TSHFileInfo; cbFileInfo, uFlags: UInt): DWord;
function SHGetNewLinkInfo(pszLinkTo, pszDir: PChar; pszName: PChar;
  var pfMustCopy: Bool; uFlags: UInt): Bool;

const
  shgnli_Pidl           = $000000001;  // pszLinkTo is a pidl
  shgnli_PrefixName     = $000000002;  // Make name "Shortcut to xxx"

  shell32 = 'shell32.dll';

implementation

function CommandLineToArgvW;    external;
function DoEnvironmentSubst;    external;
procedure DragAcceptFiles;      external;
procedure DragFinish;           external;
function DragQueryFile;         external;
function DragQueryPoint;        external;
function DuplicateIcon;         external;
function ExtractAssociatedIcon; external;
function ExtractIcon;           external;
function ExtractIconEx;         external;
function FindExecutable;        external;
function SHAppBarMessage;       external;
function SHFileOperation;       external;
procedure SHFreeNameMappings;   external;
function SHGetFileInfo;         external;
function SHGetNewLinkInfo;      external;
function ShellAbout;            external;
function ShellExecute;          external;
function ShellExecuteEx;        external;
function Shell_NotifyIcon;      external;

end.
