照着別人的代碼寫了個“設置個性CMD的東西”
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Registry; type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Memo1: TMemo; Label2: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure SetBat(const Path:string = ''); var reg:TRegistry; begin reg:=TRegistry.Create; reg.RootKey:=HKEY_LOCAL_MACHINE; reg.OpenKey('/SOFTWARE/Microsoft/Command Processor',True); reg.WriteString('AutoRun',Path); reg.Free; if Path<>'' then MessageDlg('設置完畢',mtInformation,[mbok],0) else MessageDlg('已經還原',mtInformation,[mbOK],0); end; procedure DirPath(const Title:String;ITems:TStrings); var path,s:string; F:Textfile; i:Integer; WinPath:array[0..MAX_PATH] of Char; //第二個參數表示winding盤符路徑最大長度 begin GetWindowsDirectory(WinPath,MAX_PATH);//得到windows目錄 path:=(WinPath+'/hellsb.bat'); //path此時等於:PATH=WINDOWS/HELLSB.BAT AssignFile(f,path); //在windows下創建名爲hellsb.bat的文件 Rewrite(f); //會覆蓋已存在的文件 writeln(f,'@echo off'); //像hellsb.bat下寫入文件 Writeln(f,'cls'); Writeln(f,'title ' + title); if ITems.Count-1 > -1 then begin for i:=0 to ITems.Count-1 do begin S:=Trim(ITems[i]); Writeln(f,'echo ' + s); end; end; CloseFile(f); if FileExists(path) then setbat(path); //如果存在文件的話就進行傳參 end; procedure TForm1.Button3Click(Sender: TObject); begin WinExec('Cmd.exe',1) //打開CMD,第二個參數爲非0的正整數 end; procedure TForm1.Button1Click(Sender: TObject); begin DirPath(Edit1.Text,Memo1.Lines); //調用DirPath並進行傳參 end; procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(Memo1.Handle,GWL_STYLE,GetWindowLong(Memo1.Handle,GWL_STYLE) or ES_CENTER); //設置文字居中顯示,同樣適用於TEdit組件 end; end.
不盡人意,希望看到的大大幫我改正。 var reg,reg1:TRegistry; title,url:string; function SetReg():Boolean; begin SetWindowLong(Form
Delphi實現窗體總是向前操作 procedure TForm1.Button1Click(Sender: TObject); begin if form1.FormStyle=fsNormal then //默認操作
獲取指定窗口句柄結束進程 OpenProcess FindWindow GetExitCodeprocess TerminateProcess procedure TForm1.Button1Click(Sender: TObject);