PB中消息对话框的居中显示
上海大学 孙渊磊
| 和共享对象有关的函数包括: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函数列出所有有效的共享对象。 |
| 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” |
| 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) |
| Ulong lul_hwnd //存放消息对话框的句柄 |
| Ulong lul_start //计时开始时刻的值 |
| lul_start = GetTickCount ( ) //计时开始 |
| lul_hwnd=FindWindowA ( lpclassname ,lpwindowname ) |
| if lul_hwnd <> 0 then exit |
| loop while GetTickCount( )-lul_start< dwtimeout |
| return of_center ( 0 ,lul_hwnd ) |
| ccuo_thread.of_center ( Ulong hwndp ,Ulong hwndc ) return Boolean |
| stc_rect lstc_parent //父窗口的4边坐标 |
| stc_rect lstc_child //子窗口的4边坐标 |
| if hwndp = 0 then hwndparent = |
| 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 |
| 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 |
转载请注明原文地址: https://ibbs.8miu.com/read-31732.html