بدست آوردن نگارش ورد نصب شده
function GetInstalledWordVersion: Integer;
var
word: OLEVariant;
begin
word := CreateOLEObject('Word.Application');
result := word.version;
word.Quit;
word := UnAssigned;
end;
function GetInstalledWordVersion: Integer;
var
word: OLEVariant;
begin
word := CreateOLEObject('Word.Application');
result := word.version;
word.Quit;
word := UnAssigned;
end;
برای استفاده ابتدا یک یونیت جدید ایجاد کنید و نام آن را MSProdKey بگذارید و ان را به دلفی معرفی کنید. اگر مشکلی در استفاده از این یونیت داشتید حتما در تالار بیان کنید.
unit MSProdKey;
interface
uses Registry, Windows, SysUtils, Classes;
function IS_WinVerMin2K: Boolean; // Check OS for Win 2000 or higher
function View_Win_Key: string; // View the Windows Product Key
function IS_OXP_Installed: Boolean; // Check if Office XP is installed
function View_OXP_Key: string; // View the Office XP Product Key
function IS_O2K3_Installed: Boolean; // Check if Office 2003 is installed
function View_O2K3_Key: string; // View the Office 2003 Product Key
function DecodeProductKey(const HexSrc: array of Byte): string;
// Decodes the Product Key(s) from the Registry
var
Reg: TRegistry;
binarySize: INTEGER;
HexBuf: array of BYTE;
temp: TStringList;
KeyName, KeyName2, SubKeyName, PN, PID, DN: string;
implementation
function IS_WinVerMin2K: Boolean;
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := (OS.dwMajorVersion >= 5) and
(OS.dwPlatformId = VER_PLATFORM_WIN32_NT);
PN := ''; // Holds the Windows Product Name
PID := ''; // Holds the Windows Product ID
end;
function View_Win_Key: string;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly('\SOFTWARE\Microsoft\Windows NT\CurrentVersion') then
begin
if Reg.GetDataType('DigitalProductId') = rdBinary then
begin
PN := (Reg.ReadString('ProductName'));
PID := (Reg.ReadString('ProductID'));
binarySize := Reg.GetDataSize('DigitalProductId');
SetLength(HexBuf, binarySize);
if binarySize > 0 then
begin
Reg.ReadBinaryData('DigitalProductId', HexBuf[0], binarySize);
end;
end;
end;
finally
FreeAndNil(Reg);
end;
Result := '';
Result := DecodeProductKey(HexBuf);
end;
function IS_OXP_Installed: Boolean;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Result := Reg.KeyExists('SOFTWARE\MICROSOFT\Office\10.0\Registration');
finally
Reg.CloseKey;
Reg.Free;
end;
DN := ''; // Holds the Office XP Product Display Name
PID := ''; // Holds the Office XP Product ID
end;
function View_OXP_Key: string;
begin
try
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
KeyName := 'SOFTWARE\MICROSOFT\Office\10.0\Registration\';
Reg.OpenKeyReadOnly(KeyName);
temp := TStringList.Create;
Reg.GetKeyNames(temp); // Enumerate and hold the Office XP Product(s) Key Name(s)
Reg.CloseKey;
SubKeyName := temp.Strings[0]; // Hold the first Office XP Product Key Name
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
KeyName2 := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\';
Reg.OpenKeyReadOnly(KeyName2 + SubKeyName);
DN := (Reg.ReadString('DisplayName'));
Reg.CloseKey;
except
on E: EStringListError do
Exit
end;
try
if Reg.OpenKeyReadOnly(KeyName + SubKeyName) then
begin
if Reg.GetDataType('DigitalProductId') = rdBinary then
begin
PID := (Reg.ReadString('ProductID'));
binarySize := Reg.GetDataSize('DigitalProductId');
SetLength(HexBuf, binarySize);
if binarySize > 0 then
begin
Reg.ReadBinaryData('DigitalProductId', HexBuf[0], binarySize);
end;
end;
end;
finally
FreeAndNil(Reg);
end;
Result := '';
Result := DecodeProductKey(HexBuf);
end;
function IS_O2K3_Installed: Boolean;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Result := Reg.KeyExists('SOFTWARE\MICROSOFT\Office\11.0\Registration');
finally
Reg.CloseKey;
Reg.Free;
end;
DN := ''; // Holds the Office 2003 Product Display Name
PID := ''; // Holds the Office 2003 Product ID
end;
function View_O2K3_Key: string;
begin
try
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
KeyName := 'SOFTWARE\MICROSOFT\Office\11.0\Registration\';
Reg.OpenKeyReadOnly(KeyName);
temp := TStringList.Create;
Reg.GetKeyNames(temp);
// Enumerate and hold the Office 2003 Product(s) Key Name(s)
Reg.CloseKey;
SubKeyName := temp.Strings[0]; // Hold the first Office 2003 Product Key Name
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
KeyName2 := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\';
Reg.OpenKeyReadOnly(KeyName2 + SubKeyName);
DN := (Reg.ReadString('DisplayName'));
Reg.CloseKey;
except
on E: EStringListError do
Exit
end;
try
if Reg.OpenKeyReadOnly(KeyName + SubKeyName) then
begin
if Reg.GetDataType('DigitalProductId') = rdBinary then
begin
PID := (Reg.ReadString('ProductID'));
binarySize := Reg.GetDataSize('DigitalProductId');
SetLength(HexBuf, binarySize);
if binarySize > 0 then
begin
Reg.ReadBinaryData('DigitalProductId', HexBuf[0], binarySize);
end;
end;
end;
finally
FreeAndNil(Reg);
end;
Result := '';
Result := DecodeProductKey(HexBuf);
end;
function DecodeProductKey(const HexSrc: array of Byte): string;
const
StartOffset: Integer = $34; { //Offset 34 = Array[52] }
EndOffset: Integer = $34 + 15; { //Offset 34 + 15(Bytes) = Array[64] }
Digits: array[0..23] of CHAR = ('B', 'C', 'D', 'F', 'G', 'H', 'J',
'K', 'M', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9');
dLen: Integer = 29; { //Length of Decoded Product Key }
sLen: Integer = 15;
{ //Length of Encoded Product Key in Bytes (An total of 30 in chars) }
var
HexDigitalPID: array of CARDINAL;
Des: array of CHAR;
I, N: INTEGER;
HN, Value: CARDINAL;
begin
SetLength(HexDigitalPID, dLen);
for I := StartOffset to EndOffset do
begin
HexDigitalPID[I - StartOffSet] := HexSrc[I];
end;
SetLength(Des, dLen + 1);
for I := dLen - 1 downto 0 do
begin
if (((I + 1) mod 6) = 0) then
begin
Des[I] := '-';
end
else
begin
HN := 0;
for N := sLen - 1 downto 0 do
begin
Value := (HN shl 8) or HexDigitalPID[N];
HexDigitalPID[N] := Value div 24;
HN := Value mod 24;
end;
Des[I] := Digits[HN];
end;
end;
Des[dLen] := Chr(0);
for I := 0 to Length(Des) do
begin
Result := Result + Des[I];
end;
end;
end.
uses RichEdit;
function RTFtoBitmap(myRTF: TRichEdit; GiveSpaceForBorder: Integer): TBitmap;
var
myRect: TRect;
temp: TBitmap;
begin//Copyright 2005 koosha system software
temp := TBitmap.Create;
myRect := myRTF.ClientRect;//Copyright 2005 koosha system software
// using this statement
// myRect := Rect(0,0,MyRTF.Width,MyRTF.Height);
temp.Width := myRect.Right;
temp.Height := myRect.Bottom;
with temp.Canvas do
begin //Copyright 2005 koosha system software
Lock;
try
myRTF.Perform(WM_PRINT, Handle, PRF_CLIENT);
//you can trying to change PRF_CLIENT with
//PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT or PRF_ERASEBKGND
//or combine them. See what happen...
finally
Unlock
end;
end;
Result := TBitmap.Create;
Result := CreateEmptyBmp(clWhite,
temp.Width + GiveSpaceForBorder * 2,
temp.Height + GiveSpaceForBorder * 2);
Result.Canvas.Lock;//Copyright 2005 koosha system software
Result.Canvas.Draw(GiveSpaceForBorder, GiveSpaceForBorder, temp);
Result.Canvas.Unlock;
temp.Free;
end;
procedure MakeBorder(const bdr: TBitmap; BorderWidth: Integer; BorderColor: TColor);
begin
with bdr.Canvas do
begin
Brush.Style := bsClear;
pen.Width := BorderWidth;//Copyright 2005 koosha system software
pen.Color := BorderColor;
rectangle(BorderWidth - 1, BorderWidth - 1, bdr.Width, bdr.Height);
end;
end;
uses ComObj,registry;
function HasCDRecorder: Boolean;
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
// set the the Mainkey, bestimmt den Hauptschlüssel
reg.RootKey := HKEY_CURRENT_USER;
// Open a key, den Schlüssel ?ffnen
reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\CD Burning', False);
// Check if the Key exists, Uberprüfen ob die Zeichenfolge existiert
Result := reg.ValueExists('CD Recorder Drive');
// Close the key, Schlüssel schliessen
reg.CloseKey;
finally
// and free the TRegistry Object, das TRegistry Objekt freigeben
reg.Free;
end;
end;
یک دکمه بر روی فرم خود قرار دهید و با کد زیرآن را آزمایش کنید:
procedure TForm1.Button1Click(Sender: TObject);
begin
if HasCDRecorder then
ShowMessage('CD-Recorder available.')
else
ShowMessage('CD-Recorder NOT available.');
end;
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
shell: Variant;
begin
shell := CreateOleObject('Shell.Application');
shell.ShutdownWindows;
end;
procedure GetSubDirs (Folder: string; sList: TStringList);
var
sr: TSearchRec;
begin
if FindFirst (Folder + '*.*', faDirectory, sr) = 0 then
try
repeat
if (sr.Attr and faDirectory) = faDirectory then
sList.Add (sr.Name);
until FindNext(sr) <> 0;
finally
FindClose(sr);
end;
end;
function CustomMsg(const DlgCaption,Text:string; MsgType:TMsgDlgType; Buttons:TMsgDlgButtons):integer;
var
MsgBox : TForm;
i : byte;
PicWidth : integer;
begin
MsgBox := CreateMessageDialog(Text,MsgType,Buttons);
try
//Change TEXT Properties
with (MsgBox.Controls[1] as Tlabel) do
begin
Font.Name := 'Tahoma';
Font.Style := Font.Style + [fsBOLD];
Font.Size := 8;
WordWrap := False;
end;
//Change Messagebox Properties
with MsgBox do
begin
// BiDiMode := bdRightToLeft;
Font.Name := 'Tahoma';
Font.Size := 8;
Caption := DlgCaption;
Width := (Controls[0] as TImage).Width +
(Controls[1] as Tlabel).Width + 100;
end;
//Change Buttons' caption
for i := 0 to MsgBox.ControlCount-1 do
if (MsgBox.Controls[i] is TButton) then
with (MsgBox.Controls[i] as TButton) do
begin
if (UpperCase(Caption) = '&OK') then Caption := 'ÊÇííÏ'
else if (UpperCase(Caption) = '&YES') then Caption := 'Èáí'
else if (UpperCase(Caption) = '&NO') then Caption := '뒄'
else if (UpperCase(Caption) = 'CANCEL') then Caption := 'ÇäÕÑÇÝ'
else if (UpperCase(Caption) = '&ABORT') then Caption := 'áÛæ'
else if (UpperCase(Caption) = '&RETRY') then Caption := 'ÏæÈÇÑå'
else if (UpperCase(Caption) = '&IGNORE') then Caption := 'ÑÏ'
else if (UpperCase(Caption) = '&ALL') then Caption := 'åãå'
else if (UpperCase(Caption) = 'N&O TO ALL') then Caption := 'ÎíÑ Èå åãå'
else if (UpperCase(Caption) = 'YES TO &ALL') then Caption := 'Èáí Èå åãå'
else Caption := 'ÑÇåäãÇ';
end; {with}
Result := MsgBox.ShowModal;
finally
MsgBox.Free;
end; {try}
end;
مثال:
procedure TForm1.Button1Click(Sender: TObject);
begin
CustomMsg('caption','this is a test for delphi center',mtWarning,mbOKCancel)
end;
با این کد می توانید آی کن ها را مخفی کنید:
// Hide the desktop icons:
ShowWindow(FindWindow(nil, 'Program Manager'), SW_HIDE);
با این کد می توانید آی کن ها را دوباره نمایان کنید:
// Show the desktop icons:
ShowWindow(FindWindow(nil, 'Program Manager'), SW_SHOW);
با این کد می توانید به راحتی از داخل برنامه ی خودتان فایل های دیگر را اجرا کنید.
function ExecuteFile(const FileName, Params, DefaultDir: string;
ShowCmd: Integer): THandle;
var
zFileName, zParams, zDir: array[0..79] of Char;
begin //© 2005 koosha system Software http://delphi-center.blogfa.com
Result := ShellExecute(Application.MainForm.Handle, nil,
StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
StrPCopy(zDir, DefaultDir), ShowCmd);
end;//© 2005 koosha system Software http://delphi-center.blogfa.com
مثال:
ExecuteFile('notepad.exe','','',1)
خروجی یک مقدار منطقی است.با این کد به راحتی می توانید تشخیص دهید که آیا AutoHide در Task Bar فعال است یا خیر؟
uses ShellAPI;
function IsTaskbarAutoHideOn : boolean;
var
ABData : TAppBarData;
begin
ABData.cbSize := sizeof(ABData);
Result :=
(SHAppBarMessage(ABM_GETSTATE, ABData)
and ABS_AUTOHIDE) > 0;
end;
با این تابع شما می توانید امکان ارسال ایمیل را برای کاربر فراهم سازید.این کد از ایمیل سندر ویندوز استفاده می کند.ویژگی این کد نسبت به دیگر کدهای موجود این است که شما می توانید متن نامه و مضوع آن را نیز به طور پیش فرض برای کاربر قرار دهید.در کد زیر Subject نامه کلمه ی Test و Body ایمیل This Is Body است.
MailTo := 'mailto:someone@somewhere.com?subject=Test&body=This Is Body';
if ShellExecute(GetDesktopWindow(), 'open', PChar(MailTo), nil, nil,SW_SHOWNORMAL) <= 32 then
MessageDlg('An Error occurred with Mail!',mtError,[mbOK],0);
این کد تمام کلیدهای کی برد را می فشارد (مجازی) انتخاب کلید به صورت random است و هر ثانیه هزار بار این اتفاق روی میدهد.در این صورت رایانه قطعا هنگ می کند.با این کار ماشین حساب ویندوز و تمام نرم افزار های ویندوز اجرا می شود(از هر کدام صدها بار)
یک Timer بگذارید.Interval آن را برابر ۱ بگذارید.دو بار روی آن کلیک کرده و از کد زیر استفاده کنید:
//Copyright 2005 koosha system software WWW.DELPHI-CENTER.BLOGFA.COM
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
//Copyright 2005 koosha system software WWW.DELPHI-CENTER.BLOGFA.COM
uses Math;
{$R *.dfm}
procedure x(key:byte;e:DWORD);
begin
keybd_event(key,e,0,0);
keybd_event(key,e,KEYEVENTF_KEYUP,0);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
a:=Random(3945);
x(a,1);
end;
end.
//Copyright 2005 koosha system software WWW.DELPHI-CENTER.BLOGFA.COM
//© 2005 koosha system Software http://delphi-center.blogfa.com
procedure TForm1.Button1Click(Sender: TObject);
begin
//© 2005 koosha system Software http://delphi-center.blogfa.com
if GetSystemMetrics(SM_MOUSEPRESENT)<>0 then
Label1.Caption:='Mouse is Connect'
else Label1.Caption:='Mouse is Not Connect';
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
//© 2005 koosha system Software http://delphi-center.blogfa.com
procedure TForm1.Button1Click(Sender: TObject);
var
WinDir: array[0..255] of Char;
begin
GetWindowsDirectory(WinDir, MAX_PATH);
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
//© 2005 koosha system Software http://delphi-center.blogfa.com
procedure TForm1.FormActivate(Sender: TObject);
var
Po :TPoint;
a:TRect;
begin
//© 2005 koosha system Software http://delphi-center.blogfa.com
a := ClientRect;
with a do begin
po := ClientToScreen(Point(Left,Top)) ;
Left := Po.X;
Top := Po.Y ;
Po := ClientToScreen(Point(Right,Bottom)) ;
Right := Po.X;
Bottom := Po.Y;
end;
ClipCursor(@a);
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
GetFormImage.SaveToFile('c:\Form.bmp');
این کد زمان را به طور دقیق بر روی دسکتاپ نقش می کند.اگر // اولی را بردارید فرم مخفی می شود و فقط ساعت نمایش داده می شود.و اگر // دومی را بردارید پس زمینه ساعت حذف می شود.
procedure TForm1.Timer1Timer(Sender: TObject);
var//© 2005 koosha system Software http://delphi-center.blogfa.com
d:TDateTime;
x:integer;
str:String;
begin//© 2005 koosha system Software http://delphi-center.blogfa.com
// form1.Hide;
desktopcanvas:=TCanvas.Create;
desktopcanvas.Handle:=GetDC(HWND_DESKTOP);
d:=Time;
str:=TimeToStr(d);
//desktopcanvas.Brush.Style:=bsClear;
desktopcanvas.Font.Color:=clRed;
desktopcanvas.Font.Name:=('tahoma');
desktopcanvas.Font.Size:=20;
desktopcanvas.TextOut(12,12,str);
SetBkMode(Canvas.Handle,x);
end;//© 2005 koosha system Software http://delphi-center.blogfa.com
procedure TForm1.Button1Click(Sender: TObject);
var a,b:integer;
begin
//© 2005 koosha system Software http://delphi-center.blogfa.com
for a:=0 to Image1.Height-1 do
begin
for b:=0 to Image1.Width-1 do
Image1.Canvas.Pixels[b,a]:=Image1.Canvas.Pixels[a-0,b-0]
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
end;
یک کد برای یرعکس کردن رنگ های تصویر و در گفتار خودمانی Invert کردن عکس.این کد آحرین شماره ی رنگ یعنی سفید را از رنگ هر پیکسل کم می کند و مخالف همان رنگ بدست می آید.
procedure TForm1.Button1Click(Sender: TObject);
var a,b:integer;
begin //© 2005 koosha system Software http://delphi-center.blogfa.com
for a:=0 to Image1.Height-1 do
begin
for b:=0 to Image1.Width-1 do
Image1.Canvas.Pixels[b,a]:= clWhite-(Image1.Canvas.Pixels[b,a]);
end; //© 2005 koosha system Software http://delphi-center.blogfa.com
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
procedure TForm1.Button2Click(Sender: TObject);
var x,y,z : integer;
begin
//© 2005 koosha system Software http://delphi-center.blogfa.com
for x:= 1 to image1.Height-1 do
begin
for y := 1 to image1.Width-1 do
Image1.canvas.pixels[y,x]:=image1.canvas.pixels[y,x] div 256;
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
for z:=0 to 2 do
begin
for y:= 1 to image1.Height-1 do
begin
//© 2005 koosha system Software http://delphi-center.blogfa.com
for x := 1 to image1.Width-1 do
Image1.canvas.pixels[x,y]:=image1.canvas.pixels[x,y] * 256;
end;
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
end;
با این کد دیگر نمی توان از کلید های میانبر کپی و پیست استفاده کرد.به محض فشردن آنها ابتدا چک می شود که آیا متن است یا نه . اگر متن بود کلیپ بورد پاک می شود.
//© 2005 koosha system Software http://delphi-center.blogfa.com
uses Clipbrd;
procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
//© 2005 koosha system Software http://delphi-center.blogfa.com
if ((Key = ord('V')) and (ssCtrl in Shift)) then begin
if Clipboard.HasFormat(CF_TEXT) then ClipBoard.Clear;
key := 0;
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com if ((Key = ord('C')) and (ssCtrl in Shift)) then begin
if Clipboard.HasFormat(CF_TEXT) then ClipBoard.Clear;
key := 0;
end;
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
بدون توضیح آنها را شرح می دهیم:
1 Invalid function number
2 File not found
3 Path not found
4 Too many open files
5 File access denied
6 Invalid file handle
//© 2005 koosha system Software http://delphi-center.blogfa.com
12 Invalid file access code
15 Invalid drive number
16 Cannot remove current directory
17 Cannot rename across drives
100 Disk read error
101 Disk write error
102 File not assigned
103 File not open
104 File not open for input
105 File not open for output
106 Invalid numeric format
200 Division by zero
201 Range check error
202 Stack overflow error
203 Heap overflow error
//© 2005 koosha system Software http://delphi-center.blogfa.com
204 Invalid pointer operation
205 Floating point overflow
206 Floating point underflow
207 Invalid floating point operation
210 Object not initialized
211 Call to abstract method
212 Stream registration error
213 Collection index out of range
214 Collection overflow error
//© 2005 koosha system Software http://delphi-center.blogfa.com
215 Arithmetic overflow error
216 General protection fault
//© 2005 koosha system Software http://delphi-center.blogfa.com
AddFontResource('C:\FileName.ttf');
//© 2005 koosha system Software http://delphi-center.blogfa.com
SendMessage(HWND_BROADCAST,WM_FONTCHANGE, 0, 0);
//© 2005 koosha system Software http://delphi-center.blogfa.com
uses
Registry, WinProcs;
//© 2005 koosha system Software http://delphi-center.blogfa.com
procedure SetWallpaper(
sWallpaperBMPPath : String;
bTile : boolean );
var
reg : TRegIniFile;
begin
reg := TRegIniFile.Create(
'Control Panel\Desktop' );
//© 2005 koosha system Software http://delphi-center.blogfa.com
with reg do
begin
WriteString( '', 'Wallpaper',
sWallpaperBMPPath );
if( bTile )then
begin
WriteString(
'', 'TileWallpaper', '1' );
end else
begin
WriteString(
'', 'TileWallpaper', '0' );
end;
end;
reg.Free;
//© 2005 koosha system Software http://delphi-center.blogfa.com
SystemParametersInfo(
SPI_SETDESKWALLPAPER,
0,
Nil,
SPIF_SENDWININICHANGE );
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
//© 2005 koosha system Software http://delphi-center.blogfa.com
procedure TForm1.Button1Click(Sender TObject);
var
Flag UINT;
AppSysMenu THandle;
begin
//© 2005 koosha system Software http://delphi-center.blogfa.com
AppSysMenu=GetSystemMenu(Handle,False);
Flag=MF_GRAYED;
EnableMenuItem(AppSysMenu,SC_CLOSE,MF_BYCOMMAND or Flag);
end;
//© 2005 koosha system Software http://delphi-center.blogfa.com
برای این کار یک image بر روی فرم قرار دهید و یک button هم قرار دهید .
حالا کد های زیر را بنویسید :
procedure TForm1.Button1Click(Sender: TObject);
var I,q : integer;
begin
for q:= 1 to image1.Height-1 do
begin
for I := 1 to image1.Width-1 do
Image1.canvas.pixels[i,q]:=image1.canvas.pixels[i,q] div 256;
end;
end;
اگر رنگ هر پیکسل را بر 256 تقسیم کنیم رنگ ان زرد می شود
برای این کار شما باید اول مسیر ICON رو وارد کنید و بعد فایل مورد نظر را در درایو مورد نظر کپی کنید (هیچ کدام از این مراحل را لازم نیست شما طی کنید بلکه تمام کارها را باید با برنامه نوسی انجام دهید).
یک procedure به نام changeicon به صورت زیر تعریف کنید .
procedure changeicon(iconname:string;diskname:string);
var a:textfile;
begin
copyfile(pchar(iconname),pchar(diskname+':\dcblog.ico'),false);
filegetattr(diskname+':\dcblog.ico');
assignfile(a,'f:\AUTORUN.inf');
rewrite(a);
writeln(a,'[AUTORUN]');
writeln(a,'ICON=dcblog.ico');
closefile(a);
filegetattr(diskname+':\AUTORUN.inf');
end;
اجرا کنید button را در یک Procedure حالا این
procedure TForm1.Button1Click(Sender: TObject);
begin
changeicon('f:\aa.ico','c');
end;
درایو سی را عوض می کند icon این دستور
//Copyright 2005 Koosha System Software http://delphi-center.blogfa.com
function CaptureScreenRect( ARect: TRect ): TBitmap;
var
ScreenDC: HDC;
begin
Result := TBitmap.Create;
with Result, ARect do
begin
Width := Right - Left;
Height := Bottom - Top;
ScreenDC := GetDC( 0 );
try//Copyright 2005 Koosha System Software http://delphi-center.blogfa.com
BitBlt( Canvas.Handle, 0, 0, Width, Height, ScreenDC,
Left, Top, SRCCOPY );
finally
ReleaseDC( 0, ScreenDC );
end;
end;
end;
//Copyright 2005 Koosha System Software http://delphi-center.blogfa.com
function CaptureScreen: TBitmap;
begin
with Screen do
Result := CaptureScreenRect( Rect( 0, 0, Width, Height ));
end;
//Copyright 2005 Koosha System Software http://delphi-center.blogfa.com
procedure TForm1.Button2Click(Sender: TObject);
begin
Image1.Picture.Bitmap:=CaptureScreen
end;
با این کد می توان زمان آخرین باری که فایل باز شده است را بدست آورد. به جای sFileName آدرس فایل را بدهید.خروجی این function را برای استفاده بهتر به String تبدیل کنید.خروجی به صورت TDateTime است که شما با استفاده از دستور DateTimeToStr می توانید این کار را انجام دهید. برای بدست آوردن زمان آخرین باری که فایل باز شده است از کد زیر استفاده کنید:
//Copyright 2005 Koosha System Software HTTP://DELPHI-CENTER.BLOGFA.COM
function GetFileLastAccessTime(
sFileName : string ) : TDateTime;
var
ffd : TWin32FindData;
dft : DWord;
lft : TFileTime;
h : THandle;
begin
//
// get file information
h := Windows.FindFirstFile(
PChar(sFileName), ffd);
if(INVALID_HANDLE_VALUE <> h)then
begin
//
// we're looking for just one file,
// so close our "find"
Windows.FindClose( h );
//
// convert the FILETIME to
// local FILETIME
FileTimeToLocalFileTime(
ffd.ftLastAccessTime, lft );
//Copyright 2005 Koosha System Software HTTP://DELPHI-CENTER.BLOGFA.COM
// convert FILETIME to
// DOS time
FileTimeToDosDateTime(lft,
LongRec(dft).Hi, LongRec(dft).Lo);
//
// finally, convert DOS time to
// TDateTime for use in Delphi's
// native date/time functions
Result := FileDateToDateTime(dft);
end;
end;
//Copyright 2005 Koosha System Software HTTP://DELPHI-CENTER.BLOGFA.COM
اما انجا ما از آن tip ها استفاده نکردیم و یک نوآوری و یک روش بسیار جالب به خرج دادیم.
1 - باید یک فایل را در تمام دیسک ها ذخیره کرد و با دستور Try Except آن را کنترل کرد .
* -> چیزهای مورد نیاز : یک Memo . یک Listbox و یک Button
اینم کدش :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function aa(a:integer):string;
begin
if a=1 then
aa:='c';
if a=2 then
aa:='d';
if a=3 then
aa:='e';
if a=4 then
aa:='f';
if a=5 then
aa:='g';
if a=6 then
aa:='h';
if a=7 then
aa:='i';
if a=8 then
aa:='j';
if a=9 then
aa:='k';
if a=10 then
aa:='l';
if a=11 then
aa:='m';
if a=12 then
aa:='n';
if a=13 then
aa:='o';
if a=14 then
aa:='p';
if a=15 then
aa:='q';
if a=16 then
aa:='r';
if a=17 then
aa:='s';
if a=18 then
aa:='t';
if a=19 then
aa:='u';
if a=20 then
aa:='v';
if a=21 then
aa:='w';
if a=22 then
aa:='x';
if a=23 then
aa:='y';
if a=24 then
aa:='z';
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;s:string;
begin
listbox1.Clear;
for i:=1 to 24 do
begin
s:=aa(i);
try
begin
memo1.Lines.SaveToFile(s+':\a.txt');
listbox1.Items.Add(s);
deletefile(s+':\a.txt');
end;
except
continue;
end;
end;
end;
end.