操作系统编程

更改Windows的墙纸。
  在Delphi中你可以很方便地更改墙纸,请参考以下的程序。
  procedureChangeIt;
  var
  Reg:TregIniFile;
  begin
  Reg:ΚTRegIniFile.Create(′ControlPanel′);
  Reg.WriteString(′desktop′,′Wallpaper′,′c:ιpwin95ιforest.bmp′);
  Reg.WriteString(′desktop′,′TileWallpaper′,′1′);
  Reg.Free;
  SystemParametersInfo(SPI—SETDESKWALLPAPER,0,nil,SPIF—SENDWININICHANGE);
  end;

 
屏蔽系统按键
也许您希望您的程序在运行时不想让用户按系统按键 Alt-Tab 或  Ctrl-Alt-Del,那么可以通过以下的程序段屏蔽这些按键。  
procedure TForm1.FormCreate(Sender: TObject);  
begin  
var  
tmp : integer;
  begin
  tmp := 0;
  //屏蔽 Alt-Tab
  SystemParametersInfo( SPI_SETFASTTASKSWITCH, 1, @tmp, 0);
  //屏蔽 Ctrl-Alt-Del
  SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @tmp, 0);   end;  end;

 
更换墙纸  
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar('WallPaper.BMP', 0);

 
设置系统日期和时间:
  例如:
    var
       MyST:TSystemTime;
    begin
         with MyST do
         begin
              wYear:=1998;
              wMonth:=12;
              wDay:=7;
              wHour:=8;
              wMinute:=9;
              wSecond:=10;
         end;
         SetSystemTime(MyST);
    end;
s

 
如果隐藏和显示Windows的任务条?(Delphi 3 and 2.0)
如果隐藏和显示Windows的任务条?仅仅调用以下的函数就可以.
procedure hideTaskbar; //隐藏
var
wndHandle : THandle;
wndClass : array[0..50] of Char;
begin
StrPCopy(@wndClass[0], 'Shell_TrayWnd');
wndHandle := FindWindow(@wndClass[0], nil);
ShowWindow(wndHandle, SW_HIDE);
 
End;
 
procedure showTaskbar;
var
wndHandle : THandle;
wndClass : array[0..50] of Char;
begin
StrPCopy(@wndClass[0], 'Shell_TrayWnd');
wndHandle := FindWindow(@wndClass[0], nil);
ShowWindow(wndHandle, SW_RESTORE);
end;

 
控制面板大全
  在程序运行过程中启动控制面板的各个设置功能:
var x:cardinal;
begin
{启动控制面板}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL',9);
{辅助选项 属性-键盘}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL access.cpl,,1',9);
{辅助选项 属性-声音}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL access.cpl,,2',9);
{辅助选项 属性-显示}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL access.cpl,,3',9);
{辅助选项 属性-鼠标}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL access.cpl,,4',9);
{辅助选项 属性-常规}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL access.cpl,,5',9);
{添加/删除程序 属性-安装/卸载}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,1',9);
{添加/删除程序 属性-Windows安装程序}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,2',9);
{添加/删除程序 属性-启动盘}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,3',9);
{显示 属性-背景}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0',9);
{显示 属性-屏幕保护程序}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,1',9);
{显示 属性-外观}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,2',9);
{显示 属性-设置}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3',9);
{Internet 属性-常规}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,0',9);
{Internet 属性-安全}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,1',9);
{Internet 属性-内容}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,2',9);
{Internet 属性-连接}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,3',9);
{Internet 属性-程序}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,4',9);
{Internet 属性-高级}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,5',9);
{区域设置 属性-区域设置}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,0',9);
{区域设置 属性-数字}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,1',9);
{区域设置 属性-货币}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,2',9);
{区域设置 属性-时间}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,3',9);
{区域设置 属性-日期}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,4',9);
{游戏控制器-一般}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Joy.cpl,,0',9);
{游戏控制器-高级}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Joy.cpl,,1',9);
{鼠标 属性}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Main.cpl',9);
{多媒体 属性-音频}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,0',9);
{多媒体 属性-视频}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,1',9);
{多媒体 属性-MIDI}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,2',9);
{多媒体 属性-CD音乐}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,3',9);
{多媒体 属性-设备}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,4',9);
{调制解调器 属性}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Modem.cpl',9);
{网络}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Netcpl.cpl',9);
{密码 属性}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Password.cpl',9);
{扫描仪与数字相机 属性}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Sticpl.cpl',9);
{系统 属性-常规}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl,,0',9);
{系统 属性-设备管理器}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl,,1',9);
{系统 属性-硬件配置文件}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl,,2',9);
{系统 属性-性能}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl,,3',9);
{日期/时间 属性}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL timedate.cpl',9);
{电源管理 属性}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Powercfg.cpl',9);
{拨号属性}
x:=winexec('rundll32.exe shell32.dll,Control_RunDLL Telephon.cpl',9);
{----------------------调用错误----------------------}
if x=0 then messagebox(0,'程序超出内存','错误',0);
if x=ERROR_BAD_FORMAT then messagebox(0,'该程序非一个合法的Win32.EXE程序).','错误',0);
if x=ERROR_FILE_NOT_FOUND then messagebox(0,'指定文件没找到','错误',0);
if x=ERROR_PATH_NOT_FOUND then messagebox(0,'指定路径没找到','错误',0);
end;

 
控制壁纸
控制Windows 95的壁纸,以下程序使壁纸变为我们想要的位图,如果THEPCHAR为空,那么就取消壁纸,变为Win默认色彩; 但这种方法只是暂时的,在WINDOWS重新启动后还是原来的位图,这时就需要对WIN.INI文件进行写操作,才能保存住我们改动的图片不被替换。
var THEPCHAR:pchar;
begin
THEPCHAR:='e:\a.bmp';
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, THEPCHAR, SPIF_SENDWININICHANGE)
end;

 
辨别分辨率
要得到显示器的分辨率,由下列程序得到:
var
x:longint;
a:string;
begin
x := GetSystemMetrics(SM_CXSCREEN);
Str(x,a);
Label1.Caption := '显示器水平分辨率' + a;
x := GetSystemMetrics(SM_CYSCREEN);
Str(x,a);
Label2.Caption := '显示器垂直分辨率' + a;
end;

 
启动屏幕保护
执行下列语句开始Windows屏幕保护程序
SendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_SCREENSAVE,0);

 
取系统颜色
要取得系统颜色,把参数换一下就可以
COLOR_SCROLLBAR      滚动条
COLOR_BACKGROUND      桌面背景
COLOR_ACTIVECAPTION     活动窗口标题
cOLOR_INACTIVECAPTION   非活动窗口标题
cOLOR_MENU         菜单
COLOR_WINDOW        窗口背景
cOLOR_WINDOWFRAME     窗口框
COLOR_MENUTEXT       窗口文字
COLOR_WINDOWTEXT      3D 阴影 (Win95)
COLOR_CAPTIONTEXT     标题文字
COLOR_ACTIVEBORDER     活动窗口边框
COLOR_INACTIVEBORDER    非活动窗口边框
COLOR_APPWORKSPACE     MDI 窗口背景
COLOR_HIGHLIGHT      选择条背景
COLOR_HIGHLIGHTTEXT    选择条文字
COLOR_BTNFACE       按钮
COLOR_BTNSHADOW      3D 按钮阴影
COLOR_GRAYTEXT       灰度文字
COLOR_BTNTEXT       按钮文字
COLOR_INACTIVECAPTIONTEXT 非活动窗口文字
COLOR_BTNHIGHLIGHT     3D 选择按钮}
var i:integer;
begin
//取得活动窗口标题颜色
i :=GetSysColor(COLOR_ACTIVECAPTION);
end;

 
动态修改显示器分辨率
Windows提供给我们两个API函数,可以动态调整显示器的分辨率,他们是EnumDisplaySettings() 和ChangeDisplaySettings(),下面这个例子就是了
function DynamicResolution(X, Y: word): BOOL;
var
lpDevMode: TDeviceMode;
begin
Result := EnumDisplaySettings(nil, 0, lpDevMode);
if Result then
begin
lpDevMode.dmFields := DM_PELSWIDTH Or DM_PELSHEIGHT;
lpDevMode.dmPelsWidth := X;
lpDevMode.dmPelsHeight := Y;
Result := ChangeDisplaySettings(lpDevMode, 0) = DISP_CHANGE_SUCCESSFUL;
end
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if DynamicResolution(640, 480) then
ShowMessage('Now is 640*480');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if DynamicResolution(800, 600) then
ShowMessage('Now is 800*600');
end;

 
隐藏桌面上的图标
  使桌面上的图标消失,连桌面上的右键功能也不能使用如果不让初学者乱用“我的电脑”的话,那么把程序放到“启动”里,顺便把“Windows资源管理器”也去掉, 再加上个多用户密码,那么想破坏电脑文件也无从下手了。该程序Delphi 4里通过
var
hDesktop : THandle;
begin
hDesktop := FindWindow('Progman', nil);
ShowWindow(hDesktop, SW_HIDE);
end;

 
怎样获得程序启动快捷键中记载的程序路径  
ShortCut that Started Application?
OK, your problem is not setting current directory but you want to take
"ANY" shortcut and resolve its properties. Am I correct now ? :))
Take a look at unit ShlObj and IShellLink. (API help file)
var SCut: IShellLink;
SCut.Resolve
GetWorkingDirectory - Retrieves the name of the working directory for a
shell link object
GetPath - Retrieves the path and filename of a shell link object.
I have not done this before, just giving you ideas

 
让彩色光标出现在Delphi程序中
   在Delphi中用Loadcursor()得到的光标只有黑白两色,怎样在程序中得到彩色光标呢?笔者尝试制作了以下程序:
  方法一 用Loadcursorfromfile()从外部调入图标作为光标
  Loadcursorfromfile()函数可以读*CUR,*ICO,*ANI为后缀的文件作为光标,其中ICO为彩色图标格式(可用Image Editor制作),ANI为动画光标格式。以下为打开一图标作为光标的演示程序段,当光标移动到测试区域内光标会变成选定的图案;
  {设:opendialog1:Topendialog;Bitbtn1:Tbitbtn}
  procedure TForm1.BitBtn1Click(Sender:TObject);
  var tt:pchar;size:integer;s:string;
  begin
  if opendialog1.Execute then
  begin
  size:=length(opendialog1.filename);
  getmem(tt,size);
  s:=opendialog1.filename;
  strpcopy(tt,s);
  screen.cursors[2]:=loadcursorfromfile(tt);
  bf.cursor:=2;
  freemem(tt,size);
  end;
  end;
  方法二 从资源文件加载彩色光标
  用方法一发送程序时必须包含*CUR文件,因而从资源文件中加载彩色光标是更可行的方法。用图标存放彩色光标,使用时把图标存入临时文件,用Loadcursorfromfile()从临时文件读出彩色光标。
  程序段:
  procedure ZloadfromResourse(screenindex:integer;name:Pchar);
  var td:ticon;
  begin
  try
  td:=ticon.Create;
  td.Handle:=LoadIcon(Hinstance,name);
  td.SaveToFile(′temp.cur′);
  screen.Cursors[screenindex]:=loadcursorfromfile(′temp.cur′);
  deletefile(′temp.cur′);
  finally
  td.free;
  end;
  end;
  此程序把名字为name的图标变为序号为screenindex的光标;
  例:
  ZloadfromResourse(2,′myicon′);
  Form1.cursor:=2;
 

转载于:https://www.cnblogs.com/myamanda/articles/1597570.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值