例子,使用API很简单,但要掌握方法和技巧,要学会举一反三 临时路径 有时需要Windows的临时路径来做备份等工作,那么就要知道路径在哪,下面的程序 var aa:pchar; begin GetTempPath(20,aa); //返回路径名 edit1.text:=aa; end;
还是看看<<windows程序设计>>
多看看Delphi自带的帮助,一切问题都会变得更易。 yxg20803(爱好和平的大灰狼) 就是一个简单的例程。 var aa:pchar; begin GetTempPath(20,aa); //返回路径名 edit1.text:=aa; end;
procedure TForm1.Button1Click(Sender: TObject); var T : TRect; begin PostMessage(Edit1.Handle, WM_KEYDOWN, 72, 0);//模拟edit按下了a键 T := Edit2.BoundsRect; MapWindowPoints(Handle,0,T,2); ClipCursor(@T); end; ---------------嘻嘻,为xgto灌灌水----------俺不要你的分,嘻嘻------- -------------这段时间不见你了啊,俺的API也不太好,还要学一学,学好了,嘻嘻俺教你---------------------
临时路径
有时需要Windows的临时路径来做备份等工作,那么就要知道路径在哪,下面的程序
var aa:pchar;
begin
GetTempPath(20,aa); //返回路径名
edit1.text:=aa;
end;
yxg20803(爱好和平的大灰狼) 就是一个简单的例程。
var aa:pchar;
begin
GetTempPath(20,aa); //返回路径名
edit1.text:=aa;
end;
var
T : TRect;
begin
PostMessage(Edit1.Handle, WM_KEYDOWN, 72, 0);//模拟edit按下了a键
T := Edit2.BoundsRect;
MapWindowPoints(Handle,0,T,2);
ClipCursor(@T);
end;
---------------嘻嘻,为xgto灌灌水----------俺不要你的分,嘻嘻-------
-------------这段时间不见你了啊,俺的API也不太好,还要学一学,学好了,嘻嘻俺教你---------------------
当然最好你有一些API函数的用法表和实例表
help就很不错的!
delphi中可以直接调用api,
如果你想学api,不要看delphi的书,要看windows编程的书。
其中"ABCD"代表以下命令之一:
"rundll32 shell32,Control_RunDLL" - 运行控制面板
"rundll32 shell32,OpenAs_RunDLL" - 打开"打开方式"窗口
"rundll32 shell32,ShellAboutA Info-Box" - 打开"关于"窗口
"rundll32 shell32,Control_RunDLL desk.cpl" - 打开"显示属性"窗口
"rundll32 user,cascadechildwindows" - 层叠全部窗口
"rundll32 user,tilechildwindows" - 最小化所有的子窗口
"rundll32 user,repaintscreen" - 刷新桌面
"rundll32 shell,shellexecute Explorer" - 重新运行Windows Explorer
"rundll32 keyboard,disable" - 锁写键盘
"rundll32 mouse,disable" - 让鼠标失效
"rundll32 user,swapmousebutton" - 交换鼠标按钮
"rundll32 user,setcursorpos" - 设置鼠标位置为(0,0)
"rundll32 user,wnetconnectdialog" - 打开"映射网络驱动器"窗口
"rundll32 user,wnetdisconnectdialog" - 打开"断开网络驱动器"窗口
"rundll32 user,disableoemlayer" - 显示BSOD窗口, (BSOD) = Blue Screen Of Death, 即蓝屏
"rundll32 diskcopy,DiskCopyRunDll" - 打开磁盘复制窗口
"rundll32 rnaui.dll,RnaWizard" - 运行"Internet连接向导", 如果加上参数"/1"则为silent模式
"rundll32 shell32,SHFormatDrive" - 打开"格式化磁盘(A)"窗口
"rundll32 shell32,SHExitWindowsEx -1" - 冷启动Windows Explorer
"rundll32 shell32,SHExitWindowsEx 1" - 关机
"rundll32 shell32,SHExitWindowsEx 0" - 退当前用户
"rundll32 shell32,SHExitWindowsEx 2" Windows9x 快速重启
"rundll32 krnl386.exe,exitkernel" - 强行退出Windows 9x(无确认)
"rundll rnaui.dll,RnaDial "MyConnect" - 运行"网络连接"对话框
"rundll32 msprint2.dll,RUNDLL_PrintTestPage" - 选择打印机和打印测试页
"rundll32 user,setcaretblinktime" - 设置光标闪烁速度
"rundll32 user, setdoubleclicktime" - 测试鼠标双击速度
"rundll32 sysdm.cpl,InstallDevice_Rundll" - 搜索非PnP设备
procedure TForm1.Button1Click(Sender: TObject);
var
Res: Cardinal; // WinExe的返回结果
begin
// 显示控制面板
Res:=WinExec('rundll32.exe shell32.dll,Control_RunDLL',9);
if Res=0 then
MessageBox(Handle,'程序超出内存。','错误',MB_OK+MB_ICONERROR)
else if Res=ERROR_BAD_FORMAT then
MessageBox(Handle,'命令错误。','错误',MB_OK+MB_ICONERROR)
else if Res=ERROR_FILE_NOT_FOUND then
MessageBox(Handle,'指定文件没找到。','错误',MB_OK+MB_ICONERROR)
else if Res=ERROR_PATH_NOT_FOUND then
MessageBox(Handle,'指定路径没找到。','错误',MB_OK+MB_ICONERROR);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
// 辅助选项 | 键盘
WinExec('rundll32.exe shell32.dll,Control_RunDLL access.cpl,,1',9);
end;procedure TForm1.Button3Click(Sender: TObject);
begin
// 添加/删除程序 属性 | 安装/卸载
WinExec('rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl,,1',9);
end;procedure TForm1.Button4Click(Sender: TObject);
begin
// 显示 属性 | 背景
WinExec('rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0',9);
end;procedure TForm1.Button5Click(Sender: TObject);
begin
// Internet 属性 | 常规
WinExec('rundll32.exe shell32.dll,Control_RunDLL Inetcpl.cpl,,0',9);
end;procedure TForm1.Button6Click(Sender: TObject);
begin
// 区域设置 属性 | 区域设置
WinExec('rundll32.exe shell32.dll,Control_RunDLL Intl.cpl,,0',9);
end;procedure TForm1.Button7Click(Sender: TObject);
begin
// 游戏控制器 | 一般
WinExec('rundll32.exe shell32.dll,Control_RunDLL Joy.cpl,,0',9);
end;procedure TForm1.Button8Click(Sender: TObject);
begin
// 鼠标 属性 | 按钮
WinExec('rundll32.exe shell32.dll,Control_RunDLL Main.cpl',9);
end;procedure TForm1.Button9Click(Sender: TObject);
begin
// 多媒体 属性 | 音频
WinExec('rundll32.exe shell32.dll,Control_RunDLL Mmsys.cpl,,0',9);
end;procedure TForm1.Button10Click(Sender: TObject);
begin
// 调制解调器 属性
WinExec('rundll32.exe shell32.dll,Control_RunDLL Modem.cpl',9);
end;procedure TForm1.Button11Click(Sender: TObject);
begin
// 网络 | 配置
WinExec('rundll32.exe shell32.dll,Control_RunDLL Netcpl.cpl',9);
end;procedure TForm1.Button12Click(Sender: TObject);
begin
// 密码 属性 | 更改密码
WinExec('rundll32.exe shell32.dll,Control_RunDLL Password.cpl',9);
end;procedure TForm1.Button13Click(Sender: TObject);
begin
// 扫描仪与数字相机 属性 | 设备
WinExec('rundll32.exe shell32.dll,Control_RunDLL Sticpl.cpl',9);
end;procedure TForm1.Button14Click(Sender: TObject);
begin
// 系统 属性 | 常规
WinExec('rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl,,0',9);
end;procedure TForm1.Button15Click(Sender: TObject);
begin
// 日期/时间 属性 | 日期和时间
WinExec('rundll32.exe shell32.dll,Control_RunDLL timedate.cpl',9);
end;procedure TForm1.Button16Click(Sender: TObject);
begin
// 电源管理 属性 | 电源方案
WinExec('rundll32.exe shell32.dll,Control_RunDLL Powercfg.cpl',9);
end;procedure TForm1.Button17Click(Sender: TObject);
begin
// 拨号 属性 | 我的位置
WinExec('rundll32.exe shell32.dll,Control_RunDLL Telephon.cpl',9);
end;end.
procedure TForm1.FormCreate(Sender: TObject);
var
tmp:integer;
flag:integer;
begin
tmp:= 0;
Flag:= 1;
//屏蔽 Alt-Tab
SystemParametersInfo( SPI_SETFASTTASKSWITCH, Flag, @tmp, 0);
//屏蔽 Ctrl-Alt-Del
SystemParametersInfo( SPI_SCREENSAVERRUNNING,Flag, @tmp, 0);
end;
//当你要恢复功能键时用以下代码:
//Flag := 0;
//SystemParametersInfo(SPI_SCREENSAVERRU-NNING,Flag,@temp,0);
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
hidetaskbar;
end;
procedure Tform1.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;
看来API的数量真是庞大,要掌握可要花不少时间
在实际工作中慢慢积累、安装一个MSDN很有用处
另外,参考VCL的源代码也是一个学习API很好的手段
即使我现在是用VC++编程,也可以从VCL中学习到API的使用方法(*//
//From <<Kingron猛料>>
授人以鱼,不如授人以渔,教你一个方法:
当你有一个API不知道在那个单元的时候,可以使用查找法:把这个API的函数名复制下来,然后用查找文件的方法,查找包含这个API名字的*.pas文件,如果Delphi声明了的话,肯定在某个pas文件中,否则的话,就是没有声明了,必须自己声明这个API。
//*)
所说的方法,扩充到在网上搜索更管用,还搜出很多例子
如果要学会很大一部分,那么去看Windows驱动程序开发的书;(保证是极好的爬虫杀手)
如果要学会一部分,那么去写Windows的控件、组件。(“消息”会让你晕头转向);
如果要一点就可以了,那么看一下《Windows程序设计》就够用了。
TO TommyTong(童童) 我的信用分太低了啊,这个贴子对每个人都有好处的嘛,加进精化贴里不可以吗?
老这么用功会坏眼的!
所以: ExitWindowsEx(1,0);//关机睡觉!
comp : array[0..250] of char
begin
GetComputerName( comp,251);
end;
得到当前计算机名
SetWindowRgn(Handle,CreateEllipticRgn(0,0,Width,Height));
创建一个椭圆形窗体.
Var
Yx:TNotifyIconData;
dd:Ticon;
begin
dd:=Ticon.Create;
dd.LoadFromFile('F:\Windows98Se\drivers\display\intel\i810\i81xcfg.ico');
Yx.cbSize:=sizeof(yx);
//yx.Wnd:=handle;
//yx.uID:=2;
yx.uFlags:=NIF_ICON;
yx.hIcon:=dd.Handle;
Shell_NotifyIcon(NIM_ADD,@Yx); 在系统托盘中加入图标!
//Shell_NotifyIcon(NIM_delete,@Yx);
end;procedure TForm1.Button2Click(Sender: TObject);
Var
dd:Ticon;
begin
dd:=Ticon.Create;
dd.LoadFromFile('F:\Windows98Se\drivers\display\intel\i810\i81xcfg.ico');
ShellAbout(handle,'ss','ddd',dd.handle); 可能是版本信息!!
end;window_shell的API
下个API的详细的中文说明。
不过那声明是VB的。
请问coreapi哪儿可以下的.
我在Torry's找不到。
需要的话,请留下Email