hdc 怎么用?高分啊
请问以下的hdc在vb中如何产生?
就是如何给printit函数传一个参数
那个过程大致相同,只是不能在控件中直接使用VB的Printer对象,否则VB会将你在控件中的打印输出处理为一个单独的页面,而是应该将Printer.hDc传给它,通过调用那些需要指定 HDC 的Windows API函数实现与容器的打印输出在一个页面上,比如我们可以这样定义这个控件的打印方法:
注释: PrintIt 方法将对应的条形码输出到缺省打印机
Public Sub PrintIt(ByVal PrintDC As Long, _
Optional ByVal intXPos As Integer = 0, _
Optional ByVal intYPos As Integer = 0, _
Optional ByVal intPrintHeight As Integer = 10)
既然不能使用Printer对象,那么画线和输出文字也不能使用Printer对象的Line和Print方法,在我们的程序中至少要申明以下三个Windows API函数:
‘ 移动画笔的位置
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
‘ 从画笔的当前位置到(x,y)画一条线
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
‘ 在(x,y)处输出一个字符串
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
‘ MoveToEx() 函数需要的参数
Private Type POINTAPI
xp As Long
yp As Long
End Type
Dim papi As POINTAPI
画线操作为(原来的Printer.Line函数):
MoveToEx PrintDC, x + k, y, papi
LineTo PrintDC, x + k, y + intHeight + 1
打印字符为(原来的Printer.Print函数):
TextOut PrintDC, x, y + intHeight, Mid(strBC, i + 1, 1), 1