Application scenarios
Printview in Xtreme command bars ActiveX control. You can use APIs to draw arbitrary graphics and text. printview of Xtreme command bars ActiveX control only supports
The Basic Input Source of the two types of input: RTF format and XAML.
Createmarkupprintview creates an iprintview object from the supplied XAML markup string.
Createricheditprintview creates an iprintview object from the supplied RTF string.
Thanks: soyokaze in http://topic.csdn.net/u/20081016/08/e5189330-4fec-4287-9009-47e681723ea3.htmlCode
Who's in http://zj1.51.net/book/show.php? Type = code in vbtip & id = 1099050675
The following code outputs the printview control of the image in the clipboard:
1. Image Input
Public Function copyentirepicture (byref objfrom as object) as Boolean
Dim lhdc as long
Dim lhbmp as long
Dim lhbmpold as long
'Create a DC pointing to the object to be copied in the memory:
Lhdc = createcompatibledc (objfrom. HDC)
If (lhdc <> 0) then
'Create a bitmap pointing to the object to be copied:
Lhbmp = createcompatiblebitmap (objfrom. HDC, objfrom. scalewidth \ screen. twipsperpixelx, objfrom. scaleheight \ screen. twipsperpixely)
If (lhbmp <> 0) then
'Select the bitmap to the DC we just created, and store the old bitmap from there:
Lhbmpold = SelectObject (lhdc, lhbmp)
'Copy the object content to the created bitmap:
Bitblt lhdc, 0, 0, objfrom. scalewidth \ screen. twipsperpixelx, objfrom. scaleheight \ screen. twipsperpixely, objfrom. HDC, 0, 0, srccopy
'Restore the content in the DC:
SelectObject lhdc, lhbmpold
'Load the bitmap to the clipboard now:
Emptyclipboard
Openclipboard 0
Setclipboarddata cf_bitmap, lhbmp
Closeclipboard
'Here we do not need to delete the created bitmap --
'It now belongs to the clipboard. When the clipboard changes, Windows will delete it for us.
End if
'Clear the created DC:
Deleteobject lhdc
End if
End Function
2. image output
Implements iprintview
Option explicit
Private declare function getdibits lib "GDI32 "(_
Byval ahdc as long ,_
Byval hbitmap as long ,_
Byval nstartscan as long ,_
Byval nnumscans as long ,_
Lpbits as any ,_
Lpbi as bitmapinfo ,_
Byval wusage as long )_
As long
Private type bitmapinfoheader '40 bytes
Bisize as long
Biwidth as long
Biheight as long
Biplanes as integer
Bibitcount as integer
Bicompression as long
Bisizeimage as long
Bixpelspermeter as long
Biypelspermeter as long
Biclrused as long
Biclrimportant as long
End type
Private type rgbquad
Rgbblue as byte
Rgbgreen as byte
Rgbred as byte
Rgbreserved as byte
End type
Private type bitmapinfo
Bmiheader as bitmapinfoheader
Bmicolors as rgbquad
End type
Private const bi_rgb = 0 &
Private const bi_rle4 = 2 &
Private const bi_rle8 = 1 &
Private const bi_bitfields = 3 &
Private const dib_rgb_colors = 0
Private declare function stretchdibits lib "GDI32" (byval HDC as long, byval X as long, byval y as long, byval DX as long, byval dy as long, byval srcx as long, byval srcy as long, byval wsrcwidth as long, byval wsrcheight as long, lpbits as any, lpbitsinfo as bitmapinfo, byval wusage as long, byval dwrop as long) as long
Private declare function geticoninfo lib "USER32" (byval hicon as long, piconinfo as iconinfo) as long
Private type iconinfo
Ficon as long
Xhotspot as long
Yhotspot as long
Hbmmask as long
Hbmcolor as long
End type
Private declare function getobjecttype lib "GDI32" (byval hgdiobj as long) as long
Private const obj_bitmap = 7
Private const obj_brush = 2
Private const obj_font = 6
Private const obj_pal = 5
Private const obj_pen = 1
Private declare function GetObject lib "GDI32" alias "getobjecta" (byval hobject as long, byval ncount as long, lpobject as any) as long
Private type bitmap
Bmtype as long
Bmwidth as long
Bmheight as long
Bmwidthbytes as long
Bmplanes as integer
Bmbitspixel as integer
Bmbits as long
End type
Private type size
CX as long
Cy as long
End type
Private const srccopy = & hcc0020 '(DWORD) DEST = Source
Private type rect
Left as long
Top as long
Right as long
Bottom as long
End type
Private const dt_center = & H1
Private const dt_singleline = & H20
Private sub iprintview_beginprinting (byval HDC as long, byval hattribdc as long, byval printinfo as xtremecommandbars. printinfo)
End sub
Private sub iprintview_endprinting (byval HDC as long, byval hattribdc as long, byval printinfo as xtremecommandbars. printinfo)
End sub
Private sub iprintview_preparedc (byval HDC as long, byval hattribdc as long, byval printinfo as xtremecommandbars. printinfo)
End sub
Private sub iprintview_prepareprinting (byval printinfo as xtremecommandbars. printinfo)
Printinfo. maxpage = 1
End sub
Private sub iprintview_printpage (byval HDC as long, byval hattribdc as long, byval printinfo as xtremecommandbars. printinfo)
If (printinfo. currentpage = 1) then
Dim R as rect
R. Left = printinfo. printrectleft
R. Top = printinfo. printrecttop
R. Right = printinfo. printrectright
R. Bottom = printinfo. printrectbottom
Dim mypic as picture 'defines the picture object
Set mypic = clipboard. getdata (vbcfbitmap)
Dim tbmpinfo as bitmapinfo
Dim tsize as size
Dim hbmp as long
Dim bybits () as byte
Dim nbperline as long
Hbmp = mypic. Handle
Call getimagesize (hbmp, tsize)
'Get BMP pixel bit
With tbmpinfo. bmiheader
. Bisize = Len (tbmpinfo. bmiheader)
. Biwidth = tsize. CX
. Biheight = tsize. Cy
. Biplanes = 1
. Bibitcount = 24
. Bicompression = bi_rgb
End
Nbperline = (tsize. CX * 3 + 3) and & hfffffffc
Redim bybits (nbperline-1, tsize. Cy-1) as byte
Call getdibits (HDC, hbmp, 0, tsize. Cy, bybits (0, 0), tbmpinfo, dib_rgb_colors)
Call stretchdibits (HDC, 0, 0, tsize. CX, tsize. cy, 0, 0, tsize. CX, tsize. cy, bybits (0, 0), tbmpinfo, dib_rgb_colors, srccopy)
End if
End sub
Private sub getimagesize (byval hobject as long, tsize as size)
Dim tbmp as bitmap
Dim ticon as iconinfo
If getobjecttype (hobject) = obj_bitmap then
Call GetObject (hobject, lenb (tbmp), tbmp)
Elseif geticoninfo (hobject, ticon) then
Call GetObject (ticon. hbmmask, lenb (tbmp), tbmp)
End if
Tsize. Cx = tbmp. bmwidth
Tsize. Cy = tbmp. bmheight
End sub