Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/01/2014 in all areas

  1. GRS

    Printing from AutoIt

    I am somewhat new to AutoIt, but have been trying to create a UDF for printing that does not require a DLL external to the OS. I have not been able to add the ability to print images or to change the paper orientation. I have only tested this on WinXP with AutoIt v3.2.12.0. Could someone help add these features(printing images & setting paper orientation)? PrintWinAPI.au3: #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_EllipseSample output: Example.au3 #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
    1 point
  2. A simple script for get differences between 2 "Text" files. The different parts are highlighted and a double click on a line of listviews located to the bottom of the Gui permit to access to the line in the Text. Its defects : Using _ArraySearch, it's a bit slow and hungry on cpu usage. Previous downloads : 69 source and executable are available in the Download Section Hope it can help !
    1 point
  3. Hum it's a little maths problem #include <Array.au3> $sData = BinaryToString(InetRead("http://steamcommunity.com/market/")) $aItems = StringRegExp($sData, '(?sU)row_link.*href="(.*)".*&#36;(\d+\.\d{2}).*item_name".*>(.*)<\/span>.*<\/a>', 3) ;_ArrayDisplay($aItems) Local $res[UBound($aItems)/3][3] For $i = 0 to UBound($aItems)-1 $n = Mod($i, 3) $res[($i-$n-1)/3+1][$n] = $aItems[$i] Next _ArrayDisplay($res)
    1 point
  4. Not sure about the links you want to get Please try this #include <Array.au3> Local $data = BinaryToString(InetRead("http://steamcommunity.com/market/search?q=") ) $var = "0.03" $res = StringRegExp($data, '(?s)listing_row_link"\h*href="(.*?)".*?\Q' & $var & '\E\h*USD', 3) _ArrayDisplay($res)
    1 point
  5. 4b0082, As I mentioned when we exchanged PMs, I see no problem with what you are trying to do - the question is simply one of interaction with the content of a website and has nothing to do with gaming per se. So if anyone wants to help, please feel free to do so. M23
    1 point
  6. Versatile way of Melba's $var = "Item: 33" $aExtract = StringRegExp($sString, '(?s)<div>.*href="(.*)".*\Q' & $var & '\E.*<\/div>', 3)
    1 point
  7. 4b0082, Regular Expressions are a very clever way of extracting small sections of data from larger sets when there is a suitable pattern to identify the required section. In this case you could do something like this: #include <MsgBoxConstants.au3> $sString = "<div>" & @CRLF & _ '. . . a bunch of code . . .' & @CRLF & _ '<a href="http://somewebsite.com/123-some-random-numbers-and-text">Link Name</a>' & @CRLF & _ '. . . a bunch of code . . .' & @CRLF & _ 'Item: 33 ;this is the line of code I was searching for in my string.' & @CRLF & _ '</div>' $aExtract = StringRegExp($sString, '(?s)<div>.*href="(.*)".*Item:\s\d+.*<\/div>', 3) MsgBox($MB_SYSTEMMODAL, "Extract", $aExtract[0]) which gets you the link. The RegEx works like this: (?s) - Ignore line endings <div> - Look for '<div>'... .* - and then any number of characters until... href=" - we find 'href="'. (.*) - Now capture the characters until... " - the next double-quote. .* - Then there will be other characters until... Item:\s\d+ - we find 'Item: ' followed by one or more digits (you said this was important). .* - Then there will be other characters until... <\/div> - we find '</div>' The "3" means put all matches into an array As you can see RegExes are not for the faint-hearted - I rate them as one of the hardest things I have ever tried to learn and they still make my brain hurt. But they can be incredibly powerful and are well worth the effort to get at least a working knowledge of how they are constructed - the real gurus around here can do magic with them. I always recommend this site as a good place to get started. But if you are a novice programmer I would suggest you concentrate on the basics for a while yet. M23
    1 point
  8. I see you still haven't had any suggstions here, I did some tinkering and here is what I came up with: #include "JSON.au3" #include "array.au3" #NoTrayIcon $s = ' [{"z1":"vanueh","on":true}]' $s2 = '{"error":"Error MSG"}' Parse($s) Parse($s2) Exit Func Parse($sTemp) If StringInStr($sTemp, ",") Then $sTemp = StringRegExpReplace($sTemp, "[\[\]{}]", "") $sBreak = StringSplit($sTemp, ",") For $a = 1 To $sBreak[0] $t = _JSONDecode("{" & $sBreak[$a] & "}") _ArrayDisplay($t, "multi " & $a & " of " & $sBreak[0]) Next Else $t = _JSONDecode($sTemp) _ArrayDisplay($t, "single") EndIf EndFunc ;==>Parse It seemed to me the easiest way to deal with the issue. When the result is nested, strip all brackets, split by comma, then add brackets back to each element of the resulting array. Hopefully this offers you some way to move forward with your script. Ian
    1 point
  9. Zedna

    Remove Script Paused

    Partial solution: Opt("TrayAutoPause",0) For removing use: Opt("TrayMenuMode",1) ; no default menu (Paused/Exit) If you want your own tray menu items then use TrayCreateItem() TraySetState() TraySetClick() and in main loop use TrayGetMsg() You can look here at my Frame example using it '?do=embed' frameborder='0' data-embedContent>>
    1 point
×
×
  • Create New...