Talking about how to use PB to implement imitation QQ automatic displayhidden window (original)

zhaozj2021-02-16  50

Author: BALLOONMAN2002 2004 Nian 6 Yue 26 Ri

This article intends to combine the PowerBuilder language, briefly describe how to implement the automatic display / hiding window similar to QQ, that is, the automatic pop-up window is moved, and the window is automatically hidden after the mouse is removed, and the window is displayed when the Windows operating system is displayed after the window is displayed. Color strip scrolling effects to prompt users.

This article is intended to be divided into three sections of the following four times:

(1) Basic ideas

(2) Basic preparation work

(3) Automatic display / hidden window function implementation

(4) Realization of color strips rolling effect

First, basic ideas

(1) Use the API: TRACKMOUSEEVENT function to capture the WM_MouseEleave message to get and handle the mouse shift event; use the Window's MouseMove event to handle the mouse transfer in the event.

(2) Using the API: CreateSolidbrush, the FillRect function to dynamically create a color gradient area to implement different color bar scroll effects.

Note:

(1) Capture the four-class messages of WM_NCMOUSEHOVER, WM_NCMOUSELEAVE, WM_MOUSEHOVER, WM_MOUSEHOVER by calling the TRACKMOUSEEVENT function;

(2) You can also capture the WM_Mousehover message to handle the mouse to move in the event. In this example, you can directly process the mousemove event;

Second, the basic preparation work

1. Create a window to facilitate the problem, this example sets the Window Type property of the window to the popup type while setting the Title Bar property to no, which can reduce the impact of the WM_MOUSELEAVE message when the mouse enters non-customer area;

2, declare the local external function:

Function Integer TrackMouseevent (Ref str_track_mouse str_trm) library 'user32.dll'

Function Integer getcursorpos (Ref str_point lppoint) library 'user32.dll'

Function Integer getWindowRect (long ll_hwnd, ref str_rect lprect) library 'user32.dll'

Function Ulong PtinRect (Ref str_Rect LPRECT, ULONG PT_X, ULONG PT_Y) library "user32.dll"

Subroutine Sleep (Ulong dwmilliseconds) library "kernel32.dll"

Function Ulong getClientRect (Ulong Hwnd, Ref str_rect lprect) library "user32.dll"

Function Ulong ClientToscreen (Ulong Hwnd, Ref Str_Point LPPOINT) Library "User32.dll"

Function Ulong OffsetRect (REF STR_RECT LPRECT, ULONG PT_X, ULONG PT_Y) Library "User32.dll"

Function Ulong ReleaseCapture () library "user32.dll"

Function Ulong SendMessage (Ulong Hwnd, Ulong WMSG, Ulong WPARAM, REF ULONG LPARAM) Library "User32.dll" Alias ​​for "SendMessagea" Function Ulong getdc (ulong hwnd) library "user32.dll"

Function Ulong DeleteObject (Ulong Hobject) library "gdi32.dll"

Function Ulong Createsolidbrush (ulong crcolor) library "gdi32.dll"

Function Ulong ReleaseDC (Ulong Hwnd, Ulong HDC) Library "User32.dll"

Function Ulong FillRect (Ulong HDC, Ref Str_Rect LPRect, Ulong Hbrush) library "user32.dll"

Note: The structure involved in the above API declaration is reviews MSDN or other technical information.

3, statement instance variables:

Boolean ib_onform = false, ib_display = true, ib_first_display = true, ib_first_hide = true

Constant Integer WM_MouseLeave = 675

Constant Integer WM_NCLBUTTONDOWN = 161

Constant Integer HTCAPTION = 2

Third, automatic display / hidden window function implementation

1. Handling the Other event of the Window, with this event to capture the WM_MouseLeave message, to get and handle the mouse shift event:

STR_RECT LS_RECT

STR_POINT LS_POINT, LS_TMP

// Note: WM_MouseLeave Messages are sent once the Client area of ​​the window is sent, such as: This message will be sent when the mouse is shifted to the window, and this message will be sent when the mouse moves to the window of the window or MENU or Border Therefore, it is not possible to use any judgment and directly hide the window, and this message is only sent again. If you need to continue to track the mouse, you need to call the TRACKMOUSEEvent function again;

IF message.number = wm_mouseeleave thein

IB_ONFORM = FALSE

GetCursorpos (LS_POINT)

GetClientRect (Handle (this), LS_RECT

Ls_tmp.x = ls_rect.Left

LS_TMP.Y = Ls_Rect.top

Clienttoscreen (Handle (this), LS_TMP)

OffsetRect (ls_rect, ls_tmp.x, ls_tmp.y)

// Judgment the mouse if it exceeds the customer area, then automatically hide the window

// You can only use the client area to judge, you cannot use the entire window RECT, otherwise you may not hide the window when the mouse is moved to Border.

IF (PtinRect, LS_POINT.X, LS_POINT.Y) = 0) AND ((this.x <= 0) or (this.y <= 0)) THEN

IF this.y <= 0 THEN

WF_HIDE_V (this) // First guaranteed contraction in V-direction

Else

WF_HIDE_H (this) // Secondly guaranteed to shrink in the H direction slide end if

IB_DISPLAY = FALSE

END IF

END IF

2. Handling the Mousemove event of the Window to handle the mouse to move into the event:

IF IB_ONFORM = False Then

IB_ONFORM = TRUE

IF IB_DISPLAY = False Then

IF this.y <= 0 THEN

WF_DISPLAY_V (THIS)

Else

WF_DISPLAY_H (THIS)

END IF

IB_DISPLAY = TRUE

END IF

WF_CAPMOUSE (this)

END IF

3. Create the OPEN event of the window to set the initial location of the window:

THIS.BACKCOLOR = 16574393

this.title = "Automatic hidden window example ___ Double click Close window"

this.SetPosition (TopMost!)

THIS.WIDTH = P_1.Width

THISHEIGHT = p_1.height

THIS.X = 100

THIS.Y = -this. HEIGHT

WF_DISPLAY_V (THIS)

4. Create a corresponding window function WF_CAPMOUSE to call the mouse message capture function:

STR_TRACK_MOUSE STR_TRM

STR_TRM.NSIZE = 16

STR_TRM.HWNDTRACK = Handle (AG_DEST)

STR_TRM.NFLAGS = 2

TRACKMOUSEEVENT (STR_TRM)

5. Create a corresponding window function WF_DISPLAY_H to set up how to slide in the horizontal direction:

Integer li_left

STR_RECT LS_RECT1, LS_RECT2

STR_POINT LS_TMP

GetWindowRect (Handle (this), LS_RECT1)

GetClientRect (Handle (this), LS_RECT2)

LS_TMP.X = Ls_Rect2.Left

LS_TMP.Y = Ls_Rect2.top

Clienttoscreen (Handle (this), LS_TMP)

OffsetRect (ls_rect2, ls_tmp.x, ls_tmp.y)

LI_LEFT = ls_rect2.Left - ls_rect1.left // calculates the window border width

/ / The calculation window border can also be used with getSystemMetrics SM_CXBORDER / SM_CYBORDER / SM_CXFRAME / SM_CYFRAME, but it is necessary to judge that the window state is a variable border or a non-variable border or boundless box, so it is better to directly adopt the above method.

Do WHILE AS_WIN.X <-15

AS_WIN.X = as_win.x 10 // The 10 here is mainly used to control the window sliding speed

IF IB_FIRST_DISPLAY THEN

P_1.draw (0, 0) // This mainly prevents the image when the first sliding window is mainly displayed

END IF

Sleep function here is mainly used to control window sliding speeds

loop

as_win.x = -3 * li_left // This value does not be too small. Otherwise, the mouse is moved to the left side.

Ib_first_display = false

Note: The WF_DISPLAY_V function that is used to set the window slide in the vertical direction is no longer described again, modify the as_win.y attribute.

6. Create a corresponding window function WF_DISPLAY_H to set up how to slide hide in horizontal direction:

Do while as_win.x> -as_win.width 25as_win.x = as_win.x - 10

IF IB_First_Hide Then

P_1.draw (0, 0) // This mainly prevents image when the first hidden window

END IF

Sleep (0.005)

loop

As_win.x = -as_win.width 10 // The 10 here is used to control the width of the outer side after the last window is hidden.

IB_First_HIDE = FALSE

Note: The WF_DISPLAY_V function that is used to set the window slide in the vertical direction is no longer described again, modify the as_win.y attribute.

7. Because the window is the NO Titlebar window, it cannot be dragged. It is necessary to write the script to implement the drag effect, the method is the MouseDown event for the window:

Ulong Ll_arg

ReleaseCapture () // Release the capture of the MOUSE message, so WM_Mouseleave events occur during dragging

LL_ARG = 0

SendMessage (Handle (this), WM_NCLBUTTONDOWN, HTCAPTION, LL_ARG

// Send a WM_NCLBUTTONDOWN message, analog users to drag the titlebar effect

Fourth, color bar rolling effect

1. Get the HDC (Equipment handle) of the window, that is, write in the window of the OPEN event:

Disclaimer global variable: long gl_hdc

Declare external functions: function ulong getdc (ulong hwnd) library "user32.dll"

GL_HDC = GETDC (Handle (this))

2. Create a Timing Type User Object User Object for dynamic drawing color rectangles:

(1) First declare the object instance variable:

Integer II_Turn

STR_RECT IS_RECT_ALL, IS_RECT_FORM

Long il_hbrush, il_target_height, IL_TARGET_WIDTH, IL_TARGET_PACE, IL_HEIGHT_BASE

(2) Initialize the user object, write its constructor event:

II_TURN = 1

IL_TARGET_WIDTH = UnitStopixels (w_function.width, xunitstopixels!)

/ / Set the width of the entire target area

IL_TARGET_HEIGHT = UnitStopixels (w_function.height, yunitstopixels!)

/ / Set the height of the entire target area

IL_TARGET_PACE = 15 // Set color color strip scroll step distance

IL_HEIGHT_BASE = 100 // Set color color strip width

IS_RECT_ALL.LEFT = IL_TARGET_WIDTH - UnitStopixels (30, XUnitStopixels!)

IS_RECT_ALL.right = IL_TARGET_WIDTH

IS_RECT_FORM.TOP = 0

IS_RECT_FORM.BOTTOM = IL_TARGET_HEIGHT

IS_RECT_FORM.LEFT = IS_RECT_ALL.LEFT

IS_RECT_FORM.right = IS_RECT_ALL.RIGHT

IL_HBRUSH = Createsolidbrush (GL_BACKCOLOR)

(3) Start specific writing of dynamic color bar scroll effect code, Timer events that handle the object: STR_RECT LS_RECT_TMP

Long Ll_TMP, LL_RET, LL_HBRUSH

Integer li_red, li_green, li_blue

IF II_TURN = 1 THEN

IF is_RECT_ALL.TOP

Is_Rect_All.top = IS_RECT_ALL.TOP IL_TARGET_PACE

Else

IS_RECT_ALL.TOP = IL_TARGET_HEIGHT - IL_HEIGHT_BASE

II_TURN = -1

END IF

Else

IF is_RECT_ALL.TOP> IL_TARGET_PACE THEN

Is_Rect_All.top = IS_RECT_ALL.TOP - IL_TARGET_PACE

Else

IS_RECT_ALL.TOP = 0

II_TURN = 1

END IF

END IF

Is_rect_all.bottom = IS_RECT_ALL.TOP IL_HEIGHT_BASE

//w_function.backcolor = GL_BACKCOLOR

LL_RET = FillRect (GL_HDC, IS_RECT_FORM, IL_HBRUSH) // Note: This is higher than the above

Li_RED = MOD (GL_BackColor, 256)

LI_Green = truncate (MOD ((GL_Backcolor - Li_RED), 65536) / 256, 0)

Li_BLUE = truncate (GL_BackColor / 65536, 0)

LS_RECT_TMP.LEFT = IS_RECT_ALL.LEFT

LS_RECT_TMP.right = IS_RECT_ALL.RIGHT

IF II_TURN = 1 THEN

LS_RECT_TMP.BOTTOM = IS_RECT_ALL.TOP

Do while ls_rect_tmp.bottom

Li_RED = li_red - 20 // Note: The 20 of the colors determine the depth of color li_green = li_green - 20

LI_BLUE = li_blue - 20

IF li_red <0 THEN

Li_RED = 0

END IF

IF li_green <0 THEN

LI_Green = 0

END IF

IF li_blue <0 THEN

Li_BLUE = 0

END IF

LL_HBRUSH = Createsolidbrush (RGB (li_red, li_green, li_blue))

LS_RECT_TMP.TOP = Ls_Rect_Tmp.Bottom

Ls_rect_tmp.bottom = ls_rect_tmp.top 25 // Note: The 25 herein determines the gradient and slowness

LL_RET = FillRect (GL_HDC, LS_RECT_TMP, LL_HBRUSH)

LL_RET = deleteObject (ll_hbrush)

loop

Else

LS_RECT_TMP.TOP = IS_RECT_ALL.BOTTOM

Do WHILE LS_RECT_TMP.TOP> IS_RECT_ALL.TOPLI_RED = li_red - 20

LI_Green = li_green - 20

LI_BLUE = li_blue - 20

IF li_red <0 THEN

Li_RED = 0

END IF

IF li_green <0 THEN

LI_Green = 0

END IF

IF li_blue <0 THEN

Li_BLUE = 0

END IF

LL_HBRUSH = Createsolidbrush (RGB (li_red, li_green, li_blue))

LS_RECT_TMP.BOTTOM = Ls_Rect_Tmp.top

LS_RECT_TMP.TOP = Ls_Rect_Tmp.Bottom - 25

LL_RET = FillRect (GL_HDC, LS_RECT_TMP, LL_HBRUSH)

LL_RET = deleteObject (ll_hbrush)

loop

END IF

3. Call this Timing object in the main Window window:

(1) Handling OPEN Event: iuo_timer = CREATE UO_TIMER

(2) Handling WF_HIDE_H / V Event: iuo_timer.start (0.2)

(3) Handling Close event: Destroy iuo_timer

At this point, the imitation QQ automatically displays / hides the color bar rolling effect window all completed.

Since I am divided into two effects in two programs, I can't give a complete diagram, only examples of the following two figures:

http://blog.9cbs.net/images/blog_9cbs_net/balloonman2002/17312/r_autohide.jpg

http://blog.9cbs.net/images/blog_9cbs_net/balloonman2002/17312/r_scroll_eff.jpg

For further information, please contact QQ: 27855043, MSN: weiyin2001@msn.com

If you have something wrong, you respect your guidance.

转载请注明原文地址:https://www.9cbs.com/read-20125.html

New Post(0)