二.巧用(windows的)api函数
这里用几个具体的应用来说明:
应用1:
delphi中有控件memo,当使用应控件输入内容或编辑时,如何确定光标当前的位置呢?这时就可以调用windows api函数中的em_linefromchar和em_lineindex消息来确定memo控件中光标的当前行和列,具体调用方法的过程如下:
procedure tform1.button1click(sender: tobject);
var
linenum:longint;
charsbeforeline:longint;
begin
linenum := sendmessage(memo1.handle,em_linefromchar,
memo1.selstart,0);
charsbeforeline:=sendmessage(memo1.handle,em_lineindex,
linenum,0);
label1.caption:='line: '+inttostr(linenum + 1);
label2.caption:='position: '+inttostr((memo1.selstart -
charsbeforeline)+1);
end;
应用2:
delphi中的控件tlistbox没有提供水平滚动条,如果想添加一个水平流动条,我们只需使用api函数给tlistbox 发送一个lb_sethorizontalextent消息就行了。
源代码如下:
sendmessage(listbox1.handle,lb_sethorizontalextent,2000,
longint(0));
应用3:
当我们需要获取所运行程序的计算机的分辨率时,有二种方法:①可以通过访问delphi提供的screen全局变量,即screen.width和screen.height以像素点给出屏幕的分辨率。②利用windows的api函数getdevicecaps()来得到所用显示器的分辨率,
源代码如下:
application.initialize;
application.createform(tform1, form1);
case getdevicecaps(getdc(form1.handle), horzres) of
640 : //对640*480分辨率进行处理的代码;
800 : //对800*600分辨率进行处理的代码;
1024: //对1024*768分辨率进行处理的代码;
1280: //对1280*1024分辨率进行处理的代码;
end;
application.run;
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器