本帖最后由 虫子樱桃 于 2017-2-24 23:04 编辑
https://www.autoitscript.com/for ... inting-from-autoit/
#include-once
#include <WinAPI.au3>
#include <FontConstants.au3>
#include <GDIPlus.au3>
Const $HORZRES = 8
Const $VERTRES = 10
Const $PS_SOLID = 0
Const $PS_DASH = 1
Const $PS_DOT = 2
Const $PS_DASHDOT = 3
Const $PS_DASHDOTDOT = 4
Const $PS_NULL = 5
Const $PS_INSIDEFRAME = 6
Const $AD_COUNTERCLOCKWISE = 1
Const $AD_CLOCKWISE = 2
;=========================================================
Global Const $tagDOCINFO = "int Size;" & _ ; int cbSize;
"ptr DocName;" & _ ; LPCTSTR lpszDocName;
"ptr Output;" & _ ; LPCTSTR lpszOutput;
"ptr Datatype;" & _ ; LPCTSTR lpszDatatype;
"dword Type" ; DWORD fwType;
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_CreateDC
; Description ...: Creates a device context (DC) for a device using the specified name.
; Syntax.........: _WinAPI_CreateDC($sDriver, $sDevice)
; Parameters ....: $sDriver - Specifies driver name, "winspool" for printing, "display" for screen
; $sDevice - Specifies device name
; Return values .: Success - handle to a DC for the specified device
; ====================================================================================================
Func _WinAPI_CreateDC($sDriver, $sDevice)
Local $aResult
$aResult = DllCall("GDI32.dll", "hwnd", "CreateDC", "str", $sDriver, "str", $sDevice, "long", 0, "long", 0)
Return $aResult[0]
EndFunc ;==>_WinAPI_CreateDC
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_StartDoc
; Description ...: Starts a print job
; Syntax.........: _WinAPI_StartDoc($hDC, $tDocInfo)
; Parameters ....: $hDC - Identifies the device contex
; $tDocInfo - $tagDOCINFO structure that specifies document info
; Return values .: Success - print job identifier for the document
; ====================================================================================================
Func _WinAPI_StartDoc($hDC, $tDocInfo)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "StartDoc", "hwnd", $hDC, "ptr", DllStructGetPtr($tDocInfo))
Return $aResult[0]
EndFunc ;==>_WinAPI_StartDoc
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_EndDoc
; Description ...: Ends a print job
; Syntax.........: _WinAPI_EndDoc($hDC)
; Parameters ....: $hDC - Identifies the device contex
; Return values .: Success - return value greater than zero
; ====================================================================================================
Func _WinAPI_EndDoc($hDC)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "EndDoc", "hwnd", $hDC)
Return $aResult[0]
EndFunc ;==>_WinAPI_EndDoc
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_StartPage
; Description ...: Prepares the printer driver to accept data
; Syntax.........: _WinAPI_StartPage($hDC)
; Parameters ....: $hDC - Identifies the device contex
; Return values .: Success - return value greater than zero
; ====================================================================================================
Func _WinAPI_StartPage($hDC)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "StartPage", "hwnd", $hDC)
Return $aResult[0]
EndFunc ;==>_WinAPI_StartPage
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_EndPage
; Description ...: Notifies the device that the application has finished writing to a page
; Syntax.........: _WinAPI_EndPage($hDC)
; Parameters ....: $hDC - Identifies the device contex
; Return values .: Success - return value greater than zero
; ====================================================================================================
Func _WinAPI_EndPage($hDC)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "EndPage", "hwnd", $hDC)
Return $aResult[0]
EndFunc ;==>_WinAPI_EndPage
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_TextOut
; Description ...: Writes a character string at the specified location, using the currently selected font, background color, and text color
; Syntax.........: _WinAPI_TextOut($hDC, $iXStart, $iYStart, $sString)
; Parameters ....: $hDC - Identifies the device contex
; $iXStart - x-coordinate of starting position
; $iYStart - y-coordinate of starting position
; $sString - character string
; Return values .: Success - return value is nonzero
; ====================================================================================================
Func _WinAPI_TextOut($hDC, $iXStart, $iYStart, $sString = "")
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "TextOut", "hwnd", $hDC, "long", $iXStart, "long", $iYStart, "str", $sString, "long", StringLen($sString))
Return $aResult[0]
EndFunc ;==>_WinAPI_TextOut
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_CreatePen
; Description ...: Creates a logical pen that has the specified style, width, and color
; Syntax.........: _WinAPI_CreatePen($iPenStyle, $iWidth, $iColor)
; Parameters ....: $iPenStyle - specifies pen style
; $PS_SOLID = 0
; $PS_DASH = 1
; $PS_DOT = 2
; $PS_DASHDOT = 3
; $PS_DASHDOTDOT = 4
; $PS_NULL = 5
; $PS_INSIDEFRAME = 6
; $iWidth - width of the pen
; $iColor - pen color stated in RGB
; Return values .: Success - Handle to logical pen
; ====================================================================================================
Func _WinAPI_CreatePen($iPenStyle = $PS_SOLID, $iWidth = 0, $iColor = 0x000000)
Local $aResult
$aResult = DllCall("GDI32.dll", "hwnd", "CreatePen", "int", $iPenStyle, "int", $iWidth, "dword", $iColor)
Return $aResult[0]
EndFunc ;==>_WinAPI_CreatePen
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_MoveToEx
; Description ...: Updates the current position to the specified point and optionally retrieves the previous position
; Syntax.........: _WinAPI_MoveToEx($hDC, $iX, $iY, $tPoint)
; Parameters ....: $hDC - Identifies the device contex
; $iX - x-coordinate of the new position, in logical units
; $iY - y-coordinate of the new position, in logical units
; $tPoint - $tagPOINT structure that receives the previous position
; Return values .: Success - non-zero value
; ====================================================================================================
Func _WinAPI_MoveToEx($hDC, $iX, $iY, ByRef $tPoint)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "MoveToEx", "long", $hDC, "int", $iX, "int", $iY, "ptr", DllStructGetPtr($tPoint))
Return $aResult[0]
EndFunc ;==>_WinAPI_MoveToEx
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_LineTo
; Description ...: Draws a line from the current position up to, but not including, the specified point
; Syntax.........: _WinAPI_LineTo($hDC, $iXEnd, $iYEnd)
; Parameters ....: $hDC - Identifies the device contex
; $iXEnd - x-coordinate, in logical units, of the endpoint of the line
; $iYEnd - y-coordinate, in logical units, of the endpoint of the line
; Return values .: Success - non-zero value
; ====================================================================================================
Func _WinAPI_LineTo($hDC, $iXEnd, $iYEnd)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "LineTo", "long", $hDC, "int", $iXEnd, "int", $iYEnd)
Return $aResult[0]
EndFunc ;==>_WinAPI_LineTo
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_SetArcDirection
; Description ...: Sets the drawing direction to be used for arc and rectangle functions
; Syntax.........: _WinAPI_SetArcDirection($hDC, $Direction)
; Parameters ....: $hDC - Identifies the device contex
; $Direction - Specifies the new arc direction
; $AD_COUNTERCLOCKWISE = 1
; $AD_CLOCKWISE = 2
; Return values .: Success - old arc direction
; ====================================================================================================
Func _WinAPI_SetArcDirection($hDC, $Direction)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "SetArcDirection", "long", $hDC, "int", $Direction)
Return $aResult[0]
EndFunc ;==>_WinAPI_SetArcDirection
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_ArcTo
; Description ...: Draws an elliptical arc
; Syntax.........: _WinAPI_ArcTo($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect, $iXRadial1, $iYRadial1, $iXRadial2, $iYRadial2)
; Parameters ....: $hDC - Identifies the device contex
; $iLeftRect - x-coord of rectangle's upper-left corner
; $iTopRect - y-coord of rectangle's upper-left corner
; $iRightRect - x-coord of rectangle's lower-right corner
; $iBottomRect - y-coord of rectangle's lower-right corner
; $iXRadial1 - x-coord of first radial ending point
; $iYRadial1 - y-coord of first radial ending point
; $iXRadial2 - x-coord of second radial ending point
; $iYRadial2 - y-coord of second radial ending point
; Return values .: Success - return value is nonzero
; ====================================================================================================
Func _WinAPI_ArcTo($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect, $iXRadial1, $iYRadial1, $iXRadial2, $iYRadial2)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "ArcTo", "long", $hDC, "int", $iLeftRect, "int", $iTopRect, "int", $iRightRect, "int", $iBottomRect, "int", $iXRadial1, "int", $iYRadial1, "int", $iXRadial2, "int", $iYRadial2)
Return $aResult[0]
EndFunc ;==>_WinAPI_ArcTo
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_Arc
; Description ...: Draws an elliptical arc
; Syntax.........: _WinAPI_Arc($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect, $iXStartArc, $iYStartArc, $iXEndArc, $iYEndArc)
; Parameters ....: $hDC - Identifies the device contex
; $iLeftRect - x-coord of rectangle's upper-left corner
; $iTopRect - y-coord of rectangle's upper-left corner
; $iRightRect - x-coord of rectangle's lower-right corner
; $iBottomRect - y-coord of rectangle's lower-right corner
; $iXStartArc - x-coord of first radial ending point
; $iYStartArc - y-coord of first radial ending point
; $iXEndArc - x-coord of second radial ending point
; $iYEndArc - y-coord of second radial ending point
; Return values .: Success - return value is nonzero
; ====================================================================================================
Func _WinAPI_Arc($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect, $iXStartArc, $iYStartArc, $iXEndArc, $iYEndArc)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "Arc", "long", $hDC, "int", $iLeftRect, "int", $iTopRect, "int", $iRightRect, "int", $iBottomRect, "int", $iXStartArc, "int", $iYStartArc, "int", $iXEndArc, "int", $iYEndArc)
Return $aResult[0]
EndFunc ;==>_WinAPI_Arc
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_Rectangle
; Description ...: Draws a rectangle
; Syntax.........: _WinAPI_Rectangle($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect)
; Parameters ....: $hDC - Identifies the device contex
; $iLeftRect - x-coord of rectangle's upper-left corner
; $iTopRect - y-coord of rectangle's upper-left corner
; $iRightRect - x-coord of rectangle's lower-right corner
; $iBottomRect - y-coord of rectangle's lower-right corner
; Return values .: Success - return value is nonzero
; ====================================================================================================
Func _WinAPI_Rectangle($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "Rectangle", "long", $hDC, "int", $iLeftRect, "int", $iTopRect, "int", $iRightRect, "int", $iBottomRect)
Return $aResult[0]
EndFunc ;==>_WinAPI_Rectangle
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_RoundRect
; Description ...: Draws a rectangle
; Syntax.........: _WinAPI_RoundRect($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect, $iWidth, $iHeight)
; Parameters ....: $hDC - Identifies the device contex
; $iLeftRect - x-coord of rectangle's upper-left corner
; $iTopRect - y-coord of rectangle's upper-left corner
; $iRightRect - x-coord of rectangle's lower-right corner
; $iBottomRect - y-coord of rectangle's lower-right corner
; $iWidth - width of ellipse
; $iHeight - height of ellipse
; Return values .: Success - return value is nonzero
; ====================================================================================================
Func _WinAPI_RoundRect($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect, $iWidth, $iHeight)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "RoundRect", "long", $hDC, "int", $iLeftRect, "int", $iTopRect, "int", $iRightRect, "int", $iBottomRect, "int", $iWidth, "int", $iHeight)
Return $aResult[0]
EndFunc ;==>_WinAPI_RoundRect
; #FUNCTION# ====================================================================================================
; Name...........: _WinAPI_Ellipse
; Description ...: Draws a ellipse
; Syntax.........: _WinAPI_Ellipse($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect)
; Parameters ....: $hDC - Identifies the device contex
; $iLeftRect - x-coord of rectangle's upper-left corner of rectangle
; $iTopRect - y-coord of rectangle's upper-left corner of rectangle
; $iRightRect - x-coord of rectangle's lower-right corner of rectangle
; $iBottomRect - y-coord of rectangle's lower-right corner of rectangle
; Return values .: Success - return value is nonzero
; ====================================================================================================
Func _WinAPI_Ellipse($hDC, $iLeftRect, $iTopRect, $iRightRect, $iBottomRect)
Local $aResult
$aResult = DllCall("GDI32.dll", "long", "Ellipse", "long", $hDC, "int", $iLeftRect, "int", $iTopRect, "int", $iRightRect, "int", $iBottomRect)
Return $aResult[0]
EndFunc ;==>_WinAPI_Ellipse
Example:
#include <PrintWinAPI.au3>
; Create a printer device context
$s_DefaultPrinter = _GetDefaultPrinter()
$s_PrinterName = InputBox("AutoIt API Printing", "Enter printer name", $s_DefaultPrinter)
If $s_PrinterName = "" Then Exit
$hPrintDc = _WinAPI_CreateDC("winspool", $s_PrinterName)
; get pixel and twips info
$PixelsPerInchY = _WinAPI_GetDeviceCaps($hPrintDc, $__WINAPCONSTANT_LOGPIXELSY) ; Get Pixels Per Inch Y
$TwipsPerPixelY = 1440 / $PixelsPerInchY
$PixelsPerInchX = _WinAPI_GetDeviceCaps($hPrintDc, $__WINAPCONSTANT_LOGPIXELSX) ; Get Pixels Per Inch X
$TwipsPerPixelX = 1440 / $PixelsPerInchX
; get page width and height
$PageWidth = _WinAPI_GetDeviceCaps($hPrintDc, $HORZRES) ; Get width, in millimeters, of the physical screen
$PageHeight = _WinAPI_GetDeviceCaps($hPrintDc, $VERTRES) ; Get height, in millimeters, of the physical screen.
; set docinfo
$s_DocName = "Printing from AutoIt with WinAPI"
$DocName = DllStructCreate("char DocName[" & StringLen($s_DocName & Chr(0)) & "]")
DllStructSetData($DocName, "DocName", $s_DocName & Chr(0)) ; Size of DOCINFO structure
$DOCINFO = DllStructCreate($tagDOCINFO) ; Structure for Print Document info
DllStructSetData($DOCINFO, "Size", 20) ; Size of DOCINFO structure
DllStructSetData($DOCINFO, "DocName", DllStructGetPtr($DocName)) ; Set name of print job (Optional)
; start new print doc
$result = _WinAPI_StartDoc($hPrintDc, $DOCINFO)
; start new page
$result = _WinAPI_StartPage($hPrintDc)
; create font
$DESIREDFONTSIZE = 16
$hFont = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 0, 0, $FW_NORMAL, True, True, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Verdona')
; set newfond, save old font
$hFontOld = _WinAPI_SelectObject($hPrintDc, $hFont)
; print centered test message
$s_TextOut = "This is a test..."
$OutSize = _WinAPI_GetTextExtentPoint32($hPrintDc, $s_TextOut)
; Compute the starting point for the text-output operation(centered)
$xLeft = (($PageWidth / 2) - (DllStructGetData($OutSize, "X") / 2))
; Compute the starting point for the text-output 2 lines down
$yTop = DllStructGetData($OutSize, "Y") * 2
; Send text
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; create font structure, rotated 180 degrees
$lf = DllStructCreate($tagLOGFONT)
$DESIREDFONTSIZE = 12
DllStructSetData($lf, "Escapement", 2700)
DllStructSetData($lf, "Height", (($DESIREDFONTSIZE * -20) / $TwipsPerPixelY))
DllStructSetData($lf, "Italic", False)
DllStructSetData($lf, "Underline", False)
DllStructSetData($lf, "FaceName", "Arial")
; set font
$hLF = _WinAPI_CreateFontIndirect($lf)
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; Send rotated text to printer, starting at location 1000, 1000
$xLeft = 1000
$yTop = 1000
$s_TextOut = "Testing...123"
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
DllStructSetData($lf, "Escapement", 2250)
$hLF = _WinAPI_CreateFontIndirect($lf)
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 1800, 0, $FW_NORMAL, False, False, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 1500, 0, $FW_NORMAL, False, False, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 1200, 0, $FW_NORMAL, False, False, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 900, 0, $FW_NORMAL, False, False, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; set textcolor, save last textcolor
$iColorOld = _WinAPI_SetTextColor($hPrintDc, 0xFF0000)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 600, 0, $FW_NORMAL, False, False, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; set textcolor, save last textcolor
$result = _WinAPI_SetTextColor($hPrintDc, 0x00FF00)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 300, 0, $FW_NORMAL, False, False, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; set textcolor, save last textcolor
$result = _WinAPI_SetTextColor($hPrintDc, 0x0000FF)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; update font
_WinAPI_DeleteObject($hLF)
$hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * -20) / $TwipsPerPixelY), 0, 0, 0, $FW_BOLD, False, False, False _
, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial')
$result = _WinAPI_SelectObject($hPrintDc, $hLF)
; set textcolor, save last textcolor
$result = _WinAPI_SetTextColor($hPrintDc, 0x0)
; Send rotated text to printer, starting at location 1000, 1000
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; set textcolor
$result = _WinAPI_SetTextColor($hPrintDc, 0x0000FF)
; restore original font
$result = _WinAPI_SelectObject($hPrintDc, $hFontOld)
; restore original color
$result = _WinAPI_SetTextColor($hPrintDc, $iColorOld)
; delete fonts
_WinAPI_DeleteObject($hFont)
_WinAPI_DeleteObject($hLF)
; create pens to draw with (PenStyle, Width, RGB-Color)
$hPen0 = _WinAPI_CreatePen($PS_SOLID, 0, 0x000000)
$hPen1 = _WinAPI_CreatePen($PS_DASH, 0, 0x000000)
$hPen2 = _WinAPI_CreatePen($PS_DOT, 0, 0x000000)
$hPen3 = _WinAPI_CreatePen($PS_DASHDOT, 0, 0x000000)
$hPen4 = _WinAPI_CreatePen($PS_DASHDOTDOT, 0, 0x000000)
$hPen5 = _WinAPI_CreatePen($PS_SOLID, 20, 0x000000)
$hPen6 = _WinAPI_CreatePen($PS_SOLID, 40, 0x000000)
$hPen7 = _WinAPI_CreatePen($PS_SOLID, 40, 0x0000FF)
$hPen8 = _WinAPI_CreatePen($PS_SOLID, 40, 0x00FF00)
$hPen9 = _WinAPI_CreatePen($PS_SOLID, 40, 0xFF0000)
; set starting point
$LastPoint = DllStructCreate($tagPOINT)
$result = _WinAPI_MoveToEx($hPrintDc, 1000, 2000, $LastPoint)
; select pen, save old pen
$hPenOld = _WinAPI_SelectObject($hPrintDc, $hPen2)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1100, 3000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen4)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1200, 2000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen3)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1300, 3000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen1)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1400, 2000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen0)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1500, 3000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen5)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1600, 2000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen6)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1700, 3000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen7)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1800, 2000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen8)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 1900, 3000)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen9)
; draw line
$result = _WinAPI_LineTo($hPrintDc, 2000, 2000)
; draw arch connected from current point
$result = _WinAPI_SetArcDirection($hPrintDc, $AD_CLOCKWISE)
$result = _WinAPI_ArcTo($hPrintDc, 2500, 2000, 3000, 2500, 2500, 2500, 3000, 2500)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen4)
; draw arch
$result = _WinAPI_Arc($hPrintDc, 2500, 1000, 3500, 1500, 0, 0, 0, 0)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen5)
; create brush
$hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
; select brush
$hBrushOld = _WinAPI_SelectObject($hPrintDc, $hBrush)
; draw rectangles
$result = _WinAPI_Rectangle($hPrintDc, 3500, 2000, 4500, 2500)
$result = _WinAPI_RoundRect($hPrintDc, 3500, 2600, 4500, 3100, 200, 200)
; draw circle
$result = _WinAPI_Ellipse($hPrintDc, 3300, 1800, 3700, 2200)
; restore original brush
$result = _WinAPI_SelectObject($hPrintDc, $hBrushOld)
; select pen
$result = _WinAPI_SelectObject($hPrintDc, $hPen2)
$result = _WinAPI_Arc($hPrintDc, 3300, 1900, 3700, 2300, 0, 0, 0, 0)
; End the page
$result = _WinAPI_EndPage($hPrintDc)
; start new page
$result = _WinAPI_StartPage($hPrintDc)
; print centered test message
$s_TextOut = "This is page 2"
$OutSize = _WinAPI_GetTextExtentPoint32($hPrintDc, $s_TextOut)
; Compute the starting point for the text-output operation(centered)
$xLeft = (($PageWidth / 2) - (DllStructGetData($OutSize, "X") / 2))
; Compute the starting point for the text-output 2 lines down
$yTop = DllStructGetData($OutSize, "Y") * 2
; Send text
$result = _WinAPI_TextOut($hPrintDc, $xLeft, $yTop, $s_TextOut)
; delete pens
_WinAPI_DeleteObject($hPen0)
_WinAPI_DeleteObject($hPen1)
_WinAPI_DeleteObject($hPen2)
_WinAPI_DeleteObject($hPen3)
_WinAPI_DeleteObject($hPen4)
_WinAPI_DeleteObject($hPen5)
_WinAPI_DeleteObject($hPen6)
_WinAPI_DeleteObject($hPen7)
_WinAPI_DeleteObject($hPen8)
_WinAPI_DeleteObject($hPen9)
; delete brush
_WinAPI_DeleteObject($hBrush)
; restore original pen
$result = _WinAPI_SelectObject($hPrintDc, $hPenOld)
; restore original brush
$result = _WinAPI_SelectObject($hPrintDc, $hBrushOld)
; End the page
$result = _WinAPI_EndPage($hPrintDc)
; End the print job
$result = _WinAPI_EndDoc($hPrintDc)
; Delete the printer device context
_WinAPI_DeleteDC($hPrintDc)
Func _GetDefaultPrinter()
$s_TempDeviceID = ""
If @OSType = "WIN32_NT" Then
Local $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
If Not @error = 0 Then
; error
Else
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
If $s_TempDeviceID = "" Then $s_TempDeviceID = $objItem.DeviceID
If $objItem.Default Then $s_TempDeviceID = $objItem.DeviceID
Next
Else
;Msgbox(262192,"WMI Output","No WMI Objects Found for class: " & "Win32_Printer" )
EndIf
EndIf
EndIf
Return $s_TempDeviceID
EndFunc ;==>_GetDefaultPrinter
或者
RunWait('Rundll32.exe "' & @SystemDir & '\mshtml.dll",PrintHTML "' & $tempFile & '"', @SystemDir) ;replace $tempFile with the file which should be printed
要自动 可以看看这个https://www.autoitscript.com/for ... photo-using-autoit/ |