一.设置开机启动时不在任务栏显示uses Registry ;procedure Tsystembd . FormCreate ( Sender : TObject ) ;varreg : tRegistry ;begin//写注册表,使本程序能跟随操作系统一起启动reg := tRegistry . Create ;tryreg . RootKey := HKEY_LOCAL_MACHINE ;if reg . OpenKey ( 'SOFTWAREMicrosoftWindowsCurrentVersionRun' , True ) thenif reg . ReadString ( 'CSRSS' ) <> application . ExeName thenreg . WriteString ( 'CSRSS' , application . ExeName ) ;finallyreg . Free ;end ;end ;//不在任务栏显示1 、找到工程文件 ( Project -> View Source ) , 找到如下代码部分 :修改工程文件中的“ Application . MainFormOnTaskbar := True ; ”为“ Application . MainFormOnTaskbar := False ; ”2 在主窗体的 OnShow 事件中写下varStyle : Integer ;beginStyle := GetWindowLong ( Handle , GWL_EXSTYLE ) ;SetWindowLong ( Handle , GWL_EXSTYLE , Style and ( not WS_EX_APPWINDOW )) ;ShowWindow ( Application . Handle , SW_HIDE ) ;end3 把窗体的 Visble 属性设置成 False ;二.DELPHI高精度计时方法,取毫秒级时间精度(方法一)://取毫秒级时间精度(方法一):vart1 , t2 : int64 ;r1 : int64 ;begint1 := GetTickCount ; //获取开始计数 WINDOWS APIsleep ( 1000 ) ; {do...} //执行要计时的代码t2 := GetTickCount ; //获取结束计数值r1 := t2 - t1 ; //取得计时时间,单位毫秒(ms)showmessage ( inttostr ( r1 )) ;end ;//取毫秒级时间精度(方法二)://use DateUtils;//引用DateUtils单位vart1 , t2 : tdatetime ;r1 : int64 ;begint1 := now () ; //获取开始计时时间sleep ( 1000 ) ; {do...} //执行要计时的代码t2 := now () ; //获取结束计时时间r1 := SecondsBetween ( t2 , t1 ) ; //取得计时时间,单位秒(s)r1 := MilliSecondsBetween ( t2 , t1 ) ; //取得计时时间,单位毫秒(ms)showmessage ( inttostr ( r1 )) ;end ;//注:以上两种方式经本人测试好像只能产生0.01秒的计时精度//取系统级时间精度:varc1 : int64 ;t1 , t2 : int64 ;r1 : double ;beginQueryPerformanceFrequency ( c1 ) ; //WINDOWS API 返回计数频率(Intel86:1193180)(获得系统的高性能频率计数器在一毫秒内的震动次数)QueryPerformanceCounter ( t1 ) ; //WINDOWS API 获取开始计数值sleep ( 1000 ) ; {do...} //执行要计时的代码QueryPerformanceCounter ( t2 ) ; //获取结束计数值r1 := ( t2 - t1 ) / c1 ; //取得计时时间,单位秒(s)r1 := ( t2 - t1 ) / c1 * 1000 ; //取得计时时间,单位毫秒(ms)r1 := ( t2 - t1 ) / c1 * 1000000 ; //取得计时时间,单位微秒showmessage ( floattostr ( r1 )) ;end ;三.TStringList的用法varsl : TStringList ;str : string ;i : Integer ;beginstr := 'aa,b b,cc,dd' ;sl := TStringList . Create ;sl . Delimiter := ',' ;sl . DelimitedText := str ;for i := 0 to sl . Count - 1 doShowMessage ( sl [ i ]) ;FreeAndNil ( sl ) ;end ;这样写,对于有空格的字符会有 BUG 的可以采取下列做法://uses IdStringsvarsl : TStringList ;str : string ;i : Integer ;beginstr := 'aa,b b,cc,dd' ;sl := TStringList . Create ;SplitColumns ( str , sl , ',' ) ; //该函数没有上述的BUGfor i := 0 to sl . Count - 1 doShowMessage ( sl [ i ]) ;FreeAndNil ( sl ) ;end ;四.Delphi实现重启计算机procedure TForm1 . RebootSystem ;varosVerInfo : TOSVersionInfo ;rl : Cardinal ;hToken : Cardinal ;tkp : TOKEN_PRIVILEGES ;beginif OpenProcessToken ( GetCurrentProcess () , TOKEN_ADJUST_PRIVILEGES orTOKEN_QUERY , hToken ) thenbeginosVerInfo . dwOSVersionInfoSize := SizeOf ( TOSVersionInfo ) ;if GetVersionEx ( osVerInfo ) thencase osVerInfo . dwPlatformId ofVER_PLATFORM_WIN32_NT : // Windows NT/2000/XPbeginOpenProcessToken ( GetCurrentProcess , TOKEN_ADJUST_PRIVILEGES orTOKEN_QUERY , hToken ) ;if LookupPrivilegeValue ( nil , 'SeShutdownPrivilege' ,tkp . Privileges [ 0 ] . Luid ) thenbegintkp . Privileges [ 0 ] . Attributes := SE_PRIVILEGE_ENABLED ;tkp . PrivilegeCount := 1 ;AdjustTokenPrivileges ( hToken , False , tkp , 0 , nil , rl ) ;end ;// ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE + EWX_POWEROFF, 0); //关闭计算机ExitWindowsEx ( EWX_REBOOT , $FFFF ) ; // 重启end ;VER_PLATFORM_WIN32_WINDOWS : // Windows 95/98/98SE/Mebegin// ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE + EWX_POWEROFF, 0); //关闭计算机ExitWindowsEx ( EWX_REBOOT , $FFFF ) ; // 重启end ;end ;end ;end ;调用 :procedure TForm1 . X1Click ( Sender : TObject ) ;beginif MessageBox ( 0 , '你要重启计算机吗?' , '警告' , MB_ICONQUESTION or MB_YESNO ) = idyes thenbeginRebootSystem ;end ;application . Terminate ;end ;
几个delphi例子
最新推荐文章于 2024-02-21 09:04:25 发布