
eltorro
-
Posts
588 -
Joined
-
Last visited
Reputation Activity
-
eltorro got a reaction from senatin in 'how to run multiple _Timer_SetTimer with a wokring script'.
Without seeing your script, I can only help you by showing you how you can use multiple timers by callbacks or WM_TIMER message. Maybe you can adapt this to your needs.
#Include <Timers.au3> Global Const $WM_TIMER = 0x0113 Global $hTimer1 Global $hTimer2 Exit(Main()) Func Main() Local $iCount Local $hTimerGUI = GuiCreate("timer") ;separate callbacks $hTimer1= _Timer_SetTimer($hTimerGUI, 1000, "_Timer1_CallBack") $hTimer2= _Timer_SetTimer($hTimerGUI, 1500, "_Timer2_CallBack") While 1 sleep(10) $iCount += 1 If $iCount = 500 Then ExitLoop WEnd _Timer_KillAllTimers($hTimerGUI) ConsoleWrite(@LF) ;combined callbacks $hTimer1= _Timer_SetTimer($hTimerGUI, 1000, "_Timer3_CallBack") $hTimer2= _Timer_SetTimer($hTimerGUI, 1500, "_Timer3_CallBack") $iCount = 0 While 1 sleep(10) $iCount += 1 If $iCount = 500 Then ExitLoop WEnd _Timer_KillAllTimers($hTimerGUI) ConsoleWrite(@LF) ;combined callbacks $WM_TIMER GUIRegisterMsg($WM_TIMER,"_WM_TIMER_Message") $hTimer1= _Timer_SetTimer($hTimerGUI, 1000) $hTimer2= _Timer_SetTimer($hTimerGUI, 1500) $iCount = 0 While 1 sleep(10) $iCount += 1 If $iCount = 500 Then ExitLoop WEnd _Timer_KillAllTimers($hTimerGUI) GUIRegisterMsg($WM_TIMER,"") GUIDelete($hTimerGUI) Return 1 EndFunc ;separate callback for timer 1 Func _Timer1_Callback($hWnd, $Msg, $iIDTimer, $dwTime) ConsoleWrite("Timer1 executed."&@LF) EndFunc ;separate callback for timer 2 Func _Timer2_Callback($hWnd, $Msg, $iIDTimer, $dwTime) ConsoleWrite("Timer2 executed."&@LF) EndFunc ;combined callback ;check timer id Func _Timer3_Callback($hWnd, $Msg, $iIDTimer, $dwTime) Switch $iIDTimer Case $hTimer1 ConsoleWrite("[Timer1] executed."&@LF) Case $hTimer2 ConsoleWrite("[Timer2] executed."&@LF) EndSwitch EndFunc ;Combined callback with WM_TIMER message Func _WM_TIMER_Message($hWnd, $Msg, $iIDTimer, $dwTime) Switch $iIDTimer Case $hTimer1 ConsoleWrite("{Timer1} executed."&@LF) Case $hTimer2 ConsoleWrite("{Timer2} executed."&@LF) EndSwitch EndFunc -
eltorro got a reaction from mLipok in Print Preview
Most print preview solutions use the MFC Doc/View architecture which limits it usefulness outside of c++. I found an article where a Delphi programmer used Enhanced Meta Files wrapped in a custom header and packaged together to create a print preview control. After a little more searching, It looks like using EMFs is a solution that would work.
Some people suggest to create the document in Word or HTML and use Word or a browser to view it. Indeed, I have rendered documents to HTML and used the IE UDF to display the contents and/or print them. Not quite as ideal as one would like.
Using GRS's printwin.au3 as a start, I came up with a print preview solution which others may be able to expand upon.
The zip file contains the udf files necessary.
Screenshot:
Here is an example.
#include <WinAPI.au3> #include "WinPrint.au3" #include "Preview.au3" #include "PrintDialog.au3" Global $PixelsPerInchY, $TwipsPerPixelY, $PixelsPerInchX, $TwipsPerPixelX, $PageWidth, $PageHeight ;1 print to default printer ;2 print preview ;3 use the second parameter as the device Context ;anything else, show printer dialog and get device context. _Print(2, 0) _ShowPreview() Func _Print($iMode = 0, $hPrintDC = 0) Local $s_DefaultPrinter, $s_DocName,$DocName, $DOCINFO, $result Switch $iMode Case 1, 2 ;print to default printer $s_DefaultPrinter = _WinSpool_GetDefaultPrinter() If $s_DefaultPrinter = "" Then Return SetError(1, 0, 0) $hPrintDC = _WinAPI_CreateDC("winspool", $s_DefaultPrinter) If $hPrintDC = 0 Then Return SetError(1, 0, 0) Case 3 ;use dc provided If $hPrintDC = 0 Then Return SetError(1, 0, 0) Case Else ;Show printer dialog Local $tPD $hPrintDC = _ShowPrintDialog($tPD) $tPD = 0 If $hPrintDC = 0 Then Return SetError(1, 0, 0) EndSwitch ; get pixel and twips info $PixelsPerInchY = _WinAPI_GetDeviceCaps($hPrintDC, $__WINAPICONSTANT_LOGPIXELSY) ; Get Pixels Per Inch Y $TwipsPerPixelY = 1440 / $PixelsPerInchY $PixelsPerInchX = _WinAPI_GetDeviceCaps($hPrintDC, $__WINAPICONSTANT_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. Local $hBrush, $hBrushOld, $hLF, $hFont, $hOldFont, $DESIREDFONTSIZE, $s_TextOut Local $OutSize, $xLeft, $yTop, $tLF, $iColorOld, $LastPoint Local $hPen0,$hPen1,$hPen2,$hPen3,$hPen4,$hPen5,$hPen6,$hPen7,$hPen8,$hPen9,$hPenOld ; 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 ;$DocOutput = DllStructCreate("char DocOutput[" & StringLen($s_DocOutput & chr(0)) & "]") ;DllStructSetData($DocOutput, "DocOutput", $s_DocOutput) $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) ;DllStructSetData($DOCINFO, "Output", DllStructGetPtr($DocOutput)) ; Set name of print job (Optional) If $iMode = 2 Then $result += _MetaFile_StartDoc($hPrintDC, $DOCINFO) $result += _MetaFile_StartPage($hPrintDC) Else $result += _WinAPI_StartDoc($hPrintDC, $DOCINFO) ; start new page $result += _WinAPI_StartPage($hPrintDC) EndIf ; create font $DESIREDFONTSIZE = 18 $hFont = _WinAPI_CreateFont((($DESIREDFONTSIZE * - 20) / $TwipsPerPixelY), 0, 0, 0, $FW_NORMAL, False, False, False _ , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Times New Roman') ; set newfont, save old font $hOldFont = _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 $xLeft = Inch2PixelX(0.781250) $yTop = Inch2PixelY(0.260417) $result += _WinAPI_TextOut($hPrintDC, $xLeft, $yTop, $s_TextOut) ; create font structure, rotated 180 degrees $tLF = DllStructCreate($tagLOGFONT) $DESIREDFONTSIZE = 12 DllStructSetData($tLF, "Escapement", 2700) DllStructSetData($tLF, "Height", (($DESIREDFONTSIZE * - 20) / $TwipsPerPixelY)) DllStructSetData($tLF, "Italic", False) DllStructSetData($tLF, "Underline", False) DllStructSetData($tLF, "FaceName", "Arial") ; set font $hLF = _WinAPI_CreateFontIndirect($tLF) $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($tLF) DllStructSetData($tLF, "Escapement", 2250) $hLF = _WinAPI_CreateFontIndirect($tLF) $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, $hOldFont) ; restore original color $result += _WinAPI_SetTextColor($hPrintDC, $iColorOld) ; delete fonts _WinAPI_SelectObject($hPrintDC, $hOldFont) _WinAPI_DeleteObject($hFont) _WinAPI_DeleteObject($hLF) $tLF = 0 ; 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) ;============================================================================== ; If $iMode = 2 Then ; End the page $result += _MetaFile_EndPage($hPrintDC) ; start new page $result += _MetaFile_StartPage($hPrintDC) ;Each page is a new dc. Else ; End the page $result += _WinAPI_EndPage($hPrintDC) ; start new page $result += _WinAPI_StartPage($hPrintDC) EndIf _WinAPI_DeleteObject($hLF) $hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * - 20) / $TwipsPerPixelY), 0, 0, 0, $FW_NORMAL, False, False, False _ , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial') $result += _WinAPI_SelectObject($hPrintDC, $hLF) ; 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_SetTextColor($hPrintDC, 0x0000FF) $result += _WinAPI_TextOut($hPrintDC, $xLeft, $yTop, $s_TextOut) ; restore original font $result += _WinAPI_SelectObject($hPrintDC, $hOldFont) ; restore original color $result += _WinAPI_SetTextColor($hPrintDC, $iColorOld) ; 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) ; delete font _WinAPI_DeleteObject($hLF) ; restore original font $result += _WinAPI_SelectObject($hPrintDC, $hOldFont) ; restore original pen $result += _WinAPI_SelectObject($hPrintDC, $hPenOld) ; restore original brush $result += _WinAPI_SelectObject($hPrintDC, $hBrushOld) If $iMode = 2 Then ; End the page $result += _MetaFile_EndPage($hPrintDC) ; End the print job $result += _MetaFile_EndDoc($hPrintDC) Else ; End the page $result += _WinAPI_EndPage($hPrintDC) ; End the print job $result += _WinAPI_EndDoc($hPrintDC) ; Delete the printer device context EndIf _WinAPI_ReleaseDC(0, $hPrintDC) _WinAPI_DeleteDC($hPrintDC) Return $result EndFunc ;==>_Print Func Inch2PixelX($iInchesx) Return Int($iInchesx * $PixelsPerInchX) EndFunc ;==>Inch2PixelX Func Inch2PixelY($iInchesy) Return Int($iInchesy * $PixelsPerInchY) EndFunc ;==>Inch2PixelY
Some thing that needs to be noted are:
Each "page" is a new device context. This is significant in that GDI objects (like fonts and brushes) loaded to the dc are lost with the dc then page ends. I could not find a way to clear the meta file and reuse to device context. The page size is fixed at letter size portrait. Each page is a separate emf file.
The meta files are dumped into a temp folder with an ini file. The preview window reads the ini file for the title and page count then loads the preview. When the preview dialog is closed, the meta files and ini are erased.
The zip file is here.
The zip contains:
WinPrint.au3 - GRS's printwin script modified. PrintDialog.au3 -- Show the printer common dialog. MetaFile.au3 -- Windows enhanced meta file api calls in AutoIt3 Preview.au3 -- Shows the print preview window. PreviewTest.au3 -- A little demonstration. A basic overview for print preview:
Include Preview.au3 Get a handle to a printer device context Setup the DOCINFO structure Use _MetaFIle_StartDoc in place of _WinAPI_StartDoc Use _MetaFile_StartPage in place of _WinAPI_StartPage Draw on the device context use gdi functions. Use _MetaFile_EndPage in place of _WinAPI_EndPage Repeat from _MetaFile_StartPage as necessary. Use _MetaFile_EndDoc in place of _WinAPI_EndDoc Call _ShowPreview()
Please look at the example to see how it works.
::eltorro
edit: changed topic description, added link to top, added screenshot link.
-
eltorro got a reaction from Earthshine in Print Preview
Most print preview solutions use the MFC Doc/View architecture which limits it usefulness outside of c++. I found an article where a Delphi programmer used Enhanced Meta Files wrapped in a custom header and packaged together to create a print preview control. After a little more searching, It looks like using EMFs is a solution that would work.
Some people suggest to create the document in Word or HTML and use Word or a browser to view it. Indeed, I have rendered documents to HTML and used the IE UDF to display the contents and/or print them. Not quite as ideal as one would like.
Using GRS's printwin.au3 as a start, I came up with a print preview solution which others may be able to expand upon.
The zip file contains the udf files necessary.
Screenshot:
Here is an example.
#include <WinAPI.au3> #include "WinPrint.au3" #include "Preview.au3" #include "PrintDialog.au3" Global $PixelsPerInchY, $TwipsPerPixelY, $PixelsPerInchX, $TwipsPerPixelX, $PageWidth, $PageHeight ;1 print to default printer ;2 print preview ;3 use the second parameter as the device Context ;anything else, show printer dialog and get device context. _Print(2, 0) _ShowPreview() Func _Print($iMode = 0, $hPrintDC = 0) Local $s_DefaultPrinter, $s_DocName,$DocName, $DOCINFO, $result Switch $iMode Case 1, 2 ;print to default printer $s_DefaultPrinter = _WinSpool_GetDefaultPrinter() If $s_DefaultPrinter = "" Then Return SetError(1, 0, 0) $hPrintDC = _WinAPI_CreateDC("winspool", $s_DefaultPrinter) If $hPrintDC = 0 Then Return SetError(1, 0, 0) Case 3 ;use dc provided If $hPrintDC = 0 Then Return SetError(1, 0, 0) Case Else ;Show printer dialog Local $tPD $hPrintDC = _ShowPrintDialog($tPD) $tPD = 0 If $hPrintDC = 0 Then Return SetError(1, 0, 0) EndSwitch ; get pixel and twips info $PixelsPerInchY = _WinAPI_GetDeviceCaps($hPrintDC, $__WINAPICONSTANT_LOGPIXELSY) ; Get Pixels Per Inch Y $TwipsPerPixelY = 1440 / $PixelsPerInchY $PixelsPerInchX = _WinAPI_GetDeviceCaps($hPrintDC, $__WINAPICONSTANT_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. Local $hBrush, $hBrushOld, $hLF, $hFont, $hOldFont, $DESIREDFONTSIZE, $s_TextOut Local $OutSize, $xLeft, $yTop, $tLF, $iColorOld, $LastPoint Local $hPen0,$hPen1,$hPen2,$hPen3,$hPen4,$hPen5,$hPen6,$hPen7,$hPen8,$hPen9,$hPenOld ; 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 ;$DocOutput = DllStructCreate("char DocOutput[" & StringLen($s_DocOutput & chr(0)) & "]") ;DllStructSetData($DocOutput, "DocOutput", $s_DocOutput) $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) ;DllStructSetData($DOCINFO, "Output", DllStructGetPtr($DocOutput)) ; Set name of print job (Optional) If $iMode = 2 Then $result += _MetaFile_StartDoc($hPrintDC, $DOCINFO) $result += _MetaFile_StartPage($hPrintDC) Else $result += _WinAPI_StartDoc($hPrintDC, $DOCINFO) ; start new page $result += _WinAPI_StartPage($hPrintDC) EndIf ; create font $DESIREDFONTSIZE = 18 $hFont = _WinAPI_CreateFont((($DESIREDFONTSIZE * - 20) / $TwipsPerPixelY), 0, 0, 0, $FW_NORMAL, False, False, False _ , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Times New Roman') ; set newfont, save old font $hOldFont = _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 $xLeft = Inch2PixelX(0.781250) $yTop = Inch2PixelY(0.260417) $result += _WinAPI_TextOut($hPrintDC, $xLeft, $yTop, $s_TextOut) ; create font structure, rotated 180 degrees $tLF = DllStructCreate($tagLOGFONT) $DESIREDFONTSIZE = 12 DllStructSetData($tLF, "Escapement", 2700) DllStructSetData($tLF, "Height", (($DESIREDFONTSIZE * - 20) / $TwipsPerPixelY)) DllStructSetData($tLF, "Italic", False) DllStructSetData($tLF, "Underline", False) DllStructSetData($tLF, "FaceName", "Arial") ; set font $hLF = _WinAPI_CreateFontIndirect($tLF) $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($tLF) DllStructSetData($tLF, "Escapement", 2250) $hLF = _WinAPI_CreateFontIndirect($tLF) $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, $hOldFont) ; restore original color $result += _WinAPI_SetTextColor($hPrintDC, $iColorOld) ; delete fonts _WinAPI_SelectObject($hPrintDC, $hOldFont) _WinAPI_DeleteObject($hFont) _WinAPI_DeleteObject($hLF) $tLF = 0 ; 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) ;============================================================================== ; If $iMode = 2 Then ; End the page $result += _MetaFile_EndPage($hPrintDC) ; start new page $result += _MetaFile_StartPage($hPrintDC) ;Each page is a new dc. Else ; End the page $result += _WinAPI_EndPage($hPrintDC) ; start new page $result += _WinAPI_StartPage($hPrintDC) EndIf _WinAPI_DeleteObject($hLF) $hLF = _WinAPI_CreateFont((($DESIREDFONTSIZE * - 20) / $TwipsPerPixelY), 0, 0, 0, $FW_NORMAL, False, False, False _ , $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Arial') $result += _WinAPI_SelectObject($hPrintDC, $hLF) ; 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_SetTextColor($hPrintDC, 0x0000FF) $result += _WinAPI_TextOut($hPrintDC, $xLeft, $yTop, $s_TextOut) ; restore original font $result += _WinAPI_SelectObject($hPrintDC, $hOldFont) ; restore original color $result += _WinAPI_SetTextColor($hPrintDC, $iColorOld) ; 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) ; delete font _WinAPI_DeleteObject($hLF) ; restore original font $result += _WinAPI_SelectObject($hPrintDC, $hOldFont) ; restore original pen $result += _WinAPI_SelectObject($hPrintDC, $hPenOld) ; restore original brush $result += _WinAPI_SelectObject($hPrintDC, $hBrushOld) If $iMode = 2 Then ; End the page $result += _MetaFile_EndPage($hPrintDC) ; End the print job $result += _MetaFile_EndDoc($hPrintDC) Else ; End the page $result += _WinAPI_EndPage($hPrintDC) ; End the print job $result += _WinAPI_EndDoc($hPrintDC) ; Delete the printer device context EndIf _WinAPI_ReleaseDC(0, $hPrintDC) _WinAPI_DeleteDC($hPrintDC) Return $result EndFunc ;==>_Print Func Inch2PixelX($iInchesx) Return Int($iInchesx * $PixelsPerInchX) EndFunc ;==>Inch2PixelX Func Inch2PixelY($iInchesy) Return Int($iInchesy * $PixelsPerInchY) EndFunc ;==>Inch2PixelY
Some thing that needs to be noted are:
Each "page" is a new device context. This is significant in that GDI objects (like fonts and brushes) loaded to the dc are lost with the dc then page ends. I could not find a way to clear the meta file and reuse to device context. The page size is fixed at letter size portrait. Each page is a separate emf file.
The meta files are dumped into a temp folder with an ini file. The preview window reads the ini file for the title and page count then loads the preview. When the preview dialog is closed, the meta files and ini are erased.
The zip file is here.
The zip contains:
WinPrint.au3 - GRS's printwin script modified. PrintDialog.au3 -- Show the printer common dialog. MetaFile.au3 -- Windows enhanced meta file api calls in AutoIt3 Preview.au3 -- Shows the print preview window. PreviewTest.au3 -- A little demonstration. A basic overview for print preview:
Include Preview.au3 Get a handle to a printer device context Setup the DOCINFO structure Use _MetaFIle_StartDoc in place of _WinAPI_StartDoc Use _MetaFile_StartPage in place of _WinAPI_StartPage Draw on the device context use gdi functions. Use _MetaFile_EndPage in place of _WinAPI_EndPage Repeat from _MetaFile_StartPage as necessary. Use _MetaFile_EndDoc in place of _WinAPI_EndDoc Call _ShowPreview()
Please look at the example to see how it works.
::eltorro
edit: changed topic description, added link to top, added screenshot link.
-
eltorro got a reaction from strongy in ToolTip and Statusbar text change when mouse cursor over a dropdown menu
You can try the following code. I assume your running beta.
;Menu Help ;Stephen Podhajecki [eltorro] gehossafats@netmdc.com #Include <GuiConstants.au3> #include <Array.au3> Global $USE_TOOLTIP = TRUE Global $DEBUG = True Local $aCtrlArray[1], $aCtrlMsgArray[1],$ControlID, $Global_I = 0, $__ControlID, $HoverActive = 0, $Temp_Found = 0, $szTemp_Array[2] Global $defaultstatus = "Ready" Global $status Global $Timer Global Const $WM_MENUSELECT = 0x011F GUIRegisterMsg($WM_MENUSELECT,"MouseOverMenu") $Form1 = GUICreate('TITLE', 400, 285) $filemenu = GUICtrlCreateMenu("&File") _AddCtrl($filemenu,"FileMenu") $file1 = GUICtrlCreateMenuitem("Label 1", $filemenu) _AddCtrl($file1,"This is Label1") $file2 = GUICtrlCreateMenuitem("Label 2", $filemenu) _AddCtrl($file2,"Label 2 at Your Service") $file3 = GUICtrlCreateMenuitem("Label3", $filemenu) _AddCtrl($file3,"Pleased to meet you from Label 3") $file4 = GUICtrlCreateMenuitem("Label 4", $filemenu) _AddCtrl($file4,"Well, you get the picture, Label 4") $statuslabel = GUICtrlCreateLabel($defaultstatus, 0, 250, 300, 16, BitOR($SS_SIMPLE, $SS_SUNKEN)) $statuslabel2 =GUICtrlCreateLabel($defaultstatus, 300, 250, 100, 16, BitOR($SS_SIMPLE, $SS_SUNKEN)) $file11= GUICtrlCreateMenuitem("Label 11",$file1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $file1 MsgBox(266288,"Menu Clicked","Label1 clicked.") EndSelect ;~ $t_Sec = int( TimerDiff($Timer)/1000) ;~ ;if $t_Sec = int($t_Sec) then ;~ GuiCtrlSetData($statuslabel2,$t_Sec) ;~ ;EndIf ;~ ;~ if TimerDiff($Timer) >3000 Then ToolTip("") WEnd Exit Func MouseOverMenu($hWndGUI, $MsgID, $WParam, $LParam) if $DEBUG then ConsoleWrite( "hWndGui= "&$hWndGUI& @LF &"MsgId= "&$MsgID& @LF &"WParam= " &$WParam& @LF &"$LParam= "&$LParam& @LF) Local $id = BitAnd($WParam, 0xFFFF) if $DEBUG then ConsoleWrite("ID= "& $id & @LF) for $x= 0 to UBound($aCtrlArray)-1 if $id = ($aCtrlArray[$x]) then GuiCtrlSetData($statuslabel , $aCtrlMsgArray[$x]) if $USE_TOOLTIP then ToolTip($aCtrlMsgArray[$x]) ;~ $Timer = TimerInit() ExitLoop EndIf Next Return $GUI_RUNDEFMSG EndFunc Func _AddCtrl($ControlID,$ControlMsg) _ArrayAdd($aCtrlArray,$ControlID) _ArrayAdd($aCtrlMsgArray,$ControlMsg) EndFunc
Regards
-
eltorro got a reaction from IgImAx in Finally Zip support
Until there is a plugin we can use this COM dll.
;zip functions using x-zip.dll ;Get the dll here ;http://xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7 ;quick and dirty example of zip functionality in autoit. dim $oMyError ; Initialize SvenP 's error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ;Show version as proof object created. $objZip = ObjCreate("XStandard.Zip") MsgBox(0,"Version","Version "&$objZip.Version) $objZip = "" ;Add/Create archive $objZip = objCreate("XStandard.Zip") ; .Pack(Source file, Dest archive) $objZip.Pack ("c:\reportcard1.jpg","C:\Temp\Report.zip") $objZip.Pack ("c:\reportcard.bmp","C:\Temp\Report.zip") $objZip = "" ; get archive contents $message ="" $objZip = ObjCreate("XStandard.Zip") ; .Contents(Zip.file.to.get.contents.of) For $objItem In $objZip.Contents("C:\Temp\archive.zip") $message &= $objItem.Path & $objItem.Name & @CRLF Next MsgBox(0,"Contents",$message) $objZip = "" $objItem = "" ;Extract archive to folder $objZip = ObjCreate("XStandard.Zip") ; .UnPack( Zip file , Destination) $objZip.UnPack ("C:\Temp\archive.zip", "C:\Temp\archive") $objZip = "" ;Extract archive using wildcards $objZip = ObjCreate("XStandard.Zip") ; .UnPack (Zip Archive, Dest "*.Whatever") $objZip.UnPack ("C:\Temp\archive.zip", "C:\Temp\wild", "*.jpg") $objZip = "" Exit ; these functs not tested but should work as written ;Archive with different compression levels $objZip = ObjCreate("XStandard.Zip") ; .Pack (Source file, Dest Archive, Keep path (0=false), compression level) $objZip.Pack ("C:\x-zip.doc", "C:\Temp\archive.zip",0 , 9) $objZip.Pack ("C:\sky.jpg", "C:\Temp\archive.zip", 0, 1) $objZip = "" ;Create with default path $objZip = ObjCreate("XStandard.Zip") $objZip.Pack ("C:\x-zip.doc", "C:\Temp\archive.zip", 1) $objZip.Pack ("C:\sky.jpg", "C:\Temp\archive.zip", 1) $objZip = "" ;Create with custom paths (tested and working) $objZip = ObjCreate("XStandard.Zip") ; .Pack (Source file, Dest Archive, Keep path (1=TRUE), Path or default if left blank) $objZip.Pack ("C:\x-zip.doc", "C:\Temp\archive.zip", 1, "files/word") $objZip.Pack ("C:\sky.jpg", "C:\Temp\archive.zip", 1, "files/images") $objZip = "" ;Create archive using wildcards $objZip = ObjCreate("XStandard.Zip") $objZip.Pack ("C:\*.jpg", "C:\Temp\images.zip") $objZip = "" ;Remove file from archive $objZip = ObjCreate("XStandard.Zip") $objZip.Delete ("sky.jpg", "C:\Temp\images.zip") $objZip = "" ;Move file within archive $objZip = ObjCreate("XStandard.Zip") $objZip.Move ("files/images/sky.jpg", "images/sky.jpg", "C:\Temp\images.zip") $objZip = "" ;Rename file in archive $objZip = ObjCreate("XStandard.Zip") $objZip.Move ("files/images/sky.jpg", "files/images/sky1.jpg", "C:\Temp\images.zip") $objZip = "" Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1); to check for after this function returns Endfunc
I tested a few of the fuctions and they seem to work. The examples here are just converted from the .asp examples provided on the dll web page and are given only as proof it works.
Enjoy
EDIT
In case the link is dead, here is the main page http://xstandard.com/default.asp
click on all products, the down a little ways is zip component.
-
eltorro got a reaction from cyberbit in XML DOM wrapper (COM)
Try using
MsgBox(4096, "test", $search[1]) oÝ÷ Ú)ìµæ¡ö®¶s`¤×6t&÷CbÂgV÷C·FW7BgV÷C²Âb33c·6V&6oÝ÷ Ù«¢+Ø(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ìչѥ½¸9µè}a51ÑY±Õ(ìÍÉ¥ÁÑ¥½¸èÐa50¥±Í½¸aAÑ ¥¹ÁÕÐɽ´É½½Ð¹½¸(ìAɵÑÉÌèÀÌØíÁÑ áµ°ÑÉÁÑ É½´É½½Ð¹½¡É½½Ð½¡¥±½¡¥±¸¸¤(ìMå¹Ñàè}a51ÑY±Õ ÀÌØíÁÑ ¤(ìÕÑ¡½È¡Ì¤èMÑÁ¡¸A½¡©¤±Ðí¡½ÍÍÑ͹ѵ¹½´Ðì(ìIÑÕɹÌèÉÉä½¥±ÌÑáÐÙ±Õ̴Ľ¸¥±ÕÉ(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(oÝ÷ Øw«zØ^r^"ëu«¢+Ø)1½°ÀÌØíÍ¥±ôÅÕ½Ðí½½Ì¹áµ°ÅÕ½Ðì(%¥±á¥ÍÑÌ ÀÌØíÍ¥±¤Q¡¸(ÀÌØíÉÐô}a51¥±=Á¸ ÀÌØíÍ¥±¤(¥ÀÌØíÉÐôÀÑ¡¸á¥Ð((ÀÌØí ½Èô}a51ÑY±Õ ÅÕ½ÐíMÑÑ¥¹Ì½ ½ÈÅÕ½Ðì¤(ÀÌØíYÉ¥¹ô}a51ÑY±Õ ÅÕ½ÐíMÑÑ¥¹Ì½YÉ¥¹ÅÕ½Ðì¤(ÀÌØíÍÉ ô}a51ÑY±Õ ÅÕ½ÐíMÑÑ¥¹Ì½MÉ ÅÕ½Ðì¤((5Í ½à ÐÀ䨰ÅÕ½ÐíÑÍÐÅÕ½Ðì°ÀÌØíÍÉ¡lÅt¤(5Í ½à ÐÀ䨰ÅÕ½ÐíÉɽÈÅÕ½Ðì°}a51ÉÉ½È ¤¤(¹%(
eltorro
-
eltorro got a reaction from Loz in _PathSplitByRegExp()
Try this
Func _PathSplitByRegExp($sPath) If $sPath = "" Or (StringInStr($sPath, "\") And StringInStr($sPath, "/")) Then Return SetError(1, 0, -1) Local $RetArray[8], $pDelim = "" If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\" If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//" If $pDelim = "" Then $pDelim = "/" If Not StringInStr($sPath, $pDelim) Then Return $sPath If $pDelim = "\" Then $pDelim &= "\" $RetArray[0] = $sPath $RetArray[1] = StringReplace($sPath,StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*|\\w*\\)', ''),"") $RetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '') $RetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '') $RetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & '|\\\\\w*\\|\\w*\\)', '') $RetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '') $RetArray[6] = StringRegExpReplace($RetArray[5], '\.[^.]*$', '') $RetArray[7] = StringRegExpReplace($sPath, '^.*\.', '') Return $RetArray EndFunc
Results:
C:/my test/path/file.zip [0] =C:/my test/path/file.zip [1] =C:/ [2] =C:/my test/path [3] =C:/my test/path/file [4] =my test/path/file.zip [5] =file.zip [6] =file [7] =zip \\nas\public\videos\Hackers.avi [0] =\\nas\public\videos\Hackers.avi [1] =\\nas [2] =\\nas\public\videos [3] =\\nas\public\videos\Hackers [4] =public\videos\Hackers.avi [5] =Hackers.avi [6] =Hackers [7] =avi C:\my test\path\file.zip [0] =C:\my test\path\file.zip [1] =C:\ [2] =C:\my test\path [3] =C:\my test\path\file [4] =my test\path\file.zip [5] =file.zip [6] =file [7] =zip
Regards