AD
AD

Delphi关于系统编程中的技巧

时间:2007-12-26 22:21:49  来源:  作者:
AD

更改Windows95的墙纸。

在Delphi中你可以很方便地更改墙纸,请参考以下的/doc/">程序。 字串4

procedureChangeIt; 字串9

var 字串3

Reg:TregIniFile; 字串3

begin

字串4

Reg:ΚTRegIniFile.Create(′ControlPanel′); 字串5

Reg.WriteString(′desktop′,′Wallpaper′,′c:ιpwin95ιforest.bmp′); 字串5

Reg.WriteString(′desktop′,′TileWallpaper′,′1′);

字串1

Reg.Free; 字串1

SystemParametersInfo(SPI—SETDESKWALLPAPER,0,nil,SPIF—SENDWININICHANGE);

字串1

end; 字串7

字串3

字串3

屏蔽系统按键 字串9

也许您希望您的/doc/">程序在运行时不想让用户按系统按键 Alt-Tab 或  Ctrl-Alt-Del,那么可以通过以下的/doc/">程序段屏蔽这些按键。   字串9

procedure TForm1.FormCreate(Sender: TObject);   字串9

begin  

字串4

var   字串7

tmp : integer;

字串9

begin 字串6

tmp := 0;

字串6

//屏蔽 Alt-Tab

字串6

SystemParametersInfo( SPI_SETFASTTASKSWITCH 字串9

1

字串2

@tmp

字串4

0);

字串9

//屏蔽 Ctrl-Alt-Del 字串9

SystemParametersInfo( SPI_SCREENSAVERRUNNING 字串6

1

字串3

@tmp 字串2

0);   end;  end; 字串8

字串2

字串6

更换墙纸 字串8

