Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/08/2017 in all areas

  1. It isn't a rule, but something you can consider in any on-the-fly interpreted language. Consider this simple sequence: If <Condition> Then [13,000 lines of code] Else [Action] End It's obvious that, unless a form of compilation has taken place which can jump direct to [Action] when <Condition> isn't met, the interpreter will have to read and ignore 13,000 lines, something which wastes time. Hence if you expect the false branch to be significantly more frequent than the true branch, you should swap them and negate Condition.
    2 points
  2. eltorro

    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 AutoIt3Preview.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.
    1 point
  3. Believe me, I've been there before. Chalk it up to being late in the day on a Friday.
    1 point
  4. Please read the Helpfile! The FileClose takes the FileHandle returned by the FileOPen(), not a filename! Jos
    1 point
  5. Damn how could i miss that wait? Sometimes it's the most In-your-face stuff that gets you.
    1 point
  6. Thanks again for everything and glad I could "catch" one on my own.
    1 point
  7. FIgured it out! Instead of using "RunWait($str)" I used "Run($str)". As I recall, RunWait waits for the program called by AutoIT to terminate before sending additional commands.
    1 point
  8. I'd try to leave the text part out of it, leave only the title, try with handle, with class, and the opt variations.
    1 point
  9. Experiment with Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
    1 point
  10. I added a tag that it was solved but I don't know how to edit the title of this thread.
    1 point
  11. You had this: ;Local $str = "msiexec /i """ & $aArray[0] & """ <---- It was commented out, so not read. ConsoleWrite($str) ;<----here you used the variable $str, but since it was not set, you got the error, it's like, it was the first time the script has "seen" that variable. RunWait($str)
    1 point
  12. There is a registry setting you can add to set the default application for an extension type...that would be much easier. https://social.technet.microsoft.com/Forums/ie/en-US/06d35f90-56cb-4dec-b326-bd471d06acee/change-default-program-for-file-command-line-or-registry?forum=w7itprogeneral
    1 point
  13. Follow Modular design patterns in general. Split things into small autonomous units. Never glom everything into a monolithic structure. (this one is important. Having one place to edit in case of changes instead of many files to edit. maintainability) Use good meaningful variable names Don't get carried away with macros, not to say don't use them Keep functions small, over 50 lines and you need new supporting functions (this works well with C/C++/C# but not sure if applicable to AutoIT and otehr scripting languages, but I try to do this with AutoIT. Most of what makes my functions longer are just logging if they get long in AutoIT cause I am a logging fool Don't follow the Single Entry Single Exit nonsense bullcrap either. If you run into a condition you need to break from the function, then do it Don't use GoTo statements (obviously they lead to spaghetti logic that can't be maintained) Use Constants for strings and stuff that does not change. that way, when something needs to change, it changes in one spot, not many
    1 point
  14. Thank you. Perhaps this thread should live with the "good coding practice" posts? Are there any other such? (eager to learn)
    1 point
  15. @Earthshine Maybe then make a reference to Coded UI best practices to see what I can change in UIAwrappers. I think you mean the developer builds the functional testcases also in his own programming language (white box) which is fine as long as the output can be understood by all parties in and outside of the team (either with a replayable video or a bunch of screenshots with subtitles to tell what functionally is happening) The base of all (black box) GUI tools I have seen is about Use a bunch of 1,n properties to recognize your control and give them a logical programmatic name (object map, repository, application map) More advanced tools allow regex in the property identification values Have runnable specification language (no Gherkin/BDD is not directly executable without reprogramming it in your implementation program language), your script is your documentation (or can be presented in such a way its understandable to business and IT people) Support all type of UI Objects in a similar way (from mainframe telon screens up to the modern smart watch, 1 tool fits all) AutoIt + UI Wrappers is wel suited for windows + browser application(s) and not suited for mainframe, phone, watch without a lot of work. Java widgets is somewhere in the middle doable from AutoIt with some Java Accessibility Bridge but not seen a full finished udf to handle stuff easily.
    1 point
  16. Hi argumentum, Still around, sort of... Only 2 weeks response time. That script evolved into a generic library for creating icons with context menus on the deskop, which can be found here, that various others then worked on as well. I have no idea what was in that particular script, and it's not in any of my old archives. Cheers, Mat
    1 point
  17. correct That info is in the Title as well. @xxAndrexX, Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum rules on your way in. (there is also a link in my signature) Please read them now particularly the bit about not discussing Decompiling compiled scripts - and then you will understand why you will get no help and this thread will now be locked. See you soon with a legitimate question I hope. Jos
    1 point
  18. antmar904, Try this...note the comments in the code... #include <Array.au3> #include <file.au3> Local $afile _FileReadToArray(@ScriptDir & '\invlog.log', $afile) ; your first split is on the eol char, not the colon Local $aFinal[UBound($afile)][2] ; your result array sized from the array created from _FileReadToArray Local $idx = 0 ; keep track of array row For $i = 1 To UBound($afile) - 1 If StringLeft($afile[$i], 1) = '=' Or StringLeft($afile[$i], 1) = '' Then ContinueLoop $aFinal[$idx][0] = StringStripWS(StringRegExpReplace($afile[$i], '([^:]+):.*', '$1'), 3) ; set final array elemnt 0 with data on the left side of ":'...strip leading and trailing spaces $aFinal[$idx][1] = StringStripWS(StringRegExpReplace($afile[$i], '.*:(.*)', '$1'), 3) ; set final array elemnt 1 with data on the right side of ":'...strip leading and trailing spaces $idx += 1 Next ReDim $aFinal[$idx][2] ; resize array to valid entries _ArrayDisplay($aFinal) kylomas
    1 point
  19. Of course +1 must be added to $iFrom and $iTo. Because your item_id's starts at item_id = 1 and my item_id's starts at item_id = 0. Sorting columns by clicking the column header. I would do it in the same way as the deletions: ; Create sorting table in memory database _SQLite_Exec(-1, "CREATE TABLE DisplayMemDb.Sort1 AS SELECT item_id FROM lvdata ORDER BY f1;") ; Create sorting table in memory database _SQLite_Exec(-1, "CREATE TABLE DisplayMemDb.Sort2 AS SELECT item_id FROM lvdata ORDER BY f2;") ; Create sorting table in memory database _SQLite_Exec(-1, "CREATE TABLE DisplayMemDb.Sort3 AS SELECT item_id FROM lvdata ORDER BY f3;") Detect column header clicks in the listview: Case $LVN_COLUMNCLICK Local $iCol = DllStructGetData( DllStructCreate( $tagNMLISTVIEW, $lParam ), "SubItem" ) Switch $iCol Case 1,2,3 $iSort = $iCol Case Else $iSort = 0 EndSwitch GUICtrlSendMsg( $ListView1, $LVM_SETITEMCOUNT, 500000-5, 0 ) SQL SELECT statements: Case $LVN_ODCACHEHINT Local $tNMLVCACHEHINT = DllStructCreate( $tagNMLVCACHEHINT, $lParam ), $sSQL, $iColumns $iFrom = DllStructGetData( $tNMLVCACHEHINT, "iFrom" ) Switch $iSort Case 1 $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN Sort1 ON Sort1.item_id = lvdata.item_id " & _ "WHERE Sort1.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" Case 2 $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN Sort2 ON Sort2.item_id = lvdata.item_id " & _ "WHERE Sort2.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" Case 3 $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN Sort3 ON Sort3.item_id = lvdata.item_id " & _ "WHERE Sort3.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" Case Else Local $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN RowRelation ON RowRelation.item_id = lvdata.item_id " & _ "WHERE RowRelation.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" EndSwitch _SQLite_GetTable2d( -1, $sSQL, $aResult, $iRows, $iColumns ) ConsoleWrite($sSQL&@CRLF) #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <SQLite.au3> ; SQLite #include <Timers.au3> ; Create structure $tagNMLVCACHEHINT Global Const $tagNMLVCACHEHINT = $tagNMHDR & ";int iFrom;int iTo" ; #include <GuiListView.au3> Global $hListView _SQLite_Startup() $sFileDB = @ScriptDir & '\Data.db' $TableName='lvdata' ; Create DB if not exist If Not FileExists($sFileDB) Then ; Recreate data base $hStarttime=_Timer_Init() _SQLite_Open( $sFileDB ) _SQLite_Exec( -1, "PRAGMA synchronous = OFF;" ) $sExec = 'Create Table lvdata (' & _ '[item_id] INTEGER PRIMARY KEY AUTOINCREMENT,' & _ '[f1] TEXT,' & _ '[f2] TEXT,' & _ '[f3] TEXT,' & _ '[f4] TEXT,' & _ '[f5] TEXT,' & _ '[f6] TEXT,' & _ '[f7] TEXT,' & _ '[f8] TEXT,' & _ '[f9] TEXT );' _SQLite_Exec( -1, $sExec ) _SQLite_Exec( -1, "BEGIN TRANSACTION;" ) $Row=500000 $Line='tuysdufysdfsduyfiusydfisdyfiusfdsdf' For $i=0 To $Row-1 $ind=Random(5,25,1) $sData=StringMid($Line,$ind) $sValues = "(" & $i + 1 & ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "')" For $j = 1 To 99 $sValues &= ",(" & $i + $j + 1 & ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "')" Next _SQLite_Exec( -1, "INSERT INTO lvdata VALUES " & $sValues & ";" ) $i += 99 Next _SQLite_Exec( -1, "COMMIT TRANSACTION;" ) _SQLite_Close( -1 ) ConsoleWrite(@CRLF&'Create DB, create strings, fill table: '&_Timer_Diff($hStarttime)/1000&@CRLF) ; 7.9948113493733 EndIf ; Specially delete 5 records $hDB = _SQLite_Open($sFileDB) _SQLite_Exec($hDB, 'Delete From '&$TableName&' Where item_id > 5 And item_id <= 10 ;') ; Check databases Local $iRows2 = CheckDB( @ScriptDir&"\Data.db" ) ; Count of records Local $iRows ; GUI $Form1 = GUICreate("Virtual ListViews", 908, 524, 192, 114) ; Virtual ListViews - $LVS_OWNERDATA, Reduces flicker - $LVS_EX_DOUBLEBUFFER $ListView1 = GUICtrlCreateListView("", 8, 16, 890, 462, $LVS_OWNERDATA, BitOR( $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT ) ) $hListView = GUICtrlGetHandle($ListView1) ; Handle ; Add Columns For $i = 0 To 9 _GUICtrlListView_AddColumn( $hListView, "Col" & $i, 75 ) Next $Input1 = GUICtrlCreateInput("Input1", 8, 488, 185, 21) $Button1 = GUICtrlCreateButton("Button1", 200, 488, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 680, 488, 75, 25) $Button3 = GUICtrlCreateButton("Button3", 752, 488, 75, 25) $Button4 = GUICtrlCreateButton("Button4", 824, 488, 75, 25) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState(@SW_SHOW) $iRows = $iRows2 If $iRows Then _SQLite_Open( $sFileDB ) ; Create memory database _SQLite_Exec(-1, "ATTACH DATABASE ':memory:' AS DisplayMemDb;") ; Create table in memory database _SQLite_Exec(-1, "CREATE TABLE DisplayMemDb.RowRelation AS SELECT item_id FROM lvdata;") ; Create sorting table in memory database _SQLite_Exec(-1, "CREATE TABLE DisplayMemDb.Sort1 AS SELECT item_id FROM lvdata ORDER BY f1;") ; Create sorting table in memory database _SQLite_Exec(-1, "CREATE TABLE DisplayMemDb.Sort2 AS SELECT item_id FROM lvdata ORDER BY f2;") ; Create sorting table in memory database _SQLite_Exec(-1, "CREATE TABLE DisplayMemDb.Sort3 AS SELECT item_id FROM lvdata ORDER BY f3;") ; Send message to $ListView1, $iRows - Count of records GUICtrlSendMsg( $ListView1, $LVM_SETITEMCOUNT, $iRows, 0 ) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local Static $tText = DllStructCreate( "wchar[50]" ) Local Static $pText = DllStructGetPtr( $tText ) Local Static $aResult, $iRows, $iFrom, $iSort = 0 Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hListView Switch $iCode ; View Records Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $iIndex = DllStructGetData( $tNMLVDISPINFO, "Item" ) - $iFrom + 1 ; number row Local $nCol = DllStructGetData($tNMLVDISPINFO, "subitem") ; number column If $iIndex > 0 And $iIndex < $iRows + 1 Then Local $sItem = $aResult[$iIndex][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) EndIf EndIf Case $LVN_ODCACHEHINT Local $tNMLVCACHEHINT = DllStructCreate( $tagNMLVCACHEHINT, $lParam ), $sSQL, $iColumns $iFrom = DllStructGetData( $tNMLVCACHEHINT, "iFrom" ) Switch $iSort Case 1 $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN Sort1 ON Sort1.item_id = lvdata.item_id " & _ "WHERE Sort1.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" Case 2 $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN Sort2 ON Sort2.item_id = lvdata.item_id " & _ "WHERE Sort2.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" Case 3 $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN Sort3 ON Sort3.item_id = lvdata.item_id " & _ "WHERE Sort3.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" Case Else Local $sSQL = "SELECT lvdata.* FROM lvdata " & _ "INNER JOIN RowRelation ON RowRelation.item_id = lvdata.item_id " & _ "WHERE RowRelation.rowid BETWEEN " & $iFrom + 1 & " And " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) + 1 & ";" EndSwitch ;Local $sSQL = "SELECT * FROM lvdata WHERE item_id >= " & $iFrom & _ ; " AND item_id <= " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) & ";" ;~ Local $sSQL = "SELECT * FROM lvdata WHERE rowid >= " & $iFrom & _ ;~ " AND rowid <= " & DllStructGetData( $tNMLVCACHEHINT, "iTo" )+1 & ";" _SQLite_GetTable2d( -1, $sSQL, $aResult, $iRows, $iColumns ) ConsoleWrite($sSQL&@CRLF) Case $LVN_COLUMNCLICK Local $iCol = DllStructGetData( DllStructCreate( $tagNMLISTVIEW, $lParam ), "SubItem" ) Switch $iCol Case 1,2,3 $iSort = $iCol Case Else $iSort = 0 EndSwitch GUICtrlSendMsg( $ListView1, $LVM_SETITEMCOUNT, 500000-5, 0 ) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func CheckDB( $sDBname ) Local $aRow, $iRows = 0 If FileExists( $sDBname ) Then _SQLite_Open( $sDBname ) _SQLite_QuerySingleRow( -1, "SELECT COUNT(*) FROM lvdata LIMIT 1;", $aRow ) _SQLite_Close( -1 ) EndIf If IsArray( $aRow ) Then _ $iRows = $aRow[0] + 1 Return $iRows EndFunc I've updated the code to create "lvdata" table so that column 1-3 gets sorted differently. And I've updated the code to use bulk inserts: $Row=500000 $Line='tuysdufysdfsduyfiusydfisdyfiusfdsdf' For $i=0 To $Row-1 $ind=Random(5,25,1) $sData=StringMid($Line,$ind) $sValues = "(" & $i + 1 & ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "')" For $j = 1 To 99 $sValues &= ",(" & $i + $j + 1 & ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & StringMid($Line,Random(5,25,1)) & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "'" & _ ",'" & $sData & "')" Next _SQLite_Exec( -1, "INSERT INTO lvdata VALUES " & $sValues & ";" ) $i += 99 Next This means that the SQL INSERT statement looks like this: INSERT INTO lvdata VALUES (...),(...), ..., (...); This reduces the total time to create database and table, generate strings and insert strings in the table from 25 seconds to 8 seconds on my PC. I've also placed Case statements below Switch $iCode in proper order. The rule is that Case statements with most events should be in top of the list. You must delete and recreate the database to see the effects of the sorting in Col1 - Col3.
    1 point
  20. You are right, download links are dead due to dropbox updates So you can now get the last version in the AutoIt download section Thanks In this last version Au3FileSearch is replaced by StringFinder
    1 point
  21. That is your idea of good coding practice and, although you made some good suggestions. it does not necessarily tally with everyone else's idea. Using global variables has good and bad consequences. I personally avoid using them as much as possible. Avoiding global variables frees up memory and side steps several issues that may sometimes occur.
    1 point
  22. @stasia8954, it would probably have taken you less time to actually try it than it did to write your post. Have you tried it for yourself? Are you experiencing issues? If so, instead of just a blanket "is this supposed to work" question, try explaining in detail what problems you're running into.
    1 point
  23. enaiman

    Print Preview

    Nice job
    1 point
×
×
  • Create New...