vb中使用Xtreme Command Bars ActiveX Control 的IPrintView接口绘制图形_后记

 

上篇文章 写了vb中使用Xtreme Command Bars ActiveX Control 的IPrintView接口绘制图形,但后来发现有个致命的问题,预览时没有问题,但实际输出到打印机时,则是一片

黑色,所以上篇代码无效.现重新上代码,解决以上问题的

本次实现原理是像素获取后,再逐个重绘出来.

首先还是使用IPrintView接口的类,

Implements IPrintView
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type


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)
Dim r As RECT
        r.Left = PrintInfo.PrintRectLeft
        r.Top = PrintInfo.PrintRectTop
        r.Right = PrintInfo.PrintRectRight
        r.Bottom = PrintInfo.PrintRectBottom
If Not PrintInfo.PreviewMode Then
ZoomImage 4500, 4500
End If

MemOutPut hdc, False



End Sub

  然后是调用类

With Pic1
.AutoRedraw = True
.Appearance = 0
.BorderStyle = 0
.ScaleMode = 3
End With
W = Pic1.ScaleWidth
H = Pic1.ScaleHeight
MemGet Pic1.hdc, 0, 0, W - 1, H - 1

Set Form7.PrintPreview.PrintView = cls
Form7.Show vbModal

然后是相关的函数模块下载



posted @ 2012-01-16 10:12 王跃军 阅读(15) 评论(0) 编辑

vb中使用Xtreme Command Bars ActiveX Control 的IPrintView接口绘制图形

应用场景

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

posted @ 2011-10-17 18:54 王跃军 阅读(28) 评论(0) 编辑

android开发专题系列-OPENGL

[翻译]Android 3D 游戏开发教程– Part I http://blog.csdn.net/lixinso/archive/2010/01/30/5272495.aspx lixinso
Android游戏开发简介 http://www.moandroid.com/?p=1730
Android书籍分享 http://www.moandroid.com/?p=1714
Matrix学习——基础知识 http://www.moandroid.com/?p=1771
Android开发指南-三维图形 http://blog.csdn.net/iefreer/archive/2009/10/01/4624989.aspx 陈小峰
深入Android 【二】 —— 架构和学习 http://www.cnblogs.com/duguguiyu/archive/2010/01/23/1654559.html duguguiyu
[转]OpenGL混色介绍 http://www.cnblogs.com/jacktu/archive/2010/06/04/1751170.html jsot
【转】OpenGL ES中关于设置透视视窗的函数gluPerspective的参数说明 http://www.cnblogs.com/jacktu/archive/2010/05/18/1738594.html jsot
OpenGL ES 1.0与OpengGL的区别 http://www.cnblogs.com/jacktu/archive/2010/05/18/1738444.html jsot
OPhone 3D开发之解析渲染MS3D模型 http://www.cnblogs.com/jacktu/archive/2010/02/10/1666967.html jsot
OpenGL ES 中英文字体渲染 http://www.cnblogs.com/iMobile3D/archive/2010/01/15/1648219.html iMobile3D
iPhone – saving OpenGL ES content to the Photo Album http://www.cnblogs.com/iMobile3D/archive/2009/11/13/1602490.html iMobile3D
[ZT]OpenGL ES概述 http://www.cnblogs.com/iMobile3D/articles/1291119.html iMobile3D
C++各大有名库的介绍之C++标准库 http://lgy-047.blog.163.com/blog/static/61346565201031910531534 lgy-047
Android 2.1 源码结构分析(转) http://jianhuazhang2008.blog.163.com/blog/static/4122422920104311853263 大森林
Android核心模块及相关技术 http://jianhuazhang2008.blog.163.com/blog/static/41224229201009105024819 大森林
Android OpenGL学习笔记(二)之----三角形的绘制. http://blog.csdn.net/Android_Tutor/archive/2010/05/20/5612614.aspx Android_Tutor
Android OpenGL学习笔记(一) http://blog.csdn.net/Android_Tutor/archive/2010/05/11/5580583.aspx Android_Tutor
android图形系统编程学习(一)入门 http://blog.csdn.net/wbw1985/archive/2010/05/15/5595441.aspx 布道者
OpenMAX简介 http://jituo666.blog.163.com/blog/static/2948172120104246221703 宣寄托
OpenGL 介绍 http://jituo666.blog.163.com/blog/static/29481721201001511111870 宣寄托
我保存网站 http://jituo666.blog.163.com/blog/static/294817212010015101815895 宣寄托
Android 源码分析 http://a315823806.blog.163.com/blog/static/44187634201026113948698 Android虚竹
meego API http://www.cnblogs.com/leaven/archive/2010/06/13/1757823.html 城市守望者
MeeGo体系结构 http://www.cnblogs.com/leaven/archive/2010/06/13/1757821.html 城市守望者
软件工程思想<下> http://ruixiazun.blog.163.com/blog/static/90687918201052594453462 ruixiazun
从计算机系学生(含游戏学院)到强大的游戏程序员必备书单 http://parkmy.javaeye.com/blog/684991
一个游戏引擎——Rokon http://crazier9527.javaeye.com/blog/730734
(转载)Android核心模块及相关技术 http://blog.sina.com.cn/s/blog_593aa8dd0100d9pf.html XAndroid
[转]Ogre3D支持iPhone了! http://blog.sina.com.cn/s/blog_4a0a39c30100gb8f.html 风子
Forget3D 支持G3D模型了! http://blog.sina.com.cn/s/blog_4a0a39c30100g0js.html 风子
OpenGl函数库 http://blog.sina.com.cn/s/blog_4fa676f60100ir58.html 无知者无畏
关于opengl---------(1) http://blog.sina.com.cn/s/blog_4fa676f60100ir4i.html 无知者无畏
Android 架构以及如何开发应用程序简介 http://blog.sina.com.cn/s/blog_4fa676f60100efq5.html 无知者无畏
Android学习系列 http://blog.sina.com.cn/s/blog_61bc83ff0100fzst.html 海市蜃楼
认识Android http://blog.sina.com.cn/s/blog_3d39db5901008uca.html 忘忧草
图形渲染技术的一些整理 http://blog.sina.com.cn/s/blog_537d39500100hldc.html MaxBlog
android 入门之二【android 体系架构】 http://blog.sina.com.cn/s/blog_4e60b09d0100kzws.html 12点的小鬼
Android2.1源码结构 http://blog.sina.com.cn/s/blog_55b1b0d50100ishe.html 阿圈
Opengles 1.1 manual http://paullu.blog.51cto.com/828864/172899 Paul_Lu
Android OpenGL 学习笔记 --开始篇 http://terryblog.blog.51cto.com/1764499/346996 terry_龙
用户虚拟地址转换成物理地址 http://buaadallas.blog.51cto.com/399160/353161 buaadallas
Android OpenGL实战三——3D空间效果 http://jc1226.blog.sohu.com/151349802.html
Android OpenGL实战二——颜色和旋转 http://jc1226.blog.sohu.com/151338119.html
Android OpenGL实战一——开发框架搭建、三角形和四边形的绘制 http://jc1226.blog.sohu.com/151318350.html
在Eclipse里查看android源代码 http://swverification.blog.sohu.com/144145545.html
bitmap 设置图片尺寸,避免 内存溢出 OutOfMemoryError的优化方法 http://tonyyu.javaeye.com/blog/713256
Android2.2 新特性 http://www.cnblogs.com/game-over/archive/2010/05/22/1741411.html Game_over
Gallery3D笔记 http://blog.163.com/guozioo@126/blog/static/64086947201052154913244 moon
OPENGL ES中几个重要函数详细说明 http://th8410.javaeye.com/blog/712390
androidにはOpenGLを勉強する http://th8410.javaeye.com/blog/711441
Android核心模块及相关技术(转载) http://ssd910.blog.163.com/blog/static/2387679720105301133288 云端漫步
Android OpenGL 学习笔记 --开始篇 http://www.cnblogs.com/TerryBlog/archive/2010/07/09/1774475.html Terry_龙
VLC初探 http://blog.sina.com.cn/s/blog_5be1061c0100jr0i.html 太阳下的泪
Android OpenGL 学习笔记 --开始篇 http://www.fengfly.com/plus/view-185431-1.html
《深入浅出Android多媒体编程》即将有人民邮电出版社出版 http://miaozl.spaces.live.com/Blog/cns!F408F266382E09FE!963.entry
开发者或想使用的10个Android2.2新特性 http://blog.sina.com.cn/s/blog_4e60b09d0100lcnc.html 12点的小鬼
Android 3D游戏开发教程 http://www.fengfly.com/plus/view-186702-1.html
posted @ 2010-08-18 13:59 王跃军 阅读(152) 评论(0) 编辑

android开发专题系列-Android开发指南

标题概述地址作者
Android开发指南-窗口小部件(App Widgets) http://blog.csdn.net/iefreer/archive/2009/10/01/4626274.aspx 陈小峰
Android开发指南-二维图形 http://blog.csdn.net/iefreer/archive/2009/09/30/4619697.aspx 陈小峰
Android开发指南-工具-画九宫格 http://blog.csdn.net/iefreer/archive/2009/09/29/4618025.aspx 陈小峰
Android开发指南-用户界面-创建自定义组件 http://blog.csdn.net/iefreer/archive/2009/09/26/4598932.aspx 陈小峰
Android开发指南-用户界面-绑定数据 http://blog.csdn.net/iefreer/archive/2009/09/27/4601808.aspx 陈小峰
Android开发指南-用户界面-风格和主题 http://blog.csdn.net/iefreer/archive/2009/09/25/4595533.aspx 陈小峰
Android开发指南-用户界面-用户通知 http://blog.csdn.net/iefreer/archive/2009/09/25/4594818.aspx 陈小峰
Android开发指南-三维图形 http://blog.csdn.net/iefreer/archive/2009/10/01/4624989.aspx 陈小峰
Android开发指南-用户界面-绘制视图 http://blog.csdn.net/iefreer/archive/2009/09/27/4602532.aspx 陈小峰
Android开发指南-用户界面-通用布局对象 http://blog.csdn.net/iefreer/archive/2009/09/28/4606633.aspx 陈小峰
Android开发指南-用户界面-事件处理 http://blog.csdn.net/iefreer/archive/2009/09/23/4586351.aspx 陈小峰
Android Resource介绍和使用 http://www.cnblogs.com/tt_mc/archive/2010/05/31/1748140.html tt_mc
Android开发指南-用户界面-对话框 http://blog.163.com/guozioo@126/blog/static/640869472010613103136944 moon
Android开发指南中文版 http://bbs.ldci.com.cn/read.php?tid-171.html ztmm
posted @ 2010-08-18 13:58 王跃军 阅读(110) 评论(0) 编辑

android开发专题系列-一个简单的游戏的设计

标题概述地址作者
桌面组件的开发 http://www.moandroid.com/?p=1694
一个简单游戏的设计——逐步完善 http://www.moandroid.com/?p=1754
一个简单游戏的设计——初步设计 http://www.moandroid.com/?p=1740
一个简单游戏的设计——详细设计 http://www.moandroid.com/?p=1751
posted @ 2010-08-18 13:57 王跃军 阅读(38) 评论(0) 编辑
仅列出标题  下一页

统计