Jump to content

neazoi

Active Members
  • Posts

    48
  • Joined

  • Last visited

Recent Profile Visitors

121 profile views

neazoi's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. I saw your example and this is exactly what needed. However due to my lack of good knowledge obviously, I am confused in embedding it into my (yours) application. The code I have is this (minor graphics mods to yours). I just need the functuonality you provided but each label must be a new copy to the area, so that the previous label is not overwritten or deleted, each time I put a new label. The position and the text label should be kept into the $aGDIPBuffer, like it is done for the images (if I understand this correctly), so that I can export it later on. Instead of the image name, the label text could be kept. It would be great if you could help me embed it to this example. Thanks so much for your time! ;You'll notice $aGDIPBuffer at the top of the script. I used something like this when I was trying to make a small image editor in GDI+. ;This holds the information of what to draw, where, and how tall in your work area. The [n][0] position holds the image to draw, [n][1] is the left position, ;[n][2] is the top, [n][3] is the right, and [n][4] is the bottom position of the image to draw. Having your buffer like this will also make it easier ;to delete images from the work area. ;In the WM_LBUTTONDOWN function I used _WinAPI_PtInRectEx to check what available images is being selected, based on the same algorithm I used to draw ;the images in the DrawGdipArea function. When you want to remove or move your images in the work area you can use the same thing since you stored all ;the points you need. You could do this with labels/pic control to figure out what image you're over but I used this way. Do whatever you prefer. ;If you wanted to use some kind of button to change your available circuits, you'll have to either create a separate GUI to hold the buttons or ;create them in an area outside the $hBitmap area (Currently it's the whole GUI). #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinApi.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <Array.au3> _GDIPlus_Startup() Global Const $iGuiWidth = 1501 ;Window width Global Const $iGuiHeight = 1010 ;Window height Global Const $iTablePadding = 8 ;padding of components cells Global Const $hSepPen = _GDIPlus_PenCreate(0xFF000000, 2) ;bgcolor and size of the separator line Global Const $hWorkBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ;bgcolor of the schematic area Global Const $hBackBrush = _GDIPlus_BrushCreateSolid(0x4FFFFFFF) ;bgcolor of the dragged image Global $aGDIPBuffer[1][5] ;Buffer holds the information of the work area. ;[n][0] will be the image, ;[n][1] is left position, ;[n][2] is top position, ;[n][3] is right position, ;[n][4] is bottom position of the image Global $iImageWidth = 0 Global $iImageHeight = 0 Global $aGDIImageList = LoadGdiImageList($iImageWidth, $iImageHeight, $iGuiWidth, $iGuiHeight) Global $frmMainGui = GUICreate("Schematix v0.1 by sv3ora", $iGuiWidth, $iGuiHeight) Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($frmMainGui) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGuiWidth, $iGuiHeight, $hGraphic) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) GUIRegisterMsg($WM_PAINT, WM_PAINT) GUIRegisterMsg($WM_LBUTTONDOWN, WM_LBUTTONDOWN) GUISetState(@SW_SHOW, $frmMainGui) GUISetCursor("5") ;set the window cursor to a predefined image (0-16) While (True) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE ; Always clean up your resources when you're done with GDI+ DisposeGdiImageList($aGDIImageList) _GDIPlus_PenDispose($hSepPen) _GDIPlus_BrushDispose($hWorkBrush) _GDIPlus_BrushDispose($hBackBrush) _GDIPlus_Shutdown() GUIDelete($frmMainGui) Exit 0 EndSwitch WEnd Func LoadGdiImageList(ByRef $iMaxWidth, ByRef $iMaxHeight, Const ByRef $iGuiWidth, $iGuiHeight) Local $aImageList[330] ;how many images to be displayed Local $iCurrentIndex = 0 Local $iRows = 0 Local $iColumns = 0 For $i = 0 To UBound($aImageList) - 1 $aImageList[$i] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Imagestodelete\" & $i & ".gif") $iImageWidth = Max(_GDIPlus_ImageGetWidth($aImageList[$i]), $iMaxWidth) $iImageHeight = Max(_GDIPlus_ImageGetHeight($aImageList[$i]), $iMaxHeight) Next GetTableDimensions($iRows, $iColumns, $iGuiWidth, $iGuiHeight, UBound($aImageList), $iImageWidth, $iImageHeight) Local $aImageListReturn[$iRows][$iColumns] For $iRow = 0 To UBound($aImageListReturn, $UBOUND_ROWS) - 1 For $iColumn = 0 To UBound($aImageListReturn, $UBOUND_COLUMNS) - 1 $aImageListReturn[$iRow][$iColumn] = $aImageList[$iCurrentIndex] $iCurrentIndex += 1 If ($iCurrentIndex >= UBound($aImageList)) Then For $i = $iColumn To $iColumns $aImageListReturn[$iRow][$iColumn] = $aImageList[0] Next ExitLoop 2 EndIf Next Next Return $aImageListReturn EndFunc ;==>LoadGdiImageList Func DisposeGdiImageList(ByRef $aImageList) If (IsArray($aImageList)) Then For $iRow = 0 To UBound($aImageList, $UBOUND_ROWS) - 1 For $iColumn = 0 to UBound($aImageList, $UBOUND_COLUMNS) - 1 _GDIPlus_ImageDispose($aImageList[$iRow][$iColumn]) Next Next Else Return SetError(-1, 0, 0) EndIf Return 1 EndFunc ;==>DisposeGdiImageList Func Max(Const ByRef $lhs, Const ByRef $rhs) Return ($lhs > $rhs ? $lhs : $rhs) EndFunc ;==>Max Func GetTableDimensions(ByRef $iRows, ByRef $iColumns, $iMaxWidth, $iMaxHeight, $iCount, Const ByRef $iImageWidth, Const ByRef $iImageHeight) If ($iImageWidth = 0 Or $iImageHeight = 0 Or $iMaxWidth <= 20 Or $iMaxHeight <= 20) Then Return SetError(-1, 0, 0) ; Get the max columns. $iTablePadding for the left, right, and top of the table and $iTablePadding between each iamge $iColumns = Int(($iMaxWidth - ($iTablePadding * 2)) / ($iImageWidth + $iTablePadding)) $iRows = Ceiling($iCount / $iColumns) Return 1 EndFunc ;==>GetTableDimensions Func DrawGdipArea(Const $bDrawAtEnd = True) _GDIPlus_GraphicsClear($hBuffer, 0xFFE1E1E1) ;bgcolor of the components area For $iRow = 0 To UBound($aGDIImageList, $UBOUND_ROWS) - 1 For $iColumn = 0 To UBound($aGDIImageList, $UBOUND_COLUMNS) - 1 Local $iLeft = $iTablePadding + ($iTablePadding * $iColumn) + ($iColumn * $iImageWidth) Local $iTop = $iTablePadding + ($iTablePadding * $iRow) + ($iRow * $iImageHeight) Local $iRight = $iLeft + $iImageWidth Local $iBottom = $iTop + $iImageHeight ; Draw border around image, 4px offset ;_GDIPlus_GraphicsDrawLine($hBuffer, $iLeft - 4, $iTop - 4, $iLeft - 4, $iBottom + 4) ; Left ;_GDIPlus_GraphicsDrawLine($hBuffer, $iRight + 4, $iTop - 4, $iRight + 4, $iBottom + 4) ; Right ;_GDIPlus_GraphicsDrawLine($hBuffer, $iLeft - 4, $iTop - 4, $iRight + 4, $iTop - 4) ; Top ;_GDIPlus_GraphicsDrawLine($hBuffer, $iLeft - 4, $iBottom + 4, $iRight + 4, $iBottom + 4) ; Bottom _GDIPlus_GraphicsDrawImageRect($hBuffer, $aGDIImageList[$iRow][$iColumn], $iLeft, $iTop, $iImageWidth, $iImageHeight) Next Next ; Draw border around the whole table, 8px offset ; Just to make it look pretty :) ;_GDIPlus_GraphicsDrawLine($hBuffer, $iTablePadding - 8, $iTablePadding - 8, $iTablePadding - 8, $iBottom + 8) ; Left ;_GDIPlus_GraphicsDrawLine($hBuffer, $iRight + 8, $iTablePadding - 8, $iRight + 8, $iBottom + 8) ; Right ;_GDIPlus_GraphicsDrawLine($hBuffer, $iTablePadding - 8, $iTablePadding - 8, $iRight + 8, $iTablePadding - 8) ; Top ;_GDIPlus_GraphicsDrawLine($hBuffer, $iTablePadding - 8, $iBottom + 8, $iRight + 8, $iBottom + 8) ; Bottom _GDIPlus_GraphicsFillRect($hBuffer, 0, $iBottom + 25, $iGuiWidth, $iGuiHeight - $iBottom, $hWorkBrush) ; There's an image at the top row If ($aGDIPBuffer[0][0]) Then For $iBuffer = 0 To UBound($aGDIPBuffer, $UBOUND_ROWS) - 1 _GDIPlus_GraphicsDrawImageRect($hBuffer, $aGDIPBuffer[$iBuffer][0], $aGDIPBuffer[$iBuffer][1], $aGDIPBuffer[$iBuffer][2], $iImageWidth, $iImageHeight) Next EndIf _GDIPlus_GraphicsDrawLine($hBuffer, 0, $iBottom + 25, $iGuiWidth, $iBottom + 25, $hSepPen) If ($bDrawAtEnd) Then _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0) Return True EndFunc ;==>DrawGdipArea Func WM_PAINT($hWndFrom, $iMsg, $wParam, $lParam) DrawGdipArea() Return $GUI_RUNDEFMSG EndFunc ;==>WM_PAINT Func WM_LBUTTONDOWN($hWndFrom, $iMsg, $wParam, $lParam) Local $iLButtonX = _WinAPI_LoWord($lParam) Local $iLButtonY = _WinAPI_HiWord($lParam) Local $iImageRow = -1 Local $iImageColumn = -1 Local $aCursorInfo = 0 Local $iGdipBufferIndex = UBound($aGDIPBuffer, $UBOUND_ROWS) Switch ($hWndFrom) Case $frmMainGui For $iRow = 0 To UBound($aGDIImageList, $UBOUND_ROWS) - 1 For $iColumn = 0 To UBound($aGDIImageList, $UBOUND_COLUMNS) - 1 Local $iLeft = $iTablePadding + ($iTablePadding * $iColumn) + ($iColumn * $iImageWidth) Local $iTop = $iTablePadding + ($iTablePadding * $iRow) + ($iRow * $iImageHeight) Local $iRight = $iLeft + $iImageWidth Local $iBottom = $iTop + $iImageHeight If (_WinAPI_PtInRectEx($iLButtonX, $iLButtonY, $iLeft, $iTop, $iRight, $iBottom)) Then $iImageRow = $iRow $iImageColumn = $iColumn ExitLoop EndIf Next Next If ($iImageRow > -1 And $iImageColumn > -1) Then $aCursorInfo = GUIGetCursorInfo($hWndFrom) If (@error) Then Return $GUI_RUNDEFMSG While ($aCursorInfo[2]) Local $iLeft = $aCursorInfo[0] - Int($iImageWidth / 2) Local $iTop = $aCursorInfo[1] - Int($iImageHeight / 2) DrawGdipArea(False) _GDIPlus_GraphicsFillRect($hBuffer, $iLeft, $iTop, $iImageWidth, $iImageHeight, $hBackBrush) _GDIPlus_GraphicsDrawImageRect($hBuffer, $aGDIImageList[$iImageRow][$iImageColumn], $iLeft, $iTop, $iImageWidth, $iImageHeight) _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0) $aCursorInfo = GUIGetCursorInfo($hWndFrom) If (@error) Then Return $GUI_RUNDEFMSG WEnd $aGDIPBuffer[$iGdipBufferIndex - 1][0] = $aGDIImageList[$iImageRow][$iImageColumn] $aGDIPBuffer[$iGdipBufferIndex - 1][1] = $iLeft $aGDIPBuffer[$iGdipBufferIndex - 1][2] = $iTop $aGDIPBuffer[$iGdipBufferIndex - 1][3] = $iLeft + $iImageWidth $aGDIPBuffer[$iGdipBufferIndex - 1][4] = $iTop + $iImageHeight ReDim $aGDIPBuffer[$iGdipBufferIndex + 1][5] DrawGdipArea() EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_LBUTTONDOWN
  2. Thank you very much for the code snippet, It has been very helpful! To draw electronics schematics one needs to put labels for the components, near them. I do not want to convert the text into image and place the image to a position, but instead I was wondering if this drag and drop for images you have done, can be done for text as well? What I need is to type the text into a form box and then to be able to place this text (drag and drop? or click?) to a specific area of the schematic (puzzle). The text positions should be held in the $aGDIPBuffer, similar to the images, because I want to export/import it's data later on. Would that it be easy to be done somehow?
  3. Yes I have noticed that, thanks a lot. How would you do it if you wanted the pieces to be dropped into predefined positions, like in the javascript program I sent you? That way, one does not need to accurately place one image next to the other. and the pieces are pasted always in predefined positions onto a grid. Any ideas?
  4. Ok I declared the $iLeft $iTop $iRight $iBottom at the beginning and it worked. Thanks so much for the script! thumbs up!! How would you do it if you wanted the pieces to be dropped into predefined positions, like in the javascript program I sent you? That way, one does not need to accurately place one image next to the other. PS. I wonder, why it did not work in the previous version...
  5. I did not modify it. I just installed the newest version of autoit just to make sure. Now the error is: "C:\Users\Desktop\Schematix.au3" (125) : ==> Variable used without being declared.: _GDIPlus_GraphicsDrawLine($hBuffer, $iTablePadding - 8, $iTablePadding - 8, $iTablePadding - 8, $iBottom + 8) _GDIPlus_GraphicsDrawLine($hBuffer, $iTablePadding - 8, $iTablePadding - 8, $iTablePadding - 8, ^ ERROR
  6. There must be an error somewhere, or something is happening with the includes. C:\Users\Desktop\schematic.au3 (23) : ==> Missing separator character after keyword.: GUIRegisterMsg($WM_PAINT, WM_PAINT) GUIRegisterMsg($WM_PAINT, WM_PAINT^ ERROR
  7. Hi, I have made a javascript program that can create online electronics schematics http://5.54.115.143/jlab/cad/schematic/index.html It works like a puzzle. You pick an image from the table above and then you place it into the table below (blank area). That way you create schematics, like a puzzle. I would like to move this functionality from javascript to autoit. Is there any example of puzzle (pick and place into grid functionality), so that it can help me begin with the development? Thank you
  8. Hi here is a snippet of my code that uses 7zip (external compression program) to compress a file selected from a previous dialogue. The file and location to be compressed is passed into $sFileOpenDialog and then the command to be run for the 7zip is created. The problem is that if the $sFileOpenDialog value contains spaces, the 7zip command fails to run. When I run the command manually (run the exe by hand from the windows command prompt) the spaces in the filename/location do not affect the compression Any help of how to solve this? ;$sFileOpenDialog2 is the tmp.zip file and its path Local $sFileOpenDialog2 = @TempDir&"\tmp.zip" ;compress the file selected ;First check if tmp.zip file exists Local $iFileExists = FileExists($sFileOpenDialog2) ; Check if file exists or not. If $iFileExists Then ;Delete the temporary tmp.zip file. FileDelete($sFileOpenDialog2) ;Set the parameters of the create zip command Local $param1 = @ScriptDir&"\7z.exe " Local $param3 = "a -tzip -aoa -mx=9 " Local $param4 = @TempDir&"\tmp.zip " ;Create zip RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE) Else ;Set the parameters of the create zip command Local $param1 = @ScriptDir&"\7z.exe " Local $param3 = "a -tzip -aoa -mx=9 " Local $param4 = @TempDir&"\tmp.zip " ;Create zip RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE) EndIf
  9. Hello, I have a problem of compressing a file using 7zip.exe run from inside the autoit script. The compression is on lines 170-210. I use 7zip.exe because I do not want to use the internal windows compression mechanism (win2k not supported and it does not work with all versions of modern OS). When I run manually the command "C:\7z.exe a -tzip -aoa -mx=9 C:\tmp.zip filetobecompressed.gif" from the command prompt, it works ok in all versions of OS. However from inside the script, the command runs only if the script is run from winXP, or some Win7 PCs. I have tried it on Win2k and it does not compress. I have also tried it on a friend's PC running win7 and it does not compress. What could the problem be? ; ==================================================== ; ============ DataText encoder/decoder ============== ; ==================================================== ; Version: 1.4 ; Language: English ; Author: "sv3ora" ; Info website: http://www.qrp.gr/datatext ; ; ---------------------------------------------------------------------------- ; Script Start ; ---------------------------------------------------------------------------- #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> #include <String.au3> #include <FileConstants.au3> #include <base32.au3> #include <Crypt.au3> #include <Date.au3> #include <GuiEdit.au3> _Main() Func RestartScript() If @Compiled = 1 Then Run( FileGetShortName(@ScriptFullPath)) Else Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc Func SetTime() Local $time = _TicksToTime(Int(TimerDiff($begin)), $hour, $min, $sec) ControlSetText($WinMain, "", $label, StringFormat("%02i:%02i:%02i", $hour, $min, $sec)) EndFunc Func _Main() ; Creates window Global $WinMain = GUICreate('DataText v1.4 by sv3ora', 570, 350) ; Creates main edit Local $idEditText = GUICtrlCreateEdit('', 5, 5, 560, 280) _GUICtrlEdit_SetLimitText($idEditText, 6400000) ; Create the buttons Local $idEncodeButton = GUICtrlCreateButton('Encode', 5, 290, 85, 25) Local $idDecodeButton = GUICtrlCreateButton('Decode', 96, 290, 85, 25) Local $idInfoButton = GUICtrlCreateButton('?', 545, 325, 20, 20) ; Creates the password box with blured and centered input Local $idInputPass = GUICtrlCreateInput('', 187, 290, 100, 24, BitOR($ES_CENTER, $ES_PASSWORD)) ; Pass text label Local $idLabel = GUICtrlCreateLabel(' Password', 191, 294, 91, 17) ; Set the background color of the label Password. GUICtrlSetBkColor($idLabel, $COLOR_WHITE) ; Create the combo to select the crypting algorithm Local $idCombo = GUICtrlCreateCombo("", 291, 290, 88, 25, $CBS_DROPDOWNLIST) GUICtrlSetData($idCombo, "3DES|AES (128bit)|AES (192bit)|AES (256bit)|DES|RC2|RC4", "RC4") ; Create the player buttons Local $playButton = GUICtrlCreateButton('Play', 5, 320, 40, 25) Local $stopButton = GUICtrlCreateButton('Stop', 50, 320, 40, 25) ; SLIDERS Local $volumeSliderLabel = GUICtrlCreateLabel("Volume:", 100, 325) Local $volumeSlider = GUICtrlCreateSlider(150, 320, 110, 25) GUICtrlSetData(-1, 50) ; Create the combo to select the play delay Local $delaySliderLabel = GUICtrlCreateLabel("Delay:", 270, 325) Local $idCombo2 = GUICtrlCreateCombo("", 314, 320, 65, 25, $CBS_DROPDOWNLIST) GUICtrlSetData($idCombo2, "None|0.25 sec|0.5 sec|1 sec|2 sec|3 sec|4 sec|5 sec", "None") Global $fileIsImage ;timer GUICtrlCreateLabel("Elapsed:", 387, 325) Global $hour, $min, $sec, $begin Global $label = GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ; Shows window GUISetState() Local $iAlgorithm = $CALG_RC4 Local $dEncrypted Local $dDecrypted Local $encodedDataZIP Local $iDelay While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idCombo ; Check when the combobox is selected and retrieve the correct algorithm. Switch GUICtrlRead($idCombo) ; Read the combobox selection. Case "3DES" $iAlgorithm = $CALG_3DES Case "AES (128bit)" $iAlgorithm = $CALG_AES_128 Case "AES (192bit)" $iAlgorithm = $CALG_AES_192 Case "AES (256bit)" $iAlgorithm = $CALG_AES_256 Case "DES" $iAlgorithm = $CALG_DES Case "RC2" $iAlgorithm = $CALG_RC2 Case "RC4" $iAlgorithm = $CALG_RC4 EndSwitch Case $idEncodeButton ; When you press Encode ;;;;;;;;;;;;;; SELECT FILE TO ENCODE ;;;;;;;;;;;;;;;; ; Create a constant variable in Local scope of the message to display in FileOpenDialog. Local $sMessage = "Select file to encode." ; Display an open dialog to select a file. Local $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir&"\DataText_all_files", "Images (*.jpg;*.png;*.gif)|All files (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then ; Display the error message. GUICtrlSetData($idEditText, "Error. No file was selected!") RestartScript() ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) Else ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog. $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF) EndIf ;start timer $begin = TimerInit() AdlibRegister("SetTime", 1000) ;;;;;;;;;;;;;; COMPRESS SELECTED FILE ;;;;;;;;;;;;;;;; GUICtrlSetData($idEditText, "Wait for data processing. This may take a while...") ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 10) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("10%", 535, 295) ;$sFileOpenDialog2 is the tmp.zip file and its path Local $sFileOpenDialog2 = @TempDir&"\tmp.zip" ;compress the file selected ;First check if tmp.zip file exists Local $iFileExists = FileExists($sFileOpenDialog2) ; Check if file exists or not. If $iFileExists Then ;Delete the temporary tmp.zip file. FileDelete($sFileOpenDialog2) ;Set the parameters of the create zip command Local $param1 = @ScriptDir&"\7z.exe " Local $param3 = "a -tzip -aoa -mx=9 " Local $param4 = @TempDir&"\tmp.zip " ;Create zip RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE) Else ;Set the parameters of the create zip command Local $param1 = @ScriptDir&"\7z.exe " Local $param3 = "a -tzip -aoa -mx=9 " Local $param4 = @TempDir&"\tmp.zip " ;Create zip RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE) EndIf ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 20) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("20%", 535, 295) ;;;;;;;;;;;;;; READ COMPRESSED FILE ;;;;;;;;;;;;;;;; ; Open the tmp.zip file for reading and store the handle to a variable. Local $sFileOpen = FileOpen($sFileOpenDialog2, $FO_READ) If $sFileOpen = -1 Then GUICtrlSetData($idEditText, "An error occurred when reading the file.") Return False EndIf ; Read the contents of the tmp.zip file using the handle returned by FileOpen. Local $dataZIP = FileRead($sFileOpen) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 40) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("40%", 535, 295) ;Close the temporary tmp.zip file FileClose($sFileOpen) ; Delete the temporary tmp.zip file. FileDelete($sFileOpenDialog2) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 60) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("60%", 535, 295) ;If the password box is empty, do not use encryption If GuiCtrlRead($idInputPass) = "" Then ;Encode the contents of the non encrypted variable to zbase32 $encodedDataZIP = _Base32_Encode($dataZIP) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 80) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("80%", 535, 295) ;If password box is not empty then use encryption Else ; Calls the encryption. $dEncrypted = _Crypt_EncryptData($dataZIP, GUICtrlRead($idInputPass), $iAlgorithm) ; Encrypt the text with the new cryptographic key. ;Encode the contents of the encrypted variable to zbase32 $encodedDataZIP = _Base32_Encode($dEncrypted) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 80) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("80%", 535, 295) EndIf ;;;;;;;;;;;;;; DISPLAY ENCODED DATA ;;;;;;;;;;;;;;;; ; Put encoded data to text box GUICtrlSetData($idEditText, $encodedDataZIP) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 100) GUICtrlCreateLabel("Progress:", 387, 295) Local $p1 = GUICtrlCreateLabel("100%", 535, 295) ;wait a bit Sleep(1000) GUICtrlDelete($p1) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ;end timer AdlibUnRegister("SetTime") GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) Case $idCombo2 ; Check when the combobox is selected and retrieve the correct delay. Switch GUICtrlRead($idCombo2) ; Read the combobox selection. Case "None" $iDelay = 0 Case "0.25 sec" $iDelay = 250 Case "0.5 sec" $iDelay = 500 Case "1 sec" $iDelay = 1000 Case "2 sec" $iDelay = 2000 Case "3 sec" $iDelay = 3000 Case "4 sec" $iDelay = 4000 Case "5 sec" $iDelay = 5000 EndSwitch Case $playButton ; When you press Play ; Disable the play and delay buttons GUICtrlSetState($playButton, $GUI_DISABLE) GUICtrlSetState($idCombo2, $GUI_DISABLE) ;Read text from input box Local $readedText = GUICtrlRead($idEditText) Local $char = StringSplit($readedText, "") ;store this to an array of characters Local $num = 0 Local $iRound3 = 0 Local $perc = $num&"%" ;start timer $begin = TimerInit() AdlibRegister("SetTime", 1000) For $i = 1 to $char[0] Switch GUIGetMsg() Case $stopButton ;if stop button has been clicked ExitLoop ; Exit the loop EndSwitch Local $volume = GUICtrlRead ($volumeSlider, 0) ;read volume slider SoundSetWaveVolume($volume) ; Set the volume Local $play1 = "\alphabet\" Local $play2 = ".wav" SoundPlay(@ScriptDir &$play1&$char[$i]&$play2, 1) $num = ((100*$char[0])/$char[0])-(((100*$char[0])/$char[0])-((100*$i)/$char[0])) $iRound3 = Round($num) $perc = $iRound3&"%" If StringLen($perc) > 3 Then $perc = "99%" ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, $num) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel($perc, 535, 295) Else ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, $num) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel($perc, 535, 295) EndIf Sleep ($iDelay) Next ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, (100*$char[0])/$char[0]) GUICtrlCreateLabel("Progress:", 387, 295) Local $p2 = GUICtrlCreateLabel("100%", 535, 295) ;wait a bit Sleep(1000) GUICtrlDelete($p2) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ;end timer AdlibUnRegister("SetTime") GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) ; Enable the play and delay buttons GUICtrlSetState($playButton, $GUI_ENABLE) GUICtrlSetState($idCombo2, $GUI_ENABLE) Case $idDecodeButton ; When you press Decode ;start timer $begin = TimerInit() AdlibRegister("SetTime", 1000) ;Read text from input box Local $textTodecodeCaps = GUICtrlRead($idEditText) ;if input box is empty If $textTodecodeCaps = "" Then RestartScript() Else ;convert all read text to lower case letters Local $textTodecode = StringLower($textTodecodeCaps) ; Friendly message to the text box GUICtrlSetData($idEditText, 'Wait for data processing. This may take a while...') ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 10) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("10%", 535, 295) ;DECRYPT DECODED DATA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;If the password box is empty, do not use encryption If GuiCtrlRead($idInputPass) = "" Then ;Encode the contents of the non encrypted variable to zbase32 $decodedDataZIP = _Base32_Decode($textTodecode) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 20) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("20%", 535, 295) ;If password box is not empty then use decryption Else ;Decode the contents of the variable to zbase32 Local $decodedData = _Base32_Decode($textTodecode) ; Calls the decryption. $decodedDataZIP = _Crypt_DecryptData($decodedData, GUICtrlRead($idInputPass), $iAlgorithm) ; Encrypt the text with the new cryptographic key. ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 20) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("20%", 535, 295) EndIf ;;;;;;;;;;;;;; WRITE DECODED AND/OR DECRYPTED DATA TO ZIP FILE ;;;;;;;;;;;;;;;; ;$theTMPfile is the tmp zip file and its path Local $theTMPfile = @TempDir&"\tmp2.zip" ; Open the file for writing (append to the end of a file) and store the handle to a variable. Local $rFileOpen = FileOpen($theTMPfile, $FO_OVERWRITE) If $rFileOpen = -1 Then GUICtrlSetData($idEditText, "An error occurred when reading the file.") Return False EndIf ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 40) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("40%", 535, 295) ; Write data to the file using the handle returned by FileOpen. FileWrite($rFileOpen, $decodedDataZIP) ; Close the handle returned by FileOpen. FileClose($rFileOpen) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 60) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("60%", 535, 295) ;;;;;;;;;;;;;; UNZIP THE ZIP FILE ;;;;;;;;;;;;;;;; ;First delete all files from DataText_received_files dir DirRemove(@ScriptDir&"\DataText_received_files",1) DirCreate(@ScriptDir&"\DataText_received_files") Local $DataText_received_files = @ScriptDir&"\DataText_received_files" Local $DataText_all_files = @ScriptDir&"\DataText_all_files" ;Set the parameters of the create zip command Local $param1a = @ScriptDir&"\7z.exe " Local $param3a = "e " Local $param4a = " -o" Local $param2a = " -y" ;Extract zip to DataText_received_files dir. wait for the process to finish RunWait($param1a&$param3a&$theTMPfile&$param4a&$DataText_received_files, "", @SW_HIDE) ;Extract zip to DataText_all_files dir. (if filename already exists, it will be overwritten!!!) RunWait($param1a&$param3a&$theTMPfile&$param4a&$DataText_all_files&$param2a, "", @SW_HIDE) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 80) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("80%", 535, 295) ; Delete the temporary tmp.zip file. FileDelete($theTMPfile) ; Put initial encoded data to text box GUICtrlSetData($idEditText, $textTodecode) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 100) GUICtrlCreateLabel("Progress:", 387, 295) Local $p3 = GUICtrlCreateLabel("100%", 535, 295) ;wait a bit Sleep(1000) GUICtrlDelete($p3) ; PROGRESS bar GUICtrlCreateProgress(453, 293, 78, 20) GUICtrlSetData(-1, 0) GUICtrlCreateLabel("Progress:", 387, 295) GUICtrlCreateLabel("0%", 535, 295) ;end timer AdlibUnRegister("SetTime") GUICtrlCreateLabel("00:00:00", 453, 325, 78, 20) ;open explorer window to see file Local $DataText_received_files = @ScriptDir & "\DataText_received_files" Local $windowtitle = "DataText_received_files" Run("explorer.exe " & $DataText_received_files);open explorer to see extracted files in folder Local $hExplorer = WinWait("[REGEXPTITLE:(?i)\Q" & $windowtitle & "\E$]") WinWaitClose($hExplorer) DirRemove(@ScriptDir&"\DataText_received_files",1); when files have been viewed, delete the DataText_received_files dir DirCreate(@ScriptDir&"\DataText_received_files");recreate the DataText_received_files dir EndIf Case $idInfoButton ;When you press ? ; Info message to the text box GUICtrlSetData($idEditText, "DataText by sv3ora"&@crlf&"Conversion of file to text and text to file."&@crlf&@crlf&"This program can be used to transfer data through any radio amateur digital mode "&@crlf&"(including CW), that supports text-only transmission"&@crlf&@crlf&"TO ENCODE A FILE:"&@crlf&"1. Click 'Encode' to select the file to encode."&@crlf&"2. Select all encoded text (right click) and copy it."&@crlf&"3. Paste this text to your favorite sending program."&@crlf&"If you want to password protect your file, enter a password and select the"&@crlf&"encryption algorithm from the drop down list, prior to clicking the encode button."&@crlf&@crlf&"TO DECODE A TEXT:"&@crlf&"1. Copy the text to decode from your favorite receiving"&@crlf&" program and paste it into this text box."&@crlf&"2. Click 'Decode' to decode this text."&@crlf&"3. The decoded file is automatically displayed in a new explorer window."&@crlf&"If the received data has been password protected, then you have to enter the"&@crlf&"password and select the encryption algorithm from the drop down list,"&@crlf&"prior to clicking the decode button. "&@crlf&@crlf&"Note that DataText keeps all your previously decoded files into the 'DataText_all_files' "&@crlf&"directory, inside the folder where the DataText program is."&@crlf&"If your newly received filename matches a filename in this directory, the old file"&@crlf&"will be overwritten!"&@crlf&@crlf&"EMBEDDED PLAYER: "&@crlf&"The embedded player, can be used to play any text (encoded or not) in the text area "&@crlf&"into phonetic alphabet. Set the delay between letters and click 'Play' to play the text."&@crlf&"The playback volume can be set at any time and the playback can be stopped "&@crlf&"by clicking 'Stop'."&@crlf&@crlf&"PROGRESS:"&@crlf&"The progress bar, shows the encoding, decoding and playback progress."&@crlf&"The elapsed time is also displayed during encoding, decoding and playback."&@crlf&@crlf&"More info about DataText at: http://www.qrp.gr/datatext"&@crlf&"Comments and suggestions at: sv3ora@qrp.gr") EndSwitch WEnd EndFunc ;==>_Main DataText.au3
  10. No I did not. BTW this silved the problem in a simple matter for me. I just need to call restart script not. Thank you all for your replies! #region ---Au3Recorder generated code Start --- Opt("WinWaitDelay",100) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) Local $iPID = Run('C:\Program Files\eQSO\PMR-Radio_Server\PMR_Radio_Server.exe') _WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second") MouseClick("left",695,351,1) _WinWaitActivate("PMR_Radio_Server","Failed to connect to") MouseClick("left",193,89,1) _WinWaitActivate("PMR_Radio_Server","eQSO Monitor Server ") MouseClick("left",180,125,1) _WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second") MouseClick("left",738,10,1) #region --- Internal functions Au3Recorder Start --- Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc #endregion --- Internal functions Au3Recorder End --- Sleep(30000) ;30sec pause. This is how often to restart the program ProcessClose($iPID) #endregion --- Au3Recorder generated code End ---and the restart function, to be called at the end to the code above Func RestartScript() If @Compiled = 1 Then Run( FileGetShortName(@ScriptFullPath)) Else Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc
  11. Hm... having the script (that calls the application) run all the time and restart itself after some time would be a nice solution. However, the application process needs to be killed before the next restart. How should I kill the process and wait to see if it is killed indeed, in order to restart the script again?
  12. Hello I have written a little script (using the recorder) to start up an application and click some buttons after start up. This script works fine for me #region ---Au3Recorder generated code Start --- Opt("WinWaitDelay",100) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) Run('C:\Program Files\eQSO\PMR-Radio_Server\PMR_Radio_Server.exe') _WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second") MouseClick("left",695,351,1) _WinWaitActivate("PMR_Radio_Server","Failed to connect to") MouseClick("left",193,89,1) _WinWaitActivate("PMR_Radio_Server","eQSO Monitor Server ") MouseClick("left",180,125,1) _WinWaitActivate("eQSO - Conference Server for PMR Radio ","Idle ID Time (Second") MouseClick("left",738,10,1) #region --- Internal functions Au3Recorder Start --- Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc #endregion --- Internal functions Au3Recorder End --- #endregion --- Au3Recorder generated code End ---The problem I have is that my application crashes after an hour or so, so I need to somehow: 1. kill it 2. wait for a few seconds 3. then restart it (using the script above). I want the above to loop forever (PS. I use older version of autoit for win2k, just for reference, but I think much of the code from v3 will work on it) Thanks so much for your help!
  13. ​Ok, if I understand well, I shall also develop the script using that version in a win2k machine and see what causes the error. The 7zip encryption is something I have not thought. I'll get back to you
  14. ​Does It mean that I cannot get any support on this thread for this issue? I know this is an old one, but some people still run on win2k and there are some reasons for that. I do not call the encrypt/decrypt functions when I try this. Initially, I try to run it without the option to encrypting anything, so these functions are not used.
×
×
  • Create New...