How do I implement the IPrintExt interface in VB?
The VB provides the Implements keyword that helps you to implement
an interface. The Implements keyword is used to signify that a class member implements a specific interface.
An Implements statement requires a comma-separated list of interface members to be implemented. Generally, only a single interface member is specified, but you can specify multiple members. The specification of an interface member consists of the interface name, which must be specified in an implements statement within the class, a period, and the name of the member function, property or event to be implemented. The name of a member that implements an interface member can use any legal identifier, and is not limited to the InterfaceName_MethodName convention used in earlier versions of Visual Basic.
The following steps will guide you to implement the IPrintExt interface.
Once that you followed the steps, you need to get something like follows ( in this case we have choose to have the Form class the object that implements the IPrintExt interface, of course you can choose another object or class) :
Implements IPrintExt
Private Sub Form_Load()
End Sub
Private Sub IPrintExt_DrawPage(ByVal Options As Variant, ByVal hDC As Long, ByVal Page As EXPRINTLib.IPage, pbContinue As Boolean)
End Sub
Private Property Get IPrintExt_PageCount(ByVal Options As Variant) As Long
End Property
Now, all that we need to do is to write the PageCount and DrawPage methods. Here's a simple code that fills the page's client area:
Implements IPrintExt
Private Declare Function GetClipBox Lib "gdi32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Sub IPrintExt_DrawPage(ByVal Options As Variant, ByVal hdc As Long, ByVal Page As EXPRINTLib.IPage, pbContinue As Boolean)
Dim r As RECT
GetClipBox hdc, r
FillRect hdc, r, 1
' Add your own drawing code
End Sub
Private Property Get IPrintExt_PageCount(ByVal Options As Variant) As Long
IPrintExt_PageCount = 2
End Property
Now, we have to check the code, by adding a new instance of exPrint component to the form and a new command button to the same form. The code will look like follows:
Implements IPrintExt
Private Declare Function GetClipBox Lib "gdi32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Sub IPrintExt_DrawPage(ByVal Options As Variant, ByVal hdc As Long, ByVal Page As EXPRINTLib.IPage, pbContinue As Boolean)
Dim r As RECT
GetClipBox hdc, r
FillRect hdc, r, 1
' Add your own drawing code
End Sub
Private Property Get IPrintExt_PageCount(ByVal Options As Variant) As Long
IPrintExt_PageCount = 2
End Property
Private Sub Command1_Click()
With Print1
Set .PrintExt = Me
.Preview
End With
End Sub