Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the central display method of the message dialog box in PB

2025-04-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "what is the central display method of the message dialog box in PB". In the operation of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

SharedObject series functions

Functions related to shared objects include the SharedObjectRegister, SharedObjectGet, SharedObjectUnregister, and SharedObjectDirectory functions.

First, initialize the shared object with the SharedObjectRegister function and set up a separate thread. Such as:

SharedObjectRegister ("ccuo_thread", "thread1")

Where ccuo_thread is the class name of a shared custom class user object, and thread1 is the shared name of the shared object instance. If the SharedObjectRegister function returns Success, the new thread is created successfully.

Then, execute the specified code. There are two ways for a new thread to execute the specified code: one is to write a script in the constructor event of a custom class user object, which is automatically executed when the new thread is created, and the other is to use the SharedObjectGet function. This function implements references to shared object instances, such as:

SharedObjectGet ("thread1", inv_thread)

Where inv_thread is an object variable used to store shared object instances, requiring the same class name as ccuo_thread.

Finally, the function of_function of the shared object is called asynchronously by using the post statement, that is, in the form of inv_thread.Post of_function (agrs).

After completing the task, you can use the SharedObjectUnregister function to abort the thread, or you can use the SharedObjectDirectory function to list all valid shared objects.

Function calling part

The prototype of Win32 API function used in this paper is:

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"

The following details discuss how to center the message dialog box:

/ / declare object variables

Ccuo_thread lccuo_thread

/ / create a new thread

SharedObjectRegister ('ccuo_thread',' thread_center')

/ / reference instance

SharedObjectGet ('thread_center', lccuo_thread)

/ / call the window center function

Lccuo_thread.Post of_center ('# 32770', 'Demostration', 2000)

/ / create message dialog box

MessageBox ('Demostration',' Copyright (c) 2001 by Y.L.Sun')

/ / abort the thread

SharedObjectunRegister ('thread_center')

Function implementation part

The function displayed in the center of the window is the object function of_center of the custom user object ccuo_thread. In fact, the code is as follows:

Ccuo_thread.of_center (String lpclassname, String

Lpwindowname, Ulong dwtimeout) return Boolean

/ / lpclassname: the class name of the message dialog box (# 32770)

/ / lpwindowname: title of the message dialog box

/ / dwtimeout: timeout count

Ulong lul_hwnd / / handle to the message dialog box

The value of the start time of Ulong lul_start / / timing

Lul_start = GetTickCount () / / timing starts

Do

/ / find top-level window

Lul_hwnd=FindWindowA (lpclassname, lpwindowname)

/ / after finding the top-level window, jump out of the loop

If lul_hwnd 0 then exit

/ / determine whether it has timed out

Loop while GetTickCount ()-lul_start < dwtimeout

/ / No message dialog found

If lul_hwnd = 0 then

Return false

Else

/ / the dialog box is centered

Return of_center (0, lul_hwnd)

End if

The overloaded function code of of_center is as follows:

Ccuo_thread.of_center (Ulong hwndp, Ulong hwndc) return Boolean

/ / hwndp: the handle to the parent window, which is considered to be the desktop when the value is 0

/ / hwndc: handle to the child window

X coordinates of int li_x / / window

Y coordinates of int li_y / / window

4-sided coordinates of the stc_rect lstc_parent / / parent window

The 4-sided coordinates of the stc_rect lstc_child / / child window

/ / A value of 0 is considered to be the desktop.

If hwndp = 0 then hwndparent =

GetDesktopWindow ()

/ / obtain the 4-sided coordinates of the window

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

/ / calculate the X and Y coordinates of the child window

If li_x < 0 or li_y < 0 then return false

/ / move child window

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

The code of this paper is passed under PB 7. 0.

This is the end of the content of "what is the central display method of the message dialog box in PB". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report