TRUCS & ASTUCES BORLAND DELPHI
Pour créer et
utiliser un fichier .INI
Pour écrire dans la base de registre
Pour jouer un fichier .WAV
Pour lancer l'économiseur d'écran
Pour rebooter / relancer windows
Pour déplacer un composant à l'éxecution
Pour spécifier les paramètres régionaux
Pour connaître la version du système d'exploitation
Pour afficher la liste des tâches de Windows
Pour faire un fond dégradé
Pour créer une fenêtre elliptique
Pour créer une fenêtre transparente
Pour cacher / afficher le bouton Démarrer
Pour déssiner sur le bureau
Pour connaître les infos de version de mon appli
Uses inifiles;
Procedure TForm1.EcrireFichierINI;
Begin
With TIniFile.Create('Fichier.INI') do
Begin
WriteString('Section','Ident1',Str1));
WriteInteger('Section','Ident2',Int1));
free;
End
End;
Procedure TForm1.LireFichierINI;
Begin
With TIniFile.Create('Fichier.INI') do
Begin
Str1 := ReadString('Section','Ident1','Val par default');
Int1:=
ReadInteger('Section','Ident2',100');
free;
End
End;
Uses Registry;
procedure TForm1.EcrireDansLaBaseDeRegistre;
var
Reg :TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
begin
try
RootKey := HKEY_LOCAL_MACHINE;
if KeyExists('\Software') then
begin
if OpenKey('\Software\MonAppli', true) then
begin
WriteString('Nom', 'Toto');
WriteBool('Val1', true);
WriteString('Val2', 'Test');
end;
end;
finally
free;
end;
end;
end;
Uses MMSystem;
Procedure PlayWave ( FichierWave:String ; Mode:Integer ) ;
Var
FichWav : Array [0..100] of Char;
Begin
StrPcopy(FichWav,FichierWave);
SndPlaySound(FichWav,Mode);
End;
Procedure LanceEconomiseurEcran;
Begin
Windows.PostMessage(Windows.GetDesktopWindow,WM_SYSCOMMAND,SC_SCREENSAVE,0);
End;
Procedure RebootSysteme;
Begin
ExitWindows(EW_REBOOTSYSTEM,0);
End;
Procedure RelancerWindows;
Begin
ExitWindows(EW_RESTARTWINDOWS,0);
End;
Procedure
MonObjMouseDown(Sender: TObject;...)
Begin
ReleaseCapture;
MonObj.perform(WM_Syscommand, $F012,0);
End;
DecimalSeparator := ',';
ShortDateFormat := 'dd/dd/yyyy';
Procedure AfficheInfoVersion;
Var
InfosVersion : TOSVersionInfo;
Begin
InfosVersion.dwOSVersionInfoSize:=sizeof(InfosVersion);
GetVersionEx(InfosVersion);
Case InfosVersion.dwPlatformId of
VER_PLATFORM_WIN32s :
Systeme.caption:='Système : Microsoft Windows 3.1 / Win32s ';
VER_PLATFORM_WIN32_WINDOWS :
Systeme.caption:='Système : Microsoft Windows 95';
VER_PLATFORM_WIN32_NT :
Systeme.caption:='Système : Microsoft Windows NT';
End;
VersionWin.caption:='Version n° : '+
inttostr(InfosVersion.dwMajorVersion)
+'.'+inttostr(InfosVersion.dwMinorVersion)
+'.'+inttostr(loword(InfosVersion.dwBuildNumber))
+' '+InfosVersion.szCSDVersion ;
End;
function
EnumWindowsProc(Wnd : HWnd;Form : TForm1) : Boolean; Export; {$ifdef Win32} StdCall;
{$endif}
var
Buffer : Array[0..99] of char;
begin
GetWindowText(Wnd,Buffer,100);
if StrLen(Buffer) <> 0 then
Form1.memo1.lines.Add(StrPas(Buffer));
Result := True;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc,LongInt(Self));
end;
Procedure Form1.FormPaint(Sender:
TObject);
Var
Ligne : integer;
Begin
For Ligne:=0 to
Form1.Height do
Begin
Form1.Canvas.pen.color:=RGB(0,MulDiv( Ligne,255,Form1.height),0); //vert
Form1.Canvas.MoveTo(0, Ligne);
Form1.Canvas.LineTo(Form1.Width, Ligne) ;
End;
End;
// ( rouge : RGB(MulDiv( Ligne,255,Form1.height),0,0)
/ ( bleu : RGB(0,0,MulDiv( Ligne,255,Form1.height)) )
var
hR : THandle;
begin
hR := CreateEllipticRgn(0,0,Form1.Width,Form1.Height);
SetWindowRgn(Handle,hR,True);
end;
Procedure
TForm1.FormCreate(Sender: TObject);
begin
Form1.Brush.Style := bsClear;
Form1.BorderStyle := bsNone;
end;
Procedure
TForm1.CacherBtnDemarrerClick(Sender: TObject);
var
Rgn : hRgn;
Begin
Rgn := CreateRectRgn(0, 0, 0, 0);
SetWindowRgn(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0,
'Button', nil), Rgn, true);
End;
Procedure TForm1.AfficherBtnDemarrerClick(Sender: TObject);
Begin
SetWindowRgn(FindWindowEx(FindWindow('Shell_TrayWnd', nil),
0, 'Button', nil), 0, true);
End;
Procedure
TForm1.Button1Click(Sender: TObject);
Var
dc : hdc;
Begin
dc := GetDc(0);
MoveToEx(Dc, 0, 0, nil);
LineTo(Dc, 300, 300);
ReleaseDc(0, Dc);
End;
Procedure
TForm1.Button1Click(Sender: TObject);
Var
VerSize : Dword;
FName : String;
Zero : THandle;
PBlock : Pointer;
PS : Pointer;
Size : Uint;
Begin
// Get size of Version resource
VerSize := GetFileVersionInfoSize(PChar(application.ExeName), Zero);
If VerSize = 0 Then Exit;
// Allocate memory
GetMem(PBlock, VerSize);
// Get Version resource
GetFileVersionInfo(PChar(application.ExeName), 0, VerSize, PBlock);
// Get predefined string
GetMem(PS, 256);
VerQueryValue(PBlock,
PChar('\\StringFileInfo\\040C04E4\\FileDescription'),PS, Size);
Description.caption := StrPas(PS);
VerQueryValue(PBlock,
PChar('\\StringFileInfo\\040C04E4\\FileVersion'),PS, Size);
Version.caption := 'Version: '+ StrPas(PS);
VerQueryValue(PBlock, PChar('\\StringFileInfo\\040C04E4\\Comments'),PS,
Size);
Comment.caption :=Version.caption + ' '+StrPas(PS);
VerQueryValue(PBlock,
PChar('\\StringFileInfo\\040C04E4\\LegalCopyright'),PS, Size);
Copyright.caption := 'Copyright: '+ StrPas(PS);
VerQueryValue(PBlock,
PChar('\\StringFileInfo\\040C04E4\\CompanyName'),PS, Size);
Organisation.caption := StrPas(PS);
End;
( 040C04E4 = Langage / Id locale $040C / Français - Standard )
Pour m'envoyer vos Trucs & Astuces, c'est ICI.