惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 王跃军

成本安全硬件(二):RFID on PN532 之WINDOWS 环境应用 C# 委托的三种调用示例(同步调用 异步调用 异步回调) 之 FUNC 版 vb中使用Xtreme Command Bars ActiveX Control 的IPrintView接口绘制图形_后记 android开发专题系列-OPENGL android开发专题系列-Android开发指南 android开发专题系列-一个简单的游戏的设计 android网站汇集 android开发资料(DEVELOPER.ANDROID.COM/SDK)WORD版 可也extJs相媲美的js 控件集 DHTMLX 对ASP.NET 安全方面的一些理解 ANDROID 开发资源网站列表(2008年1月14日) [转]林西:企业信息化规划方法 [收藏]DIV+CSS布局积累 [转]常用SQL 深入实例理解 [转]可用表格样式表 DataSet 加载XML 数据效果 纯ajax式,多用户选择示例 asp.net全局异常处理 也nhibernate会遇到问题,还好找到原因了
vb中使用Xtreme Command Bars ActiveX Control 的IPrintView接口绘制图形
王跃军 · 2011-10-17 · via 博客园 - 王跃军

应用场景

Xtreme Command Bars ActiveX Control中的PrintView,可以通过API绘制任意图形和文字,Xtreme Command Bars ActiveX Control的PrintView只支持

rtf格式和XAML两种输入基本输入源的。

CreateMarkupPrintView Creates an IPrintView object from the supplied XAML Markup string. 
CreateRichEditPrintView Creates an IPrintView object from the supplied RTF string.

感谢 :  Soyokaze在 http://topic.csdn.net/u/20081016/08/e5189330-4fec-4287-9009-47e681723ea3.html 里的代码

            无名氏    在      http://zj1.51.net/book/show.php?type=vbtip&id=1099050675里的代码

如下代码,实现剪贴板里的图片的PrintView控件输出

1.图像输入

Public Function CopyEntirePicture(ByRef objFrom As Object) As Boolean

Dim lhDC As Long

Dim lhBMP As Long

Dim lhBMPOld As Long

    '在内存中建立一个指向我们将要复制对象的DC:

    lhDC = CreateCompatibleDC(objFrom.hdc)

    If (lhDC <> 0) Then

        '建立一张指向将要复制对象的位图:

        lhBMP = CreateCompatibleBitmap(objFrom.hdc, objFrom.ScaleWidth \ Screen.TwipsPerPixelX, objFrom.ScaleHeight \ Screen.TwipsPerPixelY)

        If (lhBMP <> 0) Then

            '把位图选入我们刚才建立的DC中,并贮存原先在那里的老位图:

            lhBMPOld = SelectObject(lhDC, lhBMP)

            '把objFrom的内容复制到建立的位图里:

            BitBlt lhDC, 0, 0, objFrom.ScaleWidth \ Screen.TwipsPerPixelX, objFrom.ScaleHeight \ Screen.TwipsPerPixelY, objFrom.hdc, 0, 0, SRCCOPY

            '恢复DC中的内容:

            SelectObject lhDC, lhBMPOld

            '现在把位图装入剪贴板:

            EmptyClipboard

            OpenClipboard 0

            SetClipboardData CF_BITMAP, lhBMP

            CloseClipboard

            '我们在这里不用删除建立的位图——

            '它现在属于剪贴板,当剪贴板变化时,Windows将为我们删除它。

        End If

        '清除刚才建立的DC:

        DeleteObject lhDC

    End If

End Function

2.图像输出

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                        '定义Picture对象

        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)

    '取得 Bmp 像素位

    With tBmpInfo.bmiHeader

        .biSize = Len(tBmpInfo.bmiHeader)

        .biWidth = tSize.cx

        .biHeight = tSize.cy

        .biPlanes = 1

        .biBitCount = 24

        .biCompression = BI_RGB

    End With

    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