home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kompon / d56 / MSYSINFO.ZIP / Demos / GUI / ShareProps.pas < prev    next >
Pascal/Delphi Source File  |  2002-01-04  |  3KB  |  125 lines

  1. unit ShareProps;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ExtCtrls, ComCtrls, CheckLst;
  8.  
  9. type
  10.   TpropShare = class(TFrame)
  11.     pc: TPageControl;
  12.     tsConns: TTabSheet;
  13.     Panel4: TPanel;
  14.     lvConns: TListView;
  15.     tsGeneral: TTabSheet;
  16.     Image1: TImage;
  17.     Bevel1: TBevel;
  18.     Bevel2: TBevel;
  19.     Bevel3: TBevel;
  20.     lPath: TLabel;
  21.     lCur: TLabel;
  22.     lMax: TLabel;
  23.     lType: TLabel;
  24.     lDesc: TLabel;
  25.     stCur: TStaticText;
  26.     stName: TEdit;
  27.     stPath: TStaticText;
  28.     stMax: TStaticText;
  29.     stType: TStaticText;
  30.     stDesc: TStaticText;
  31.     bDiscon: TButton;
  32.     lComment: TLabel;
  33.     stComment: TStaticText;
  34.     clbPerms: TCheckListBox;
  35.     Label1: TLabel;
  36.     procedure clbPermsClickCheck(Sender: TObject);
  37.     procedure cmDiscon(Sender: TObject);
  38.   private
  39.     FShare: TObject;
  40.   public
  41.     property Share: TObject read FShare write FShare;
  42.     procedure Refresh;
  43.   end;
  44.  
  45. implementation
  46.  
  47. uses MiTeC_Shares, MiTeC_Routines, MiTeC_NetAPI32;
  48.  
  49. {$R *.DFM}
  50.  
  51. { TpropShare }
  52.  
  53. procedure TpropShare.Refresh;
  54. var
  55.   i,n: integer;
  56. begin
  57.   pc.ActivePage:=tsGeneral;
  58.   if IsNT then begin
  59.     with PNTShareRecord(Share)^, TConnections.Create do begin
  60.       stName.Text:=Name;
  61.       stPath.Caption:=Path;
  62.       stComment.Caption:=Comment;
  63.       stType.Caption:=ShareTypes[ShareType];
  64.       if MaxUserCount=uint(-1) then
  65.         stMax.caption:='Unlimited'
  66.       else
  67.         stMax.Caption:=Format('%d',[MaxUserCount]);
  68.       stCur.Caption:=Format('%d',[CurUserCount]);
  69.       stDesc.Caption:=BoolToStr(SecurityDesc,True);
  70.       for i:=0 to clbPerms.Items.Count -1 do
  71.         clbPerms.Checked[i]:=TPermission(i) in Permissions;
  72.       Qualifier:=Name;
  73.       Refresh;
  74.       n:=ConnectionCount;
  75.       lvConns.Items.BeginUpdate;
  76.       for i:=0 to n-1 do
  77.         with lvConns.Items.Add, Connections[i]^ do begin
  78.           Caption:=Name;
  79.           SubItems.Add(Username);
  80.           Subitems.Add(ShareTypes[ConnType]);
  81.           SubItems.Add(Format('%d',[OpenFiles]));
  82.           SubItems.Add(Format('%d',[Users]));
  83.           SubItems.Add(FormatSeconds(Time,True,False,True));ImageIndex:=-1;
  84.         end;
  85.       lvConns.Items.EndUpdate;
  86.       Free;
  87.     end;
  88.   end else begin
  89.   end;
  90. end;
  91.  
  92. procedure TpropShare.clbPermsClickCheck(Sender: TObject);
  93. var
  94.   OCC: TNotifyEvent;
  95.   idx: integer;
  96.   p: TPoint;
  97. begin
  98.   with TCheckListBox(Sender) do begin
  99.     OCC:=OnClickCheck;
  100.     OnClickCheck:=nil;
  101.     GetCursorPos(p);
  102.     p:=ScreenToClient(p);
  103.     idx:=ItemAtPos(p,True);
  104.     if idx>-1 then
  105.       Checked[idx]:=not Checked[idx];
  106.     OnClickCheck:=OCC;
  107.   end;
  108. end;
  109.  
  110. procedure TpropShare.cmDiscon(Sender: TObject);
  111. var
  112.   Buf1,Buf2: array[0..256] of WideChar;
  113.   n: DWORD;
  114. begin
  115.   if (MessageDlg('Stop sharing?',mtConfirmation,[mbYes,mbNo],0)=mryes) then begin
  116.     n:=NetShareDel(StringToWideChar(MachineName,Buf1,256),
  117.                    StringToWideChar(PNTShareRecord(Share)^.Name,Buf2,256),0);
  118.     bDisCon.Enabled:=n<>ERROR_SUCCESS;
  119.     if n<>ERROR_SUCCESS then
  120.       raise Exception.Create(GetErrorMessage(n));
  121.   end;
  122. end;
  123.  
  124. end.
  125.