Showing posts with label TCheckbox. Show all posts
Showing posts with label TCheckbox. Show all posts

Monday, June 25, 2007

User Management through Win32 call


Check out the JCL (JediVCL) it has a routine from lanmanager(JcLanMan.pas)



function CreateAccount(const Server, Username, Fullname, Password,
Description,
Homedir, Script: string; const PasswordNeverExpires: Boolean):
Boolean;
var
wServer, wUsername, wFullname,
wPassword, wDescription, wHomedir, wScript: WideString;
Details: USER_INFO_2;
Err: NET_API_STATUS;
ParmErr: DWORD;
begin
wServer := Server;
wUsername := Username;
wFullname := Fullname;
wPassword := Password;
wDescription := Description;
wScript := Script;
wHomedir := Homedir;

FillChar (Details, SizeOf(Details), 0);
with Details do
begin
usri2_name := PWideChar(wUsername);
usri2_full_name := PWideChar(wFullname);
usri2_password := PWideChar(wPassword);
usri2_comment := PWideChar(wDescription);
usri2_priv := USER_PRIV_USER;
usri2_flags := UF_SCRIPT;
if PassWordNeverExpires then
usri2_flags := usri2_flags or UF_DONT_EXPIRE_PASSWD;
usri2_script_path := PWideChar(wScript);
usri2_home_dir := PWideChar(wHomedir);
usri2_acct_expires := TIMEQ_FOREVER;
end;

Err := NetUserAdd(PWideChar(wServer), 2, @Details, @ParmErr);
Result := (Err = NERR_SUCCESS);
end;



C:\>cacls /?
Displays or modifies access control lists (ACLs) of files

CACLS filename [/T] [/E] [/C] [/G user:perm] [/R user [...]]
[/P user:perm [...]] [/D user [...]]
filename Displays ACLs.
/T Changes ACLs of specified files in
the current directory and all subdirectories.
/E Edit ACL instead of replacing it.
/C Continue on access denied errors.
/G user:perm Grant specified user access rights.
Perm can be: R Read
C Change (write)
F Full control
/R user Revoke specified user's access rights (only valid with /E).
/P user:perm Replace specified user's access rights.
Perm can be: N None
R Read
C Change (write)
F Full control
/D user Deny specified user access.
Wildcards can be used to specify more that one file in a command.
You can specify more than one user in a command.

Add checkboxes to a TShellTreeView


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellCtrls;

type
TCheckBoxShellTreeView = class(ShellCtrls.TShellTreeView)
public
procedure CreateParams(var Params: TCreateParams); override;
end;

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
ShellTreeView: TCheckBoxShellTreeView;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

const
TVS_CHECKBOXES = $00000100;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ShellTreeView := TCheckBoxShellTreeView.Create(Self);
with ShellTreeView do
begin
Name := 'ShellTreeView';
Parent := Self;
Root := 'rfDesktop';
UseShellImages := True;
Align := alClient;
AutoRefresh := False;
BorderStyle := bsNone;
Indent := 19;
ParentColor := False;
RightClickSelect := True;
ShowRoot := False;
TabOrder := 0;
end;
end;

procedure TCheckBoxShellTreeView.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or TVS_CHECKBOXES;
end;

end.

Adding TCheckbox to TCombobox

You need to do the following:

Set ComboBox.Style:=csOwnerDrawFixed

//..... your form class
private
Selected: array of Boolean;
//.....


procedure TForm1.ComboBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
SetLength(Selected, TComboBox(Control).Items.Count);
with TComboBox(Control).Canvas do
begin
FillRect(rect);

Rect.Left := Rect.Left + 1;
Rect.Right := Rect.Left + 13;
Rect.Bottom := Rect.Bottom;
Rect.Top := Rect.Top;

if not (odSelected in State) and (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON,
DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT)
else if (odFocused in State) and (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON,
DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT)
else if (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON,
DFCS_BUTTONCHECK or DFCS_CHECKED or DFCS_FLAT)
else if not (Selected[Index]) then
DrawFrameControl(Handle, Rect, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_FLAT);

TextOut(Rect.Left + 15, Rect.Top, TComboBox(Control).Items[Index]);
end;
end;

procedure TForm1.ComboBox1Select(Sender: TObject);
var
i: Integer;
Sel: string;
begin
Sel := EmptyStr;
Selected[TComboBox(Sender).ItemIndex] := not Selected[TComboBox(Sender).ItemIndex];
for i := 0 to TComboBox(Sender).Items.Count - 1 do
if Selected[i] then
Sel := Sel + TComboBox(Sender).Items[i] + ' ';
ShowMessage(Sel); //Just for test...
end;