PB中消息对话框的居中显示方法是什么
创始人
2024-12-19 10:50:00
0次

SharedObject系列函数
和共享对象有关的函数包括:SharedObjectRegister、SharedObjectGet、SharedObjectUnregister和SharedObjectDirectory函数。
首先,用SharedObjectRegister函数初始化共享对象,并建立一个单独的线程。如:
SharedObjectRegister (“ccuo_thread” ,“thread1” )
其中ccuo_thread是一个共享的自定义类用户对象的类名,thread1是共享对象实例的共享名。如果SharedObjectRegister函数返回Success,则新线程创建成功。
然后,执行指定代码。有两种方法让新线程执行指定的代码:一种是在自定义类用户对象的constructor事件中编写脚本,新线程创建后就会自动执行该事件脚本;另一种方法是使用SharedObjectGet函数。该函数实现共享对象实例的引用,如:
SharedObjectGet ( “thread1” ,inv_thread )
其中inv_thread是用来存储共享对象实例的一个对象变量,要求与ccuo_thread具有同一个类名。
最后,通过使用Post语句,即以inv_thread.Post of_function(agrs)的形式,异步调用共享对象的函数of_function。
在完成任务后,可以用SharedObjectUnregister函数中止线程,也可用SharedObjectDirectory函数列出所有有效的共享对象。
函数调用部分
本文所用Win32 API函数原型为:
Function Ulong FindWindowA ( String lpClassName ,String lpWindowName ) Library “user32.dll”
Function Ulong GetTickCount ( ) Library “kernel32.dll”
Function Ulong GetDesktopWindow ( ) Library “user32.dll”
Function Boolean GetWindowRect ( Ulong hWnd ,ref stc_rect lpRect ) Library “user32.dll”
Function Boolean MoveWindow ( Ulong hWnd ,int X ,int Y ,int nWidth ,int nHeight ,Boolean bRepaint ) Library “user32.dll”
下面具体讨论如何实现消息对话框的居中显示:
//声明对象变量
ccuo_thread lccuo_thread
//创建新线程
SharedObjectRegister (‘ccuo_thread’ ,‘thread_center’ )
//引用实例
SharedObjectGet (‘thread_center’ ,lccuo_thread )
//调用窗口居中函数
lccuo_thread.Post of_center (‘#32770’ ,‘Demostration’ ,2000 )
//创建消息对话框
MessageBox ( ‘Demostration’ ,‘Copyright(c) 2001 by Y.L.Sun’ )
//中止线程
SharedObjectunRegister ( ‘thread_center’ )
函数实现部分
实现窗口居中显示的函数是自定义类用户对象ccuo_thread的对象函数of_center,其实现代码如下:
ccuo_thread.of_center ( String lpclassname ,String
lpwindowname , Ulong dwtimeout ) return Boolean
//lpclassname: 消息对话框的类名(#32770)
//lpwindowname: 消息对话框的标题
//dwtimeout: 超时计数
Ulong lul_hwnd //存放消息对话框的句柄
Ulong lul_start //计时开始时刻的值
lul_start = GetTickCount ( ) //计时开始
do
//查找顶层窗口
lul_hwnd=FindWindowA ( lpclassname ,lpwindowname )
//找到顶层窗口后,跳出循环
if lul_hwnd <> 0 then exit
//判断是否已超时
loop while GetTickCount( )-lul_start< dwtimeout
//没有找到消息对话框
if lul_hwnd = 0 then
return false
else
//对话框居中
return of_center ( 0 ,lul_hwnd )
end if
of_center的重载函数代码如下:
ccuo_thread.of_center ( Ulong hwndp ,Ulong hwndc ) return Boolean
//hwndp:父窗口的句柄,值为0时认为是桌面
//hwndc:子窗口的句柄
int li_x //窗口的X坐标
int li_y //窗口的Y坐标
stc_rect lstc_parent //父窗口的4边坐标
stc_rect lstc_child //子窗口的4边坐标
//值为0时认为是桌面
if hwndp = 0 then hwndparent =
GetDesktopWindow ( )
//获得窗口的4边坐标
if not GetWindowRect ( hwndcurrent ,lstc_child ) then return false
if not GetWindowRect ( hwndparent ,lstc_parent ) then return false
li_x = (( lstc_parent.right - lstc_parent.left ) -
( lstc_child.right -lstc_child.left )) /2
li_y = (( lstc_parent.bottom - lstc_parent.top ) -
( lstc_child.bottom -lstc_child.top )) /2
//计算子窗口的X、Y坐标
if li_x < 0 or li_y < 0 then return false
//移动子窗口
if not MoveWindow ( hwndcurrent ,li_x ,li_y ,lstc_child.right -lstc_child.left ,lstc_child.bottom - lstc_child.top ,false ) then return false
return true
本文代码在PB 7.0下通过。

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...