Delphi开发中Windows API函数的应用
来源:互联网 发布:amx105突击型数据 编辑:程序博客网 时间:2024/06/05 01:19
Delphi作为快速开发Windows95/NT下应用程序的工具,已经为越来越多的开发者采用。但是,如果要开发出专业的Windows应用软件,还需要使用大量的Windows API函数,以下是笔者开发管理软件中的几个应用实例。
一、判定Windows版本
众所周知,Windows95/
NT某些地方有些差别,为了使应用程序避免出现因为系统不符合而导致的错误,有必要自动判定系统版本。这可以通过API函数getversion实现。
TForm1.FormCreate(Sender:Tobject);
var ver:integer;//版本号 major:integer;//主版本号 minor:integer;//次版本号
begin
ver:=getversion();//获得版本号
major:=ver and 255;//获得主版本号
minor:=(ver and 255*256)div 256;
//获得次版本号
showmessage(‘系统版本号是:’+inttostr(ver));
//显示版本号
showmessage(‘系统主版本号是:'+inttostr(major));//显示主版本号
showmessage(‘系统次版本号是:'+inttostr(minor));//显示次版本号
end;
二、判定Windows安装目录
一般Delphi开发出来的程序需要知道系统的安装目录,以便将帮助文件、动态链接库等系统部分拷贝到系统目录下,为了使安装程序能够在用户任意设定安装目录的情况下均能正常运行,需要使用API函数GetWindowsDirectory、GetSystemDirectory来实现。
procedure TForm1.FormCreate(Sender:Tobject);
var windir:pchar;
sysdir:pchar;
begin
getmem(windir,256);//获得内存
getmem(sysdir,256);//获得内存
GetWindowsDirectory(Windir,128);//获得安装目录
GetSystemDirectory(sysdir,128);//获得系统目录
showmessage(‘Windows目录是:'+windir);
//显示安装目录
showmessage(‘System目录是:'+sysdir);
//显示系统目录
freemem(windir,256);//释放内存
freemem(sysdir,256);//释放内存
end;
三、在程序中重新启动Windows系统
通常在程序中需要将系统重新启动,这时可以使用ExitWindowsEx函数来实现。
procedure TForm1.Button1Click(Sender:Tobject);
begin
ExitWindowsEx(EWX_FORCE or EWX_LOGOFF,0);
//强行结束当前登录的用户进程
ExitWindowsEx(EWX_FORCE or EWX_POWEROFF,0);
//强行关机
ExitWindowsEx(EWX_FORCE or EWX_REBOOT,0);
//强行重新启动机器
end;
四、调用其他程序
通常,用户希望能够在一个应用程序中直接调用外部程序,这可以通过winexec函数来实现。
procedure TForm1.Button1Click(Sender.Tobject);
begin
winexec(‘c:/pwin97/notepad.exe c:/config.dos',9);
end
<script type="text/javascript"><!--google_ad_client = "pub-6288292867903749";google_ad_width = 728;google_ad_height = 90;google_ad_format = "728x90_as";google_ad_type = "text";google_ad_channel ="";//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- Delphi开发中Windows API函数的应用
- Delphi开发中Windows API函数的应用
- 在Delphi中巧用WINDOWS 的API函数
- delphi 的api函数
- DELPHI中GetTickCount 函数的应用
- QT中对Windows API的应用
- Visual Basic调用Windows API函数的应用举例
- Delphi中使用API函数详解
- DELPHI中使用API函数详解
- Delphi中调用API函数经验点滴
- DELPHI中函数、过程变量的声明与应用
- Delphi XE中动态表达式的应用 (调用自定义函数)
- Windows API中mouse_event函数
- VB中windows API StretchBlt,BitBlt的应用
- delphi调用windows api
- [Delphi]几个很有用的API函数
- Delphi下的winsock-api 函数(一)
- Delphi下的winsock-api 函数(二)
- 什么是BPM
- BPM业务流程管理的关键功能
- Writing a Winsock 2 Layered Service Provider(LSP) 译文(zz)
- 信息部门人员角色划分及任职资格
- IRC聊天工具常用命令(小卡片)
- Delphi开发中Windows API函数的应用
- 选择BPM系统 必须考虑建立BPM团队
- bat 的用法
- API函数大集合
- VC操作注册表
- 检测客户端显示器分辨率、浏览器类型和客户端IP
- SQL*PLUS命令的使用大全
- Ajax创建XMLHttpRequest完整版
- 功能强大的编辑器——Vi