Недавно добавленные исходники

•  TDictionary Custom Sort  3 225

•  Fast Watermark Sources  2 990

•  3D Designer  4 750

•  Sik Screen Capture  3 259

•  Patch Maker  3 467

•  Айболит (remote control)  3 527

•  ListBox Drag & Drop  2 903

•  Доска для игры Реверси  80 766

•  Графические эффекты  3 843

•  Рисование по маске  3 171

•  Перетаскивание изображений  2 544

•  Canvas Drawing  2 672

•  Рисование Луны  2 500

•  Поворот изображения  2 091

•  Рисование стержней  2 119

•  Paint on Shape  1 524

•  Генератор кроссвордов  2 182

•  Головоломка Paletto  1 730

•  Теорема Монжа об окружностях  2 158

•  Пазл Numbrix  1 649

•  Заборы и коммивояжеры  2 016

•  Игра HIP  1 262

•  Игра Go (Го)  1 200

•  Симулятор лифта  1 421

•  Программа укладки плитки  1 177

•  Генератор лабиринта  1 512

•  Проверка числового ввода  1 297

•  HEX View  1 466

•  Физический маятник  1 322

•  Задача коммивояжера  1 357

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Проверить, расшарена ли папка



Оформил: DeeCo

{Following code needs to use ShlObj, ComObj, ActiveX Units}

 function TForm1.IfFolderShared(FullFolderPath: string): Boolean;

   //Convert TStrRet to string 
  function StrRetToString(PIDL: PItemIDList; StrRet: TStrRet; Flag: string = ''): string;
   var
     P: PChar;
   begin
     case StrRet.uType of
       STRRET_CSTR:
         SetString(Result, StrRet.cStr, lStrLen(StrRet.cStr));
       STRRET_OFFSET:
         begin
           P := @PIDL.mkid.abID[StrRet.uOffset - SizeOf(PIDL.mkid.cb)];
           SetString(Result, P, PIDL.mkid.cb - StrRet.uOffset);
         end;
       STRRET_WSTR:
         if Assigned(StrRet.pOleStr) then
           Result := StrRet.pOleStr
         else
           Result := '';
     end;
     { This is a hack bug fix to get around Windows Shell Controls returning 
      spurious "?"s in date/time detail fields }
     if (Length(Result) > 1) and (Result[1] = '?') and (Result[2] in ['0'..'9']) then
       Result := StringReplace(Result, '?', '', [rfReplaceAll]);
   end;

   //Get Desktop's IShellFolder interface 
  function DesktopShellFolder: IShellFolder;
   begin
     OleCheck(SHGetDesktopFolder(Result));
   end;

   //delete the first ID from IDList 
  function NextPIDL(IDList: PItemIDList): PItemIDList;
   begin
     Result := IDList;
     Inc(PChar(Result), IDList^.mkid.cb);
   end;

   //get the length of IDList 
  function GetPIDLSize(IDList: PItemIDList): Integer;
   begin
     Result := 0;
     if Assigned(IDList) then
     begin
       Result := SizeOf(IDList^.mkid.cb);
       while IDList^.mkid.cb <> 0 do
       begin
         Result := Result + IDList^.mkid.cb;
         IDList := NextPIDL(IDList);
       end;
     end;
   end;

   //get ID count from IDList 
  function GetItemCount(IDList: PItemIDList): Integer;
   begin
     Result := 0;
     while IDList^.mkid.cb <> 0 do
     begin
       Inc(Result);
       IDList := NextPIDL(IDList);
     end;
   end;

   //create an ItemIDList object 
  function CreatePIDL(Size: Integer): PItemIDList;
   var
     Malloc: IMalloc;
   begin
     OleCheck(SHGetMalloc(Malloc));

     Result := Malloc.Alloc(Size);
     if Assigned(Result) then
       FillChar(Result^, Size, 0);
   end;

   function CopyPIDL(IDList: PItemIDList): PItemIDList;
   var
     Size: Integer;
   begin
     Size   := GetPIDLSize(IDList);
     Result := CreatePIDL(Size);
     if Assigned(Result) then
       CopyMemory(Result, IDList, Size);
   end;

   //get the last ItemID from AbsoluteID 
  function RelativeFromAbsolute(AbsoluteID: PItemIDList): PItemIDList;
   begin
     Result := AbsoluteID;
     while GetItemCount(Result) > 1 do
       Result := NextPIDL(Result);
     Result := CopyPIDL(Result);
   end;

   //remove the last ID from IDList 
  procedure StripLastID(IDList: PItemIDList);
   var
     MarkerID: PItemIDList;
   begin
     MarkerID := IDList;
     if Assigned(IDList) then
     begin
       while IDList.mkid.cb <> 0 do
       begin
         MarkerID := IDList;
         IDList   := NextPIDL(IDList);
       end;
       MarkerID.mkid.cb := 0;
     end;
   end;

   //if Flag include Element 
  function IsElement(Element, Flag: Integer): Boolean;
   begin
     Result := Element and Flag <> 0;
   end;
 var
   P: Pointer;
   NumChars, Flags: LongWord;
   ID, NewPIDL, ParentPIDL: PItemIDList;
   ParentShellFolder: IShellFolder;
 begin
   Result := False;
   NumChars := Length(FullFolderPath);
   P  := StringToOleStr(FullFolderPath);
   //get the folder's full ItemIDList 
  OleCheck(DesktopShellFolder.ParseDisplayName(0, nil, P, NumChars, NewPIDL, Flags));
   if NewPIDL <> nil then
   begin
     ParentPIDL := CopyPIDL(NewPIDL);
     StripLastID(ParentPIDL);      //get the folder's parent object's ItemIDList 

    ID := RelativeFromAbsolute(NewPIDL);  //get the folder's relative ItemIDList 

    //get the folder's parent object's IShellFolder interface 
    OleCheck(DesktopShellFolder.BindToObject(ParentPIDL, nil, IID_IShellFolder,
       Pointer(ParentShellFolder)));

     if ParentShellFolder <> nil then
     begin
       Flags := SFGAO_SHARE;
       //get the folder's attributes 
      OleCheck(ParentShellFolder.GetAttributesOf(1, ID, Flags));
       if IsElement(SFGAO_SHARE, Flags) then Result := True;
     end;
   end;
 end;

 {How to use the function? 
 The parameter in is the full path of a folder}

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   if IfFolderShared('C:\My Documents\WinPopup') then ShowMessage('shared')
   else
     ShowMessage('not shared');
 end;







Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте