?? auto.txt
字號:
用Delphi的人對TMediaPlayer組件比較熟悉,它是一個相當出色的多用途的多媒體組件,但是美中不足的是:如果CDROM光驅的倉門打開就不能自動關閉。而且不幸的是,TMediaPlayer的方法和屬性中沒有解決這個問題的辦法,所以我們不得不求助于Windows API,具體一些就是使用MMSystem.pas文件,另外一件需要注意的事是:我們可以單獨調用Windows API函數,但是TMediaPlayer做了一些內部處理,所以我們就不必擔心我們是否使用了組件。所以本例中使用了TMediaPlayer。
第一步 新建一個工程,然后把一個TMediaPlayer 和 TButton拖到它上面。
第二步 在窗體的uses語句中添加一個MMSystem聲明。
第三步 設置TMediaPlayer的AutoOpen屬性為真,設置DeviceType屬性為dtCDAudio,除此之外我們還可以關閉EnabledButtons屬性的btEject選項,因為我們將使用代碼來完成這個功能。
第四步 在某些應用程序中,我還要使用到數據CD,所以我也要設置Visible屬性為假,讓我的按鈕做開關倉門的動作。
第五步 就是在按鈕的onclick 事件中添加下面的代碼:
procedure TForm1.Button2Click(Sender: TObject);
begin
with MediaPlayer1 do
if (MediaPlayer1.Mode = mpOpen) then
mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0)
else
mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
end;
注意,我們使用了mciSendCommand函數,在Windows中,每個東西都是被消息控制,在設備控制方面,mciSnedCommand與windows的WndProc非常相似,都象是一個消息分發器,提供給設備了消息類型、消息標志、消息參數以及你所使用的方法。如果您想了解更詳細的信息的話,請您參閱幫助文件。
AND Stepping, 0FH //取得CPU STEPPING數送入到變量Stepping中
AND AL, 0F0H
SHR AL, 4
MOV Model, AL //取得CPU MODEL數送入到變量Model中
SHR AX, 8
AND AL, 0FH
MOV Family, AL //取得CPU FAMILYG數送入到變量Family中
POP EAX
end;
//RSA的加密和解密函數,等價于(m^e) mod n(即m的e次冪對n求余)
function Encrypt_Decrypt(m: Int64; e: Int64=$2C86F9; n: Int64=$69AAA0E3): Int64;
var
a, b, c: Int64;
begin
a:=m;
b:=e;
c:=1;
while b<>0 do
if (b mod 2)=0
then begin
b:=b div 2;
a:=(a * a) mod n;
end
else begin
b:=b - 1;
c:=(a * c) mod n;
end;
Result:=c;
end;
procedure TForm1.GetKeySpeedButtonClick(Sender: TObject);
var
ID, UserName, CpuVer: String;
s: Array [1..4] of Cardinal;
temp, Num1, Num2: Cardinal;
Code1, Code2: Int64;
i, ascii: Byte;
Reg: TRegistry;
begin
if (Edit1.Text='') and (CheckBox1.Checked=False)
then Application.MessageBox('請輸入注冊申請碼!', '警告', MB_OK);
if (Edit1.Text='') and (CheckBox1.Checked=True)
then Application.MessageBox('請輸入注冊者姓名!', '警告', MB_OK);
if (CheckBox1.Checked=true) and (Edit1.Text<>'')
then begin
UserName:=Edit1.Text; //從Edit1.Text中取得用戶名
GetCpuID; //調用過程GetCpuID
CpuVer:='Level '+IntToStr(Family)+' Rev. '+IntToStr(Model)+'.'+IntToStr(Stepping);
temp:=1;
i:=1;
while UserName[i]<>#0 do begin
ascii:=ord(UserName[i]); //函數ord()的作用為取得字符的ASCII碼
temp:=(temp*ascii+$D0878) mod $F4240;
inc(i);
end;
i:=1;
while CpuVer[i]<>#0 do begin
ascii:=ord(CpuVer[i]);
temp:=(temp*ascii+$2597D) mod $F4240;
inc(i);
end;
ID:=IntToStr(temp);
end;
if (CheckBox1.Checked=false) and (Edit1.Text<>'')
then ID:=Edit1.Text;
ID:=ID+'1234567';
SetLength(ID, 8); //把字符串ID長度變為8個,并把后面的字符截掉
//下面四行語句是把字符串'You are big pig.'的內存數據送到變量s中
s[1]:=$20756f59;
s[2]:=$20657261;
s[3]:=$20676962;
s[4]:=$2e676970;
Num1:=0;
for i:=4 downto 2 do
Num1:=(Num1+ord(ID[i])) shl 8;
Num1:=Num1+ord(ID[1]);
Num2:=0;
for i:=8 downto 6 do
Num2:=(Num2+ord(ID[i])) shl 8;
Num2:=Num2+ord(ID[5]);
temp:=0;
for i:=1 to 32 do begin
temp:=temp+$9E3779B9;
Num1:=Num1+(Num2 shl 4)+(s[1] xor Num2)+((Num2 shr 5) xor temp)+s[2];
Num2:=Num2+(Num1 shl 4)+(s[3] xor Num1)+((Num1 shr 5) xor temp)+s[4];
end;
Code1:=(Num1 mod $40000000) + 2;
Code2:=($93E0014 shl 2)+ Num1 div $40000000 + 2;
Code1:=Encrypt_Decrypt(Code1);
code2:=Encrypt_Decrypt(Code2);
if (CheckBox1.Checked=False) and (Edit1.Text<>'')
then begin
Edit2.Text:=IntToHex(Code1, 8);
Edit3.Text:=IntToHex(Code2, 8);
end;
if (CheckBox1.Checked=True) and (Edit1.Text<>'')
then begin
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('Software\Wom', True)
then begin
Reg.DeleteValue('Masters');
Reg.WriteString('Register', UserName);
Reg.WriteString('Register_1', IntToHex(Code1, 8));
Reg.WriteString('Register_2', IntToHex(Code2, 8));
end;
Reg.Free;
Application.MessageBox('自動注冊完成!', '信息', MB_OK);
end;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked=true
then begin
GetKeySpeedButton.Caption:='自動注冊';
Label1.Caption:='注冊者姓名';
Edit1.MaxLength:=0;
Label2.Visible:=false;
Label3.Visible:=false;
Edit2.Visible:=false;
Edit3.Visible:=false;
end
else begin
GetKeySpeedButton.Caption:='取得注冊碼';
Label1.Caption:='注冊申請碼';
Edit1.MaxLength:=8;
Label2.Visible:=true;
Label3.Visible:=true;
Edit2.Visible:=true;
Edit3.Visible:=true;
end;
end;
end.
propertyDataSource:TDataSourcereadGetDataSource
writeSetDataSource;//為控件增加DataSource屬性,使它能與DataSource構件連接propertyDataField:StringreadGetDataField
writeSetDataField;
end;//為控件增加DataField屬性,使它指向代表某一字段的TField對象procedureRegister;//注冊構件implementation
procedureTDBDateTime.CMExit;
begin
try
FDataLink.UpdateRecord;
//控件失去焦點時更新DataSet,這將觸發OnUpdateData事件except
Setfocus;
raise;
end;
DoExit;
end;
constructorTDBDateTime.Create(Aowner:Tcomponent);
begin
inheritedCreate(Aowner);
//創建DataLink對象,掛接OnDataChange、OnUpdateData事件處理句柄FDataLink:=TFieldDataLInk.Create;
FDataLink.OnDataChange:=DataChange;
FDataLink.OnUpdateData:=Updatedata;
end;
DestructorTDBDateTime.Destroy;
begin
FDataLink.OnDataChange:=nil;
FDataLink.OnUpdateData:=nil;
FDataLink.Free;
inheritedDestroy;
end;
functionTDBDateTime.GetdataSource:TdataSource;
begin
result:=FDataLink.DataSource;
end;
ProcedureTDBDateTime.SetDataSource(Value:TDataSource);
begin
FDataLink.DataSource:=Value;
end;
functionTDBDateTime.GetDatafield:String;
begin
result:=FDataLink.FieldName;
end;
procedureTDBDateTime.SetDataField(value:String);
begin
FdataLink.FieldName:=value;
end;
procedureTDBDateTime.DataChange(Sender:Tobject);
begin
DateTime:=now;
//若控件連了活動的DataSet則數據集變動時控件顯示當前記錄的相應字段值ifFDataLink.Field nilthen
ifFDataLink.Field.Text ''then
DateTime:=FDatalink.Field.AsDateTime;
end;
ProcedureTDBDateTime.UpdateData(sender:Tobject);
begin
FDatalink.Field.AsDateTime:=DateTime;
//用控件中的日期、時間更新相應字段end;
procedureTDBDateTime.Change;
begin
//當用戶改變了控件中的內容時將DataSet置為編輯狀態FDataLink.Modified;
ifnotFDataLink.Editingthen
FdataLink.Edit;
inheritedChange;
end;
procedureTDBDateTime.Notification(AComponent:
TComponent;Operation:TOperation);
begin
inheritedNotification(Acomponent
Operation);
//當與控件相連的TdataSource
被刪除時將控件的DataSource屬性置為空if(Operation=opRemove)and(FDataLink nil)
and(AComponent=Datasource)then
DataSource:=nil;
end;
procedureRegister;
begin
RegisterComponents('DataControls'
[TDBDateTime]);//控件注冊后安裝于DataControls頁end;
end.
本控件安裝后能以下拉日歷和遞增遞減方式改變數據庫的日期時間型字段,并能以長、短兩種格式顯示日期,方便實用。
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -