Author: BALLOONMAN2002 2004 Nian 6 Yue 26 Ri
This article intends to combine the PowerBuilder language, briefly describe how to dynamically translate the tree list, that is, the mouse moves to the tree list, which is dynamically prompt, and is a semi-transmissive tip similar to the Kingshan word.
See the renderings:
http://blog.9cbs.net/images/blog_9cbs_net/balloonman2002/17312/r_balloon-1.jpg
This article is intended to be divided into three sections of the following four times:
(1) Basic ideas
(2) How to get the current mouse coordinates corresponding Node node information
(3) Implementation of translucent effects
(4) Realization of bubble shape effect
First, basic ideas
(1) In the PowerBuilder language, the TreeView control does not have other languages such as VB. When the mouse is not selected, the current mouse corresponding to the Node node node node, which can directly use the HitTest method directly in VB. To get the Node node corresponding to the current mouse coordinates. However, by calling the API: SendMessage function to send a TVM_hittest message to the TreeView control to indirectly implement the above effects.
(2) In the Powerbuilder language, there is no direct control to transparent methods, and the current Windows2000 / XP operating system provides an API function: setLayeredWindowAttribute, but the API function does not support the Windows98 operating system, considering the comprehensive compatibility of the system. Sex, you must consider how Windows98 should achieve a translucent prompt effect. Therefore, we must give up the above API, and use the simulated translucent way, namely: processing Window's MouseMove event, when the mouse moves to a certain position, use the area of the mouse to use the API function Bitblt, alphablend screenshot, and copy to the bubble tips Control background equipment simulates a translucent effect.
(3) How to achieve Microsoft's bubble shape control? Since PowerBuilder is not well supported by some controls, and such controls are difficult to find, we consider writing themselves. Mainly by the API function: CreateRectrgn, CreateRoundRectrgn, CreatePolygonRGN, Combinergn, etc.
Second, how to get the current mouse coordinates corresponding Node node information
1. New window, with a TreeView control;
2, declare the local external function:
Function Ulong SendMessage1 (Ulong Hwnd, Ulong WMSG, Ulong WPARAM, REF TVHITTESTINFO LPARAM) Library "User32.dll" Alias for "SendMessagea"
Function Ulong SendMessage2 (Ulong Hwnd, Ulong WMSG, Ulong WPARAM, REF TVItem LParam) library "user32.dll" alias for "sendMessagea"
Subroutine CopyMemory (REF STRING DESTINATION, Long Source, long length) library "kernel32" alias for "RTLMOVEMEMORY"
Function Ulong Globalfree (Ulong HMEM) library "kernel32.dll" Function Ulong GlobalLOC (Ulong WFLAGS, ULONG DWBYTES) library "kernel32.dll" Note: Configuration of the above API declaration involves an MSDN or other technical information.
3. For this TreeView control custom user event UE_MOUSEMOVE (PBM_MOUSEMOVE), in this event, the mouse movement event is handled, send a TVM_HITTEST message:
TPoint PTA
TVHitTestinfo TF
TVItem TV
Ulong Hitem, LL_1, LL_2, LL_3, HSTR
Long Ret, LL_X, LL_Y
String Astr, BSTR, LS_HELP
PTA.x = UnitStopixels (XPOS, XUnitStopixels!)
PTA.Y = UnitStopixels (YPOS, YUNITSTOPIXELS!)
TF.PT = PTA
Tf.flags = 4
HITEM = sendMessage1 (Handle (TV_1), 4369, 0, TF)
// Note: The above 4369 is TVM_Hittest
// By sending a TVM_HitTest message to obtain the currently corresponding Node handle, save the current Node node information to the structural variable TF
IF (HITEM <= 0) or (HITEM = HITEMPRV)) THEN RETURN
HITEMPRV = HITEM
HSTR = GlobalAlloc (0,1024)
IF HSTR> 0 THEN
TV.mask = 1
TV.htreeItem = HITEM
TV.psztext = HSTR
TV.cchtextmax = 1023
RET = SendMessage2 (Handle (TV_1), 4364, 0, TV)
// Note: The above 4364 is TVM_GETITEM
/ / Save the current Node node information to the structural variable Tv by sending a TVM_GETITEM message to the current Node
astr = space (1024)
// Note: You must assign enough space here, otherwise it is easy to operate.
CopyMemory (Astr, HSTR, 1024)
// bstr = left (Astr, (POS (Astr, Char (0)) - 1))
Ret = GlobalFree (HSTR)
IDS_DS.SETFILTER ("")
IDS_DS.FILTER ()
RET = IDS_DS.FIND ("Name_Gn = '" astr "'", 1, IDS_DS.ROWCOUNT ())
IF RET> 0 THEN
Ls_help = IDS_DS.GETITEMSTRING (RET, "Help")
IF (isnull (ls_help) or trim (ls_help) = "") THEN
Timer (0)
Iuo_tips.hide ()
Else
IF is_help = ls_help then
Return
END IF
Iuo_tips.hide ()
IUO_TIPS.UF_SET_TEXT (Ls_help, Astr)
Ib_tipshow = false
Timer (1)
END IF
IS_HELP = LS_HELPELSE
Timer (0)
Iuo_tips.hide ()
END IF
Else
Timer (0)
Iuo_tips.hide ()
END IF
Third, the translucent effect is realized
1. Create a visual user object object and create an instance variable of the UO in the main window.
2, declare the local external function:
Function Ulong Getdc (Ulong Hwnd) Library "User32.dll"
Function Ulong Bitblt (Ulong HDestdc, Ulong X, Ulong Y, Ulong Nwidth, Ulong NHEIGHT, ULONG HSRCDC, ULONG XSRC, ULONG YSRC, ULONG DWROP) Library "gdi32.dll"
Function Ulong ReleaseDC (Ulong Hwnd, Ulong HDC) Library "User32.dll"
Function Ulong CreateCompatibleDC (Ulong HDC) Library "GDi32.dll"
Function Ulong CreateCompabilityBitmap (Ulong HDC, Ulong Nwidth, Ulong NHEight) library "gdi32.dll"
Subroutine Sleep (Ulong dwmilliseconds) library "kernel32.dll"
Function Ulong SelectObject (Ulong HDC, Ulong Hobject) library "gdi32.dll"
FUNCTION ULONG Alphablend (Long HDestDC, Long NHEIGHT, Long HSRCDC, Long Xsrc, Long Ysrc, Long Widthsrc, Long Heightsrc, Long Dreamaka) Library "MSIMG32"
Function Ulong Deletedc (Ulong HDC) Library "GDI32.DLL"
Function Ulong GetSystemMetrics (Ulong Nindex) library "user32.dll"
Subroutine CopyMemory2 (Ref Long Destination, Blendfunction Source, long length) library "kernel32" alias for "RTLMOVEMEMORY"
Function Ulong DeleteObject (Ulong Hobject) library "gdi32.dll"
3. Handle the Timer event of the main window for regular trigger information:
Long LL_X, LL_Y
IF II_TIP> 0 THEN
IF IB_TIPSHOW THEN
Ib_tipshow = false
Iuo_tips.hide ()
Timer (0)
Else
Ib_tipShow = TRUE
LL_X = w_main.pointx () 50
LL_Y = w_main.pointery () - iUO_TIPS.HEIGHT - 5
IF ll_y <2 THEN
LL_Y = 2
END IF
//WF_makeTrans(IUO_TIPS, IUO_TIPS.MLE_1, IL_X, IL_Y, 50)
WF_MAKETRANS (iUO_TIPS, IUO_TIPS.MLE_1, LL_X, LL_Y, 40) // The above function is a function for implementing translucent effects.
Timer (6)
END IF
END IF
4. Create a user function WF_MAKETRANS to achieve a translucent effect:
LONG HDCSCR, BHANDLE, HDEST, FRMDC, BLENDLNG, COPYWIDTH, COPYHEIGHT, COPYLEFT, COPYTOP, RET
Long CopyWidth2, CopyHeight2, Copyleft2, Copytop2, MLEDC
Long Xdeviation, YDEVIATION
Blendfunction Blend
Window LW_TMP
// blendlng = 11796480
Blend.SourceConstantalpha = char (Trans)
CopyMemory2 (Blendlng, Blend, 4)
LW_TMP = frm.getparent ()
//LW_TMP.SetredRaw (true)
CopyWidth = UnitStopixels (frm.width, xunitstopixels!)
CopyHeight = UnitStopixels (frm.height, yunitstopixels!)
CopyWidth2 = UnitsTopixels (Mle.Width, XUnitStopixels!)
CopyHeight2 = UnitStopixels (Mle.height, YunitStopixels!)
/ / The above code is used for coordinate system conversion
FRM.X = XPOS
FRM.Y = YPOS
IF lw_tmp.border <> false kil
YDEVIATION = getSystemMetrics (SM_CYCAPTION) GetSystemMetrics (SM_CYFRAME)
Xdeviation = getSystemMetrics (SM_CXFRAME)
Else
YDEVIATION = 0
Xdeviation = 0
END IF
IF Trim (LW_TMP.MENUNAME <> "" "
YDEVIATION = YDEVIATION GETSYSTEMETRICS (SM_CYMENU)
END IF
/ / Can also be converted with ClientToscreen
Copyleft = UnitStopixels ((LW_TMP.X XPOS), XUnitStopixels!) XdeViation
Copytop = UnitStopixels ((LW_TMP.Y YPOS), YUnitStopixels!) YDEVIATION
Copyleft2 = UnitStopixels (MLE.X, XUnitStopixels!)
COPYTOP2 = UnitStopixels (mle.y, yunitstopixels!)
/ / The above code is used for coordinate system conversion
HDCSCR = Getdc (0)
/ / Get the device handle of the screen
HDest = CREATECOMPATIPLEDC (HDCSCR)
Bhandle = CreateCompatibleBitmap (HDCSCR, COPYWIDTH, COPYHEIGHT)
RET = SELECTOBJECT (HDEST, BHANDLE)
FRMDC = Getdc (Handle (FRM))
MLEDC = Getdc (Handle (MLE))
// This sentence can be added, mainly to clear the original image purpose, prevent image overlap, VB must be .CLS because it has autoreraw capabilities //frm.seredRAW (true)
//mle.setredraw(true)
// 'Be sure to wait for a while, otherwise the form is not as good as HIDE, has been re-scaled.
Sleep (100)
Ret = Bitblt (HDest, 0, 0, CopyWidth, CopyHeight, HDCSCR, COPYLEFT, COPYTOP, 13369376)
/ / The above code is about to copy the screenshot of the screen to the memory cache area
// vb's properties of the model have autoreraws can be automatically redrawn, and PB has no movement, but it has to be displayed here.
IF IB_First THEN
WF_SETRGN (FRM)
END IF
frm.visible = true
IF IB_First THEN
WF_SETRGN (FRM)
IB_First = FALSE
END IF
Ret = alphablend (frMDC, 0, 0, CopyWidth, CopyHeight, HDEST, 0, 0, COPYWIDTH, COPYHEIGHT, BLENDLNG)
Ret = alphablend (MLEDC, 0, 0, CopyWidth2, CopyHeight2, HDest, Copyleft2, Copytop2, CopyWidth2, CopyHeight2, Blendlng)
/ / The above code copies the screenshots in the memory cache area to the HDC of the bubble U and the MLE_1 control there.
// setNewRGN FRM
WF_SETRGN (FRM)
Ret = releasedc (0, HDCSCR)
Ret = releasedc (Handle (FRM), FRMDC)
RET = ReleaseDC (Handle (MLE), MLEDC)
Ret = deletedc (hdest)
Ret = deleteObject (bhaldle)
// finally released or delete the acquired memory object
Fourth, the air bubble shape effect is realized
1, declare the local external function:
Function Ulong CreateRectRgn (Ulong X1, Ulong Y1, Ulong X2, Ulong Y2) Library "GDi32.dll"
Function Ulong CreateroundRectRgn (Ulong X1, Ulong Y1, Ulong X2, Ulong Y2, Ulong X3, Ulong Y3) Library "GDi32.dll"
Function Ulong CreatePolygonRgn (Ref Pointapi LPPOINT [], ULONG NCOUNT, ULONG NPOLYFILLLMODE "GDI32.DLL"
Function Ulong Combinergn (Ulong Hsrcrgn1, Ulong Hsrcrgn2, Ulong NCombinemode) Library "GDi32.dll"
Function Ulong Createsolidbrush (ulong crcolor) library "gdi32.dll"
Function Ulong Framergn (Ulong HDC, Ulong HRGN, ULONG HBRUSH, ULONG NWIDTH, ULONG NHEIGHT) LIBRARY "gdi32.dll"
Function Ulong SetwindowRgn (Ulong HWnd, Ulong HRGN, Boolean Bredraw) library "user32.dll" 2, create user functions WF_SETRGN, used to create a bubble shape control, the function is called in the user function Wf_makeTrans in the previous section:
Long RGN_1, RGN_2, MyRGN, HHBR, W, H, RET
Pointapi shapev []
// Initialization length, wide margin
W = UnitStopixels (frm.width, xunitstopixels!)
H = UnitStopixels (frm.height, yunitstopixels!)
// Initialize the right foot triangle vertex coordinate
Shapev [1] .x = w * (1/8)
Shapev [1] .y = H - 30
Shapev [2] .x = 0
Shapev [2] .y = h
Shapev [3] .x = w * (3/8)
Shapev [3] .y = h - 30
// Start to create a specified graphics area
MyRGN = CreateRectrGN (0, 0, 0, 0)
RGN_1 = CreateroundRectrgn (0, 0, W, H - 20, 20, 20)
// Create an elliptical angle rectangular area
RGN_2 = CREATEPOLYGONRGN (Shapev [], 3, 1)
// Create any polygonal area
// Merger final graphics
RET = Combinergn (MyRGN, RGN_1, RGN_2, 2)
// Create a user-defined color brush
Hhbr = Createsolidbrush (16479614)
// Frame of the final pattern
RET = Framergn (Getdc (Handle (FRM)), MyRGN, HHBR, 1, 1)
/ / Set the current form to use this area
Ret = setwindowrgn (Handle (frm), myRGN, TRUE
// Release each object
Ret = deleteObject (MyRGN)
Ret = deleteObject (RGN_1)
Ret = deleteObject (RGN_2)
Ret = deleteObject (HHBR)
2. Use the above code to easily implement the right foot prompt effect in the right task bar, as shown:
http://blog.9cbs.net/images/blog_9cbs_net/balloonman2002/17312/r_balloon-2.jpg
At this point, the tree list dynamic and translucent effect is all completed, and the renderings are shown in:
http://blog.9cbs.net/images/blog_9cbs_net/balloonman2002/17312/r_balloon-1.jpg
For further information, please contact QQ: 27855043, MSN: weiyin2001@msn.com
If you have something wrong, you respect your guidance.