10. Delphi
Sios komandos skirtos programavimo kalbai - Delphi. Jos isbandytos su
5.0 versija.
......by ZErOnE
zerone@xxx.lt
______________________________________________________________________
1. Shut Down, Reboot, Standby funkcijos:
ExitWindowsEx(EWX_SHUTDOWN,0); { ShutDown }
ExitWindowsEx(EWX_REBOOT,0); { Reboot
}
ExitWindowsEx(EWX_POWEROFF,0); { Standby }
______________________________________________________________________
2. Gauti pc IP adresa:
uses winsock;
...
function GetIPAddress: string;
var
phoste:PHostEnt;
Buffer:array[0..100] of char;
WSAData:TWSADATA;
begin
result:='';
if WSASTartup($0101, WSAData) <> 0 then
exit;
GetHostName(Buffer,Sizeof(Buffer));
phoste:=GetHostByName(buffer);
if phoste = nil then
begin
result:='127.0.0.1';
end
else
result:=StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
WSACleanup;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=GETIPAddress;
end;
______________________________________________________________________
3. Gauti win'u ir system foldery:
function GetWinDir: String;
var
dir: array [0..max_path] of char;
begin
GetWindowsDirectory(dir, max_path);
result:=StrPas(dir);
end;
function GetSysDir: String;
var
dir: array [0..max_path] of char;
begin
GetSystemDirectory(dir, max_path);
result:=StrPas(dir);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption:=GetWinDir;
label2.caption:=GetSysDir;
end;
______________________________________________________________________
4. Sisteminiu klavisu isjungimas/yhungimas (Alt+Tab, Alt+Ctrl+Del) :
var OldVal: LongInt;
begin
SystemParametersInfo (97, Word (True),
@OldVal, 0); //disable
SystemParametersInfo (97, Word (False),
@OldVal, 0); //enable
end;
______________________________________________________________________
5. Pakeisti background'a :
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar('C:\pvz.BMP'),
SPIF_SendWININICHANGE);
______________________________________________________________________
6. Pakeisti peles pozicija :
SetCursorPos(600,600);
______________________________________________________________________
7. Gauti ScreenShot'a :
function GetScreenShot:TBitmap;
var
Desktop:HDC;
begin
Result:= TBitmap.Create;
Desktop:= GetDC(0);
try
try
Result.PixelFormat:=pf32bit;
Result.Width:=Screen.Width;
Result.Height:=Screen.Height;
BitBlt(Result.Canvas.Handle,0,0,Result.Width,Result.Height,Desktop,0,0,SRCCOPY);
Result.Modified:=True;
finally
ReleaseDC(0,Desktop);
end;
except
Result.Free;
Result:=nil;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Picture.Bitmap:=GetScreenShot;
end;
______________________________________________________________________
8. Darbas su .ini failais :
uses inifiles;
...
var ini: TIniFile;
...
var reiksme1:string; {nuskaitymas}
begin
reiksme1:=ini.ReadString('Section','Edit1','');
label1.caption:=reiksme1;
end;
ini.WriteString('Section','Edit1',edit1.text); {yrasimas}
procedure TForm1.FormCreate(Sender: TObject);
begin
ini:= TIniFile.Create('c:\test.ini');
{.ini failo sukurimas}
end;
______________________________________________________________________
9. Enable/Disable Start mygtuko :
EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd',
nil), 0, 'Button', nil), TRUE); {enable}
EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd',
nil), 0, 'Button', nil), FALSE); {disable}
______________________________________________________________________
10. paslepti/grazinti desktop'a :
ShowWindow(FindWindow(nil,'Program Manager'),SW_HIDE);
{paslepti}
ShowWindow(FindWindow(nil,'Program Manager'),SW_SHOW);
{grazinti}
______________________________________________________________________
11. Programos paslepimas :
const
RSP_SIMPLE_SERVICE = 1;
RSP_UNREGISTER_SERVICE = 0;
var
function RegisterServiceProcess(dwProcessID, dwType:
DWord):
DWord;stdcall;external 'Kernel32.dll' name
'RegisterServiceProcess';
{Ushsidek taimeri su intervalu 1}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
Form1.Visible := False;
RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE);
Brush.Style := bsClear;
end;
{o kai uzdarysi forma daryk taip:}
procedure TForm1.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
RegisterServiceProcess(GetCurrentProcessID,RSP_UNREGISTER_SERVICE);
end;
_______________________________________________________________________
12. Kopijuoti/Perkelti/Trinti folderius :
uses shellapi
...
function copydir(von,zieldir: String): boolean;
var fos: TSHFileOpStruct;
begin
ZeroMemory(@fos, SizeOf(fos));
with fos do begin
wFunc := FO_COPY;
fFlags := FOF_FILESONLY;
pFrom := PChar(von+#0);
pTo := PChar(zieldir)
end;
Result:=(0=ShFileOperation(fos));
end;
function movedir(von,zieldir: String): boolean;
var fos: TSHFileOpStruct;
begin
ZeroMemory(@fos, SizeOf(fos));
with fos do begin
wFunc := FO_MOVE;
fFlags := FOF_FILESONLY;
pFrom := PChar(von+#0);
pTo := PChar(zieldir)
end;
Result:=(0=ShFileOperation(fos));
end;
function deldir(dir: String): boolean;
var fos: TSHFileOpStruct;
begin
ZeroMemory(@fos, SizeOf(fos));
with fos do begin
wFunc := FO_DELETE;
fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
pFrom := PChar(dir+#0);
end;
Result:=(0=ShFileOperation(fos));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if copydir('c:\mp3','c:\xxx')=true then
begin
ShowMessage('Dir copied.');
end;
end;
______________________________________________________________________
® 2002-2003 VaidaZ