SystemParametersInfo(SPI_SETDESKWALLPAPER 字串7

0

字串5

PChar('WallPaper.BMP'

字串7

0); 字串9

字串9

字串5

设置系统日期和时间:

字串4

例如: 字串7

var

字串7

MyST:TSystemTime; 字串8

begin 字串9

with MyST do

字串7

begin

字串9

wYear:=1998; 字串7

wMonth:=12; 字串1

wDay:=7;

字串9

wHour:=8;

字串8

wMinute:=9;

字串3

wSecond:=10; 字串7

end; 字串6

SetSystemTime(MyST); 字串2

end;

字串3

s

字串8

字串1

字串4

如果隐藏和显示Windows的任务条?(Delphi 3 and 2.0) 字串3

如果隐藏和显示Windows的任务条?仅仅调用以下的函数就可以. 字串6

procedure hideTaskbar; //隐藏 字串2

var 字串4

wndHandle : THandle; 字串9

wndClass : array[0..50] of Char;

字串7

begin

字串8

StrPCopy(@wndClass[0]

字串4

'Shell_TrayWnd'); 字串6

wndHandle := FindWindow(@wndClass[0]

字串4

nil);

字串5

ShowWindow(wndHandle

字串3

SW_HIDE);

字串4

字串2

End; 字串9

字串5

procedure showTaskbar;

字串4

var

字串6

wndHandle : THandle;

字串2

wndClass : array[0..50] of Char;

字串5

begin 字串6

StrPCopy(@wndClass[0]

字串2

'Shell_TrayWnd'); 字串8

wndHandle := FindWindow(@wndClass[0] 字串5

nil);

字串2

ShowWindow(wndHandle

字串2

SW_RESTORE);

字串8

end;

字串6

字串9

字串4

控制面板大全 字串6

在/doc/">程序运行过程中启动控制面板的各个设置功能:

字串2

var x:cardinal;

字串5

begin 字串2

{启动控制面板} 字串8

x:=winexec('rundll32.exe shell32.dll 字串3

Control_RunDLL' 字串5

9); 字串3

{辅助选项 属性-键盘} 字串8

x:=winexec('rundll32.exe shell32.dll 字串4

Control_RunDLL access.cpl 字串4

字串4

1'

字串1

9);

字串6

{辅助选项 属性-声音} 字串1

x:=winexec('rundll32.exe shell32.dll 字串3

Control_RunDLL access.cpl

字串8

字串7

2' 字串5

9); 字串8

{辅助选项 属性-显示} 字串9

x:=winexec('rundll32.exe shell32.dll

字串7

Control_RunDLL access.cpl 字串6

字串6

3' 字串5

9); 字串2

{辅助选项 属性-鼠标} 字串8

x:=winexec('rundll32.exe shell32.dll

字串8

Control_RunDLL access.cpl

字串4

字串5

4' 字串3

9);

字串6

{辅助选项 属性-常规}

字串1

x:=winexec('rundll32.exe shell32.dll

字串5

Control_RunDLL access.cpl 字串9

字串3

5' 字串5

9);

字串3

{添加/删除/doc/">程序 属性-安装/卸载} 字串4

x:=winexec('rundll32.exe shell32.dll 字串6

Control_RunDLL Appwiz.cpl 字串6

字串7

1'

字串4

9); 字串5

{添加/删除/doc/">程序 属性-Windows安装/doc/">程序} 字串1

x:=winexec('rundll32.exe shell32.dll

字串6

Control_RunDLL Appwiz.cpl

字串4

字串9

2' 字串5

9); 字串6

{添加/删除/doc/">程序 属性-启动盘} 字串6

x:=winexec('rundll32.exe shell32.dll

字串9

Control_RunDLL Appwiz.cpl

字串5

字串4

3'

字串1

9); 字串6

{显示 属性-背景} 字串2

x:=winexec('rundll32.exe shell32.dll 字串3

Control_RunDLL desk.cpl 字串6

字串2

0' 字串8

9);

字串2

{显示 属性-屏幕保护/doc/">程序}

字串8

x:=winexec('rundll32.exe shell32.dll 字串4

Control_RunDLL desk.cpl

字串4

字串5

1' 字串5

9);

字串9

{显示 属性-外观} 字串7

x:=winexec('rundll32.exe shell32.dll 字串7

Control_RunDLL desk.cpl

字串7

字串7

2'

字串8

9); 字串4

{显示 属性-设置} 字串4

x:=winexec('rundll32.exe shell32.dll 字串1

Control_RunDLL desk.cpl

字串3

字串2

3'

字串3

9);

字串7

{Internet 属性-常规}

字串3

x:=winexec('rundll32.exe shell32.dll 字串3

Control_RunDLL Inetcpl.cpl

字串1

字串9

0'

字串2

9); 字串3

{Internet 属性-安全} 字串6

x:=winexec('rundll32.exe shell32.dll

字串6

Control_RunDLL Inetcpl.cpl 字串1

字串6

1' 字串2

9); 字串3

{Internet 属性-内容}

字串1

x:=winexec('rundll32.exe shell32.dll 字串3

Control_RunDLL Inetcpl.cpl 字串7

字串2

2' 字串8

9); 字串2

{Internet 属性-连接}

字串5

x:=winexec('rundll32.exe shell32.dll 字串4

Control_RunDLL Inetcpl.cpl 字串1

字串5

3'

字串2

9); 字串4

{Internet 属性-/doc/">程序}

字串3

x:=winexec('rundll32.exe shell32.dll 字串1

Control_RunDLL Inetcpl.cpl

字串8

字串5

4'

字串2

9); 字串1

{Internet 属性-高级}

字串5

x:=winexec('rundll32.exe shell32.dll 字串5

Control_RunDLL Inetcpl.cpl

字串5

字串2

5'

字串8

9); 字串6

{区域设置 属性-区域设置}

字串3

x:=winexec('rundll32.exe shell32.dll 字串4

Control_RunDLL Intl.cpl

字串4

字串9

0' 字串2

9);

字串9

{区域设置 属性-数字} 字串9

x:=winexec('rundll32.exe shell32.dll 字串3

Control_RunDLL Intl.cpl

字串1

字串8

1' 字串8

9); 字串9

{区域设置 属性-货币}

字串8

x:=winexec('rundll32.exe shell32.dll

字串3

Control_RunDLL Intl.cpl 字串9

字串4

2'

字串6

9);

字串8

{区域设置 属性-时间}

字串1

x:=winexec('rundll32.exe shell32.dll

字串6

Control_RunDLL Intl.cpl

字串1

字串3

3' 字串4

9); 字串4

{区域设置 属性-日期}

字串6

x:=winexec('rundll32.exe shell32.dll

字串6

Control_RunDLL Intl.cpl

字串3

字串5

4' 字串9

9);

字串5

{游戏控制器-一般} 字串5

x:=winexec('rundll32.exe shell32.dll 字串6

Control_RunDLL Joy.cpl 字串6

字串2

0'

字串4

9); 字串9

{游戏控制器-高级}

字串6

x:=winexec('rundll32.exe shell32.dll

字串2

Control_RunDLL Joy.cpl

字串8

字串9

1'

字串5

9);

字串6

{鼠标 属性} 字串7

x:=winexec('rundll32.exe shell32.dll

字串9

Control_RunDLL Main.cpl'

字串4

9); 字串8

{多媒体 属性-音频} 字串1

x:=winexec('rundll32.exe shell32.dll

字串6

Control_RunDLL Mmsys.cpl 字串2

字串2

0'

字串1

9);

字串2

{多媒体 属性-视频} 字串3

x:=winexec('rundll32.exe shell32.dll 字串4

Control_RunDLL Mmsys.cpl

字串8

字串5

1' 字串5

9);

字串3

{多媒体 属性-MIDI}

字串9

x:=winexec('rundll32.exe shell32.dll 字串4

Control_RunDLL Mmsys.cpl

字串9

字串2

2'

字串2

9); 字串1

{多媒体 属性-CD音乐}

字串5

x:=winexec('rundll32.exe shell32.dll

字串8

Control_RunDLL Mmsys.cpl

字串2

字串5

3' 字串7

9);

字串7

{多媒体 属性-设备} 字串6

x:=winexec('rundll32.exe shell32.dll 字串7

Control_RunDLL Mmsys.cpl 字串4

字串5

4' 字串2

9); 字串1

{调制解调器 属性}

字串2

x:=winexec('rundll32.exe shell32.dll 字串8

Control_RunDLL Modem.cpl' 字串9

9); 字串9

{网络} 字串5

x:=winexec('rundll32.exe shell32.dll 字串5

Control_RunDLL Netcpl.cpl' 字串6

9);

字串8

{密码 属性}

字串2

x:=winexec('rundll32.exe shell32.dll

字串9

Control_RunDLL Password.cpl' 字串2

9);

字串2

{扫描仪与数字相机 属性}

字串1

x:=winexec('rundll32.exe shell32.dll

字串9

Control_RunDLL Sticpl.cpl' 字串1

9);

字串3

{系统 属性-常规} 字串1

x:=winexec('rundll32.exe shell32.dll

字串2

Control_RunDLL Sysdm.cpl 字串4

字串7

0'

字串5

9);

字串6

{系统 属性-设备管理器} 字串2

x:=winexec('rundll32.exe shell32.dll

字串3

Control_RunDLL Sysdm.cpl

字串3

字串6

1'

字串8

9);

字串4

{系统 属性-硬件配置文件}

字串7

x:=winexec('rundll32.exe shell32.dll 字串4

Control_RunDLL Sysdm.cpl

字串4

字串9

2'

字串9

9); 字串8

{系统 属性-性能} 字串1

x:=winexec('rundll32.exe shell32.dll

字串6

Control_RunDLL Sysdm.cpl

字串2

字串9

3'

字串1

9); 字串9

{日期/时间 属性} 字串4

x:=winexec('rundll32.exe shell32.dll

字串1

Control_RunDLL timedate.cpl'

字串1

9); 字串9

{电源管理 属性} 字串6

x:=winexec('rundll32.exe shell32.dll 字串9

Control_RunDLL Powercfg.cpl' 字串9

9);

字串8

{拨号属性} 字串7

x:=winexec('rundll32.exe shell32.dll 字串9

Control_RunDLL Telephon.cpl'

字串4

9); 字串3

{----------------------调用错误----------------------}

字串9

if x=0 then messagebox(0 字串9

'/doc/">程序超出内存' 字串3

'错误' 字串8

0);

字串3

if x=ERROR_BAD_FORMAT then messagebox(0 字串7

'该/doc/">程序非一个合法的Win32.EXE/doc/">程序).' 字串2

'错误'

字串3

0); 字串7

if x=ERROR_FILE_NOT_FOUND then messagebox(0 字串7

'指定文件没找到'

字串2

'错误'

字串6

0); 字串1

if x=ERROR_PATH_NOT_FOUND then messagebox(0 字串2

'指定路径没找到'

字串4

'错误'

字串5

0);

字串4

end;

字串7

字串1

字串4

控制壁纸

字串5

控制Windows 95的壁纸,以下/doc/">程序使壁纸变为我们想要的位图,如果THEPCHAR为空,那么就取消壁纸,变为Win默认色彩; 但这种方法只是暂时的,在WINDOWS重新启动后还是原来的位图,这时就需要对WIN.INI文件进行写操作,才能保存住我们改动的图片不被替换。

字串3

var THEPCHAR:pchar; 字串7

begin 字串4

THEPCHAR:='e:\a.bmp'; 字串4

SystemParametersInfo(SPI_SETDESKWALLPAPER 字串2

0

字串5

THEPCHAR 字串1

SPIF_SENDWININICHANGE)

字串6

end;

字串5

字串1

字串2

辨别分辨率 字串3

要得到显示器的分辨率,由下列/doc/">程序得到:

字串5

var 字串3

x:longint;

字串6

a:string; 字串2

begin 字串6

x := GetSystemMetrics(SM_CXSCREEN); 字串5

Str(x 字串1

a);

字串6

Label1.Caption := '显示器水平分辨率' + a; 字串4

x := GetSystemMetrics(SM_CYSCREEN); 字串1

Str(x

字串2

a);

字串5

Label2.Caption := '显示器垂直分辨率' + a; 字串4

end;

字串3

字串3

字串3

启动屏幕保护 字串7

执行下列语句开始Windows屏幕保护/doc/">程序 字串1

SendMessage(HWND_BROADCAST 字串4

WM_SYSCOMMAND 字串6

SC_SCREENSAVE

字串3

0); 字串1

字串7

字串4

取系统颜色 字串4

要取得系统颜色,把参数换一下就可以

字串7

COLOR_SCROLLBAR      滚动条 字串7

COLOR_BACKGROUND      桌面背景 字串1

COLOR_ACTIVECAPTION     活动窗口标题

字串6

cOLOR_INACTIVECAPTION   非活动窗口标题

字串1

cOLOR_MENU         菜单

字串6

COLOR_WINDOW        窗口背景

字串9

cOLOR_WINDOWFRAME     窗口框

字串9

COLOR_MENUTEXT       窗口文字 字串2

COLOR_WINDOWTEXT      3D 阴影 (Win95)

字串5

COLOR_CAPTIONTEXT     标题文字

字串6

COLOR_ACTIVEBORDER     活动窗口边框

字串1

COLOR_INACTIVEBORDER    非活动窗口边框

字串5

COLOR_APPWORKSPACE     MDI 窗口背景

字串4

COLOR_HIGHLIGHT      选择条背景

字串5

COLOR_HIGHLIGHTTEXT    选择条文字

字串1

COLOR_BTNFACE       按钮

字串5

COLOR_BTNSHADOW      3D 按钮阴影

字串5

COLOR_GRAYTEXT       灰度文字

字串1

COLOR_BTNTEXT       按钮文字

字串9

COLOR_INACTIVECAPTIONTEXT 非活动窗口文字

字串4

COLOR_BTNHIGHLIGHT     3D 选择按钮} 字串8

var i:integer; 字串1

begin 字串1

//取得活动窗口标题颜色

字串6

i :=GetSysColor(COLOR_ACTIVECAPTION);

字串7

end;

字串3

字串9

字串8

动态修改显示器分辨率

字串9

Windows提供给我们两个API函数,可以动态调整显示器的分辨率,他们是EnumDisplaySettings() 和ChangeDisplaySettings(),下面这个例子就是了

字串5

function DynamicResolution(X

字串7

Y: word): BOOL; 字串9

var 字串3

lpDevMode: TDeviceMode;

字串4

begin 字串2

Result := EnumDisplaySettings(nil 字串4

0

字串3

lpDevMode);

字串3

if Result then 字串1

begin

字串5

lpDevMode.dmFields := DM_PELSWIDTH Or DM_PELSHEIGHT;

字串1

lpDevMode.dmPelsWidth := X;

字串7

lpDevMode.dmPelsHeight := Y;

字串5

Result := ChangeDisplaySettings(lpDevMode 字串5

0) = DISP_CHANGE_SUCCESSFUL;

字串7

end 字串4

end; 字串6

procedure TForm1.Button1Click(Sender: TObject); 字串4

begin

字串2

if DynamicResolution(640

字串3

480) then

字串5

ShowMessage('Now is 640*480'); 字串4

end; 字串6

procedure TForm1.Button2Click(Sender: TObject); 字串1

begin 字串6

if DynamicResolution(800

字串8

600) then

字串2

ShowMessage('Now is 800*600');

字串1

end;

字串2

字串7

字串2

隐藏桌面上的图标 字串7

使桌面上的图标消失,连桌面上的右键功能也不能使用如果不让初学者乱用“我的电脑”的话,那么把/doc/">程序放到“启动”里,顺便把“Windows资源管理器”也去掉, 再加上个多用户密码,那么想破坏电脑文件也无从下手了。该/doc/">程序Delphi 4里通过 字串7

var

字串7

hDesktop : THandle;

字串7

begin 字串3

hDesktop := FindWindow('Progman'

字串7

nil); 字串8

ShowWindow(hDesktop

字串1

SW_HIDE);

字串6

end;

字串6

字串5

字串2

怎样获得/doc/">程序启动快捷键中记载的/doc/">程序路径 字串6

ShortCut that Started Application? 字串7

OK 字串4

your problem is not setting current directory but you want to take 字串8

ANY

字串1

shortcut and resolve its properties. Am I correct now ? :)) 字串1

Take a look at unit ShlObj and IShellLink. (API help file) 字串7

var SCut: IShellLink;

字串5

SCut.Resolve 字串6

GetWorkingDirectory - Retrieves the name of the working directory for a 字串4

shell link object 字串9

GetPath - Retrieves the path and filename of a shell link object. 字串2

I have not done this before 字串6

just giving you ideas

字串4

字串2

字串7

让彩色光标出现在Delphi/doc/">程序中 字串9

在Delphi中用Loadcursor()得到的光标只有黑白两色,怎样在/doc/">程序中得到彩色光标呢?笔者尝试制作了以下/doc/">程序: 字串6

方法一 用Loadcursorfromfile()从外部调入图标作为光标 字串1

Loadcursorfromfile()函数可以读*CUR,*ICO,*ANI为后缀的文件作为光标,其中ICO为彩色图标格式(可用Image Editor制作),ANI为动画光标格式。以下为打开一图标作为光标的演示/doc/">程序段,当光标移动到测试区域内光标会变成选定的图案; 字串1

{设:opendialog1:Topendialog;Bitbtn1:Tbitbtn}

字串6

procedure TForm1.BitBtn1Click(Sender:TObject);

字串9

var tt:pchar;size:integer;s:string;

字串6

begin

字串7

if opendialog1.Execute then

字串3

begin 字串2

size:=length(opendialog1.filename);

字串6

getmem(tt

字串6

size); 字串5

s:=opendialog1.filename;

字串5

strpcopy(tt 字串2

s);

字串5

screen.cursors[2]:=loadcursorfromfile(tt); 字串9

bf.cursor:=2; 字串4

freemem(tt

字串5

size);

字串6

end;

字串7

end;

字串1

方法二 从资源文件加载彩色光标 字串9

用方法一发送/doc/">程序时必须包含*CUR文件,因而从资源文件中加载彩色光标是更可行的方法。用图标存放彩色光标,使用时把图标存入临时文件,用Loadcursorfromfile()从临时文件读出彩色光标。 字串4

/doc/">程序段:

字串4

procedure ZloadfromResourse(screenindex:integer;name:Pchar); 字串2

var td:ticon;

字串5

begin

字串5

try

字串1

td:=ticon.Create;

字串1

td.Handle:=LoadIcon(Hinstance

字串9

name); 字串6

td.SaveToFile(′temp.cur′); 字串7

screen.Cursors[screenindex]:=loadcursorfromfile(′temp.cur′); 字串3

deletefile(′temp.cur′);

字串8

finally 字串9

td.free;

字串1

end; 字串5

end;

字串7

此/doc/">程序把名字为name的图标变为序号为screenindex的光标; 字串3

例:

字串2

ZloadfromResourse(2

字串2

′myicon′);

字串9

Form1.cursor:=2;

字串6


文章评论

共有 0位编程爱好者发表了评论 查看完整内容

    评论加载中…
忒好程序员:www.teihao.com

推荐信息

     
忒好程序员
AD