This article dedicates a PB programmer who wants to beautify the program interface.
1. Load bitmap resources and create Patternbrush as a brush LL_BMPLONG H_DESKDCLONG LL_MEMDC for filling background diagram
IF IH_BKBRUSH> 0 THEN DeleteObject (IH_BKBRUSH) IH_BKBRUSH = 0nd IF
h_deskdc = getdc (0) // Load picture LL_BMP = LoadImage (0, BMPBKNAME, 0, 0, 0, 16) // failed if ll_bmp = 0 Then ReleaseDC (0, h_deskdc) Return End IFLL_MEMDC = CreateCompAMPALDC (h_deskdc) / / Select the scene SelectObject (LL_MEMDC, LL_BMP) // Create a brush IH_BKBRUSH = CreatePatternbrush (LL_BMP) // release unwanted resource ReleteDc (ll_bmp) deleteObject (ll_MEMDC)
2. Give listview plus background diagram 1. Get a ListView customer area rectangle GetClientRect (Handle (this), LvClientRect)
2. In ListView as the event ID, custom event UE_ERASEBKGND, Script as follows IF IH_BKBRUSH> 0 THEN FILLRECT (HDC, LvClientRect, IH_BKBRUSH) Return 1END IF
3. When the ListView's display style is ListViewReport!, When the ListViewList! Is dragging the scroll bar, it will appear to extrusion needs to be used as the EVENTID custom event UE_VScroll, UE_HSCROLL. if ih_BkBrush> 0 and (View = listviewreport! or View = listviewlist!) then if (scrollcode <> SB_ENDSCROLL) and (scrollcode <> SB_THUMBPOSITION) then InvalidateRect (handle (this), lvclientRect, 1) end ifend if Nevertheless, Drag the scroll bar in the above two styles still have a flash, I have not been able to solve it, welcome everyone to make an opinion.
4. If you want listview item text and graphics in a transparent background, simply call the following Constant Long CLR_NONE = 4294967295Constant Long LVM_FIRST = 4096Constant Long LVM_SETTEXTBKCOLOR = (LVM_FIRST 38) Constant Long LVM_GETIMAGELIST = (LVM_FIRST 2) Constant Long LVM_SETBKCOLOR = (LVM_First 1) constant long lvsil_normal = 0constant long lvsil_small = 1constant long lvsil_state = 2 // Let the background color transparent Send (Handle (this), LVM_SETTEXTBKCOLOR, 0, CLR_NONE) / / Let the picture background color transparent Send (Handle (this), LVM_SETBKCOLOR, 0, CLR_NONE)
Also, if you use PB you bring a picture, you need to set PictureMaskColor to Silver.
III. Give the TreeView to the background diagram If the TreeView control is added to the TreeView control, it can also be implemented, but the graph is extruded when the child of the tree is deployed, shrinks, and drags the scroll bar. If you use setRAW control Severe flicker will occur. The text and picture background of the child of the tree cannot be transparent. 1. I will refer to the routines implemented by other programming languages, and basically handle it in the WM_PAINT event, so I use PBM_Paint as the EventID Custom Event UE_Paint. However, because the parameter HDC of this event is 0 in any case, I guess in the PB, this event is only executed before calling the WindowProc processing WM_PAINT message and does not use BeginPaint to start a drawing operation. To make the text and picture background of the child of the tree transparent, just do some raster calculations, the code is as follows: if Ih_bkbrush> 0 THEN
If Message.WordParm> 0 THEN / / Trigrated by the Send Function with WordParm Parameters, do not perform the following operation Return 0 End if tagpaintstruct PS // Start Paint Operation HDC = BeginPaint (Handle (this), PS) Long MEMDC, MASKDC, Resultdc ; long hbitmap; long li_RCWidth, li_RCHeight li_RCWidth = tvclientRect.right -tvclientRect.left li_RCHeight = tvclientRect.bottom -tvclientRect.top ResultDc = CreateCompatibleDC (hdc); hbitmap = CreateCompatibleBitmap (hdc, li_RCWidth, li_RCHeight); SelectObject (ResultDc, hbitmap) ; deleteObject (hbitmap) // background drawing apparatus to the scene ResultDc FillRect (ResultDc, tvclientRect, ih_BkBrush) // create a compatible memory dc memdc = CreateCompatibleDC (hdc); hbitmap = CreateCompatibleBitmap (hdc, li_RCWidth, li_RCHeight); SelectObject (MEMDC, HBitMap); DeleteObject (HbitMap) // Draw TV content to device scene MEMDC send (Handle (this), WM_Paint, MEMDC, 0) // Create Mask DC Maskdc = CreateCompatibleDC (HDC); hbitmap = creteBitmap (li_rcwidth, li_rcheight, 1, 1, 0); SelectObject (Maskdc, HBitmap); deleteObject (hbitmap) // only monochrome Bitblt (MaskDC, 0, 0, LI_RCWIDTH, LI_RCHEIGHT, MEMDC, 0, 0, SRCCOPY); setBk Color (MEMDC, RGB (0)); SetTextColor (MEMDC, RGB (255, 255, 255)) // Alternative to Black Bitblt (MEMDC, 0, 0, LI_RCWIDTH, LI_RCHEIGHT, MASKDC, 0, 0, SRCAND); // With the AND operation, set item and text to black Add to Bitblt (Resultdc, 0, 0, Li_RcWidth, Li_RCHEIGHT, MASKDC, 0, 0, Srcand); // TreeItem is replaced by the original There is color Bitblt (Resultdc, 0,0, li_rcwidth, li_rcheight, memdc, 0, 0, srcpaint); // will be combined after Copy to HDC Bitblt (HDC, 0, 0, LI_RCWIDTH, LI_RCHEIGHT, RESULTDC, 0, 0, SRCCOPY); DELETEDC (MEMDC) deletedc (MASKDC) deletedc (resultDC) // End Paint Operation Endpaint (Handle (this), PS) End IF
Due to the multiple bitmap processing operations, there may be a delay in the remote machine, so the length and width of the TreeView control should not be too large, and the number of children should be controlled within a reasonable range.
2. Since we have drawn backgrounds in the UE_PAINT event, you need to block the default refresh background operation. UE_ERASEBKGND: IH_ERASEBKGND: IH_BKBRUSH> 0 THEN / / Do not perform the default message handler Return 1END IF3. For TreeView due to child expansion, the graph is squeezed, it is necessary for ItemCollapsin, itemExpanding, and SELECTCHANGING event control to redraw over the control. IF IH_BKBRUSH> 0 THEN INVALIDATERECT (Handle (THIS), TVCLIENTRECT, 0) 4, and similar processing is also required for graphical backlogs generated by the scroll bar. PBM_VSCROLL and PBM_HSCROLL: IH_BKBRUSH> 0 and (scrollcode <> sb_endscroll) and (scrollcode <> sb_thumbposition) THEN INVALIDATERECT (Handle (this), TVClientRect, 0) Endiff
Here I only explain the key implementation of the program, omitting related variables, external functions, structural declarations, and other parts. The complete PB8 routine can be downloaded at http://www.tiantiansoft.com/bbs/fileshow.asp?boardid=79&id=234, you are welcome to discuss further :)