implementation
{$R *.dfm}
uses
ShlObj;
function TForm1.CommonDataPath:
string;
const
CSIDL_COMMON_APPDATA = $0023;
// All Users\Application Data
var
Path:
array [0..1024]
of char;
begin
if SHGetSpecialFolderPath(
Handle, Path, CSIDL_COMMON_APPDATA, TRUE)
then Result :=
String(path)
else Result := '
';
end;
function TForm1.GetCurrentUserName:
String;
var
pcUserName : pChar;
// temporary storage
dwMaxChars : dWord;
// length parameter
const
MAXCHARS = 255;
// max length
begin
dwMaxChars := MAXCHARS;
GetMem(pcUserName, MAXCHARS + 1);
if GetUserName(pcUserName, dwMaxChars)
then Result :=
String(pcUserName)
else Result := '
';
FreeMem(pcUserName);
end;
procedure TForm1.FormCreate(Sender: TObject);
var LgPath:
String;
begin
Label1.Caption := GetCurrentUserName;
LgPath := CommonDataPath + '
\Microsoft\User Account Pictures\' +
Label1.Caption + '
.bmp';
if FileExists(LgPath)
then
begin
Image1.Picture.Bitmap.Handle :=
LoadImage(0, PChar(LgPath), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
end else
ShowMessage(format('
%s'#13#10'
"%s"', ['
Datei nicht gefunden:', LgPath]));
end;