PB 各种小技巧(六)

11.显示一个与Windows操作系统风格一致的About对话框。 首先声明如下外部函数: function int ShellAboutA(ulong al_hWnd, string as_szApp, string as_szOtherStuff, ulong hIcon) library "shell32" ShellAboutA(handle(parent),"关于... ","欢迎",0)

12.send用法:Send(handle,message#,lowword,long)
数据窗口中按enter键实现tab功能(在数据窗口的Enter事件中)
自定义事件ID:pbm_dwnprocessenter里写如下代码:
Send(Handle(This),256,9,Long(0,0))

说明:This代表DW;Handle代表DW的句柄;256代表TAB键;9代表不加入shift键,7代表加入;Long(0,0)代表预留空位.

send(handle(this),256,9,long(0,0))
return 1
//This statement scrolls the window w_emp up one page:
Send(Handle(w_emp), 277, 2, 0)
//Both of the following statements click the CommandButton cb_OK:
Send(Handle(Parent), 273, 0, Handle(cb_OK))
cb_OK.TriggerEvent(Clicked!)
//minimizes the DataWindow:
Send(Handle(dw_1), 274, 61472, 0)
//maximizes the DataWindow:
Send(Handle(dw_1), 274, 61488, 0)
//returns the DataWindow to its normal, defined size:
Send(Handle(dw_1), 274, 61728, 0)

13.如何使PB窗口总在最上层(Always On Top)
通过SetWindowPos函数把窗口的显示层次修改为HWND—TOPMOST,就可使指定窗口永远不会被其它窗口覆
盖,该函数声明为:
Function Long SetWindowPos(Long hwnd,Long ord,Long x,Long y,Long dx,Long dy,Long uflag) Library ″user32″
参数1为要顶层显示的窗口句柄,参数2指定显示的层次,参数7为附加选项,其余参数指定窗口位置和
大小,均可忽略。在窗口的Open或Activate事件中加入如下函数调用:
SetWindowPos(Handle(This),-1,0,0,0,0,3)
参数2取-1表示在最顶层显示窗口,取1表示在最底层显示;最后一个参数若取1,表示窗口大小保持不
变,取2表示保持位置不变,因此,取3(=1+2)表示大小和位置均保持不变,取0表示将窗口的大小和
位置改变为指定值。

14.在PB中如何获得光盘盘符
通过GetDriveType函数可以获取驱动器(如:软驱、硬盘、光驱、网络映射驱动器等)的信息,该函数
声明为:
Function Uint GetDriveTypeA(String drive) Library ″kernel32.dll″
参数为一个盘符(如"C:"),返回值:1表示未知,2表示软驱,3表示本地硬盘,4表示网络驱动器,
5表示光驱。因此如下代码可以获得光盘的盘符:
For i=Asc(′D′) to Asc(′Z′)
//列举所有可能的CDROM驱动器
  If GetDriveTypeA(Char(i)+″:″)=5 Then
//若找到CDROM
MessageBox(″CDROM″,Char(i)+″:″)
//显示光盘盘符
Exit //退出列举
  End If
Next

15.在PB中如何获取目录信息
⑴获取当前目录。通过GetCurrentDirectory函数可以获取当前目录,该函数声明为:
Function Ulong GetCurrentDirectoryA(Ulong buflen, ref String dir) Library ″kernel32.dll″
参数2为接收当前目录的字符缓冲区,前面必须加ref表示地址引用;参数1用来指定字符缓冲区的长度。
调用过程为:
String curdir
curdir=Space(256)
//为字符缓冲区开辟内存空间
GetCurrentDirectoryA(256,curdir)
MessageBox(″Current Directory″,curdir)
⑵获取Windows及系统目录。要用到GetWindowsDirectory和GetSystemDirectory两个函数,须作如下声明:
Function Uint GetWindowsDirectoryA(ref String dir,Uint buflen) Library ″kernel32.dll″
Function Uint GetSystemDirectoryA(ref String dir,Uint buflen) Library ″kernel32.dll″

16.在PB中如何注销当前用户、关闭计算机、重启计算机
通过ExitWindowsEx函数可实现这三个功能,首先作如下声明:
Function Long ExitWindowsEx(Long uflag,Long nouse) Library ″user32.dll″
参数2保留不用,可取0;参数1取0可以注销当前用户,取1可以关闭计算机,取2可以重启计算机,其值
再加4表示强制结束"未响应"的进程。

17.控制由Run运行的程序(简称Run程序)
在PB程序设计中,可以用Run()来运行一些程序。比如用户按了F1,就运行一个chm文件。但Run程序无法
与PB主程序协调工作,若用户按了多次F1,就会启动Run程序的多个实例,主程序退出时,Run程序依然
运行。可以用如下函数来使它们协调工作:
Function Ulong FindWindowA(Ulong classname, String windowname) Library ″user32.dll″
Function Long SetParent(Long childwin,Long parentwin) Library ″user32.dll″
⑴使Run程序只运行一个实例
handle=FindWindowA(nul,wtitle)
//查找Run程序是否已经运行,wtitle为Run程序的标题
IF handle〉0 Then Return
//若已经在运行就返回
Run(″C:Program FilesJointJoint.chm″)
//否则运行Run程序
⑵PB主程序退出时,Run程序也关闭
handle=FindWindowA(nul,wtitle)
SetParent(handle,Handle(w—main))
//使Run程序窗口成为PB主程序的子窗口

18.映射网络驱动器
若要在程序中把远程主机的资源映射到本地驱动器,可以用如下函数:
Function long WNetAddConnectionA(String path,string pwd,String drv) Library ″mpr.dll″
19.在PB中如何打开一个文件(如.txt,.doc),就像在资源管理器中双击打开文件一样?
答:可以通过API函数来实现。
在应用程序的Global External Functions中定义:
Function long ShellExecuteA(ulong hwnd, string lpOperation, string lpFile, & string
lpParameters, string lpDirectory, long nShowCmd) library "shell32.dll”
调用如下:
String ls_null
SetNull(ls_null)
ShellExecuteA(Handle(Parent), ls_null, "c:dochello.txt”, ls_null, ls_null, 1)
20.PB中实现淡入淡出效果
声明API:
function Boolean AnimateWindow( ulong hwnd, long dwTime, long dwFlags) library 'user32.dll'
窗口 open事件:
---------------------------------------------------------------
long ll_handle
ll_handle = Handle ( this )
AnimateWindow ( ll_handle , 1000, 524288+16)//淡进
//-------------------------------- ------------------------
窗口close事件
AnimateWindow ( Handle ( This ) , 300, 524288+ 65536 + 16)//淡隐

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值