Mengaktifkan Fungsi Tombol Escape dengan Perintah API

Tuesday, May 31, 2011 | 11:27 AM|

API Explanation
The Escape function allows applications to access capabilities of a particular device not directly available through GDI. Escape calls made by an application are translated and sent to the driver

Parameter Information
Declare Function Escape Lib "gdi32" Alias "Escape" (ByVal hdc As Long, ByVal nEscape As Long, ByVal nCount As Long, ByVal lpInData As String, lpOutData As Any) As Long


· hdc
Identifies the device context.

· nEscape
Specifies the escape function to be performed. This parameter must be one of the predefined escape values. Use the ExtEscape function if your application defines a private escape value.

· cbInput
Specifies the number of bytes of data pointed to by the lpvInData parameter.

· lpvInData
Points to the input structure required for the specified escape.

· lpvOutData
Points to the structure that receives output from this escape. This parameter should be NULL if no data is returned.

If the function succeeds, the return value is greater than zero, except with the QUERYESCSUPPORT printer escape, which checks for implementation only. If the escape is not implemented, the return value is zero.

If the function fails, the return value is an error. To get extended error information, call GetLastError.


Kode dalam Form :


Const NEWFRAME = 1
Private Declare Function Escape Lib "gdi32" (ByVal hdc As Long, ByVal nEscape As Long, ByVal nCount As _ Long, ByVal lpInData As String, lpOutData As Any) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal _ nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc _ As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Dim hMemoryDC As Long

Private Sub Command1_Click()
'API uses pixels
Picture1.ScaleMode = vbPixels
Printer.ScaleMode = vbPixels
'Take paper
Printer.Print ""

'Create a compatible device context
hMemoryDC = CreateCompatibleDC(Picture1.hdc)
'Select Picture1's picture into our new device context
hOldBitMap = SelectObject(hMemoryDC, Picture1.Picture)

'Stretch our picture to the height and width of the paper
StretchBlt Printer.hdc, 0, 0, Printer.ScaleWidth, Printer.ScaleHeight, hMemoryDC, 0, 0, _
Picture1.ScaleWidth, Picture1.ScaleHeight, vbSrcCopy

'Select the original bitmap into our DC
hOldBitMap = SelectObject(hMemoryDC, hOldBitMap)
'Delete our memorydc
DeleteDC hMemoryDC

'Access our printer device
Escape Printer.hdc, NEWFRAME, 0, 0&, 0&

'End of document
Printer.EndDoc
End Sub

0 comments: