Jump to content

Leaderboard

Popular Content

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

  1. Version 1.2

    29,309 downloads

    I wrote an introductory text for new programmers to learn how to code using AutoIt. It follows along with the help file for the most part – but provides additional context and attempts to connect all the information in a cohesive way for someone without any programming experience. I find the help file to be an AMAZING resource and the text I wrote in no way reflects any opinion to the contrary. Rather, it was created from the perspective of someone who struggled early on with the most basic concepts and thought that a hand-holding guide could be useful. I was also inspired by code.org who is trying to encourage people to learn to code. I thought – what better way than to use free tools that you can download at any time with access to an amazing community? If only there was a guide to walk people through it … Full discussion about the file can be found here: https://www.autoitscript.com/forum/topic/174205-introductory-learn-to-program-text-using-au3/
    1 point
  2. LPCTSTR = L‌ong P‌ointer to a C‌onst T‌CHAR STR‌ing Not very clear here where MS says : lpVerb = Type: LPCTSTR "A string, referred to as a verb" BUT lpFile = Type: LPCTSTR "The address of a null-terminated string" Thanks Microsoft
    1 point
  3. Welcome to the AutoIt forums. You can't, that's not how it works. When you use a dynamic link library that you haven't written yourself (such as shell32), you have to play by its rules, just as when you use an AutoIt UDF, you have to parse the (types of) arguments it expects, and in the right order, or else the call will likely fail. In this case, shell32 expects pointers to work buffers to be pushed onto the stack (i.e., 4/8 bytes each), not the buffers themselves (which take up much more space than the pointers to them would, e.g., here some are 255 bytes each). It can then perform operations on the indicated memory regions. It would be incredibly inefficient to parse those buffers themselves back and forth every time (I write dlls that handle buffers that are GBs in size; can you imagine (how long it would take to be) shuffling those around for each call? You don't want to be re-allocating, copying everything across, performing an action there, copying everything back, and de-allocating, when all you really have to do is tell the dll: "you need to do X on some data that live in location Y"). So unless you're willing to write your own dlls that behave the way you want them to, you'll have to conform to their specifications, or else you don't get to play.
    1 point
  4. I am learning how to optimize my code. You are not only delivering knowledge but good karma on the forum which is sometimes more needed then anything else in life. Thank You very much for all of that.
    1 point
  5. You must also open a file before any I/O operation can be performed on it. FileOpen allocates a buffer for I/O to the file and determines the mode of access to use with the buffer. The FileHandle is a reference to this allocated buffer/file. So in case in AutoIt3 you only have an FileRead() statement, then under the hood, AutoIt3 will do an FileOpen(), FileRead(), FIleCLose(). That is also why an FileOpen(), then looping through the records and ending with an FileCLose() is much faster then only using a FileRead(filename, Recordnumber) as that avoids maybe Open/Close actions. JOs
    1 point
  6. Thank you Jayme! I am a Dragon NaturallySpeaking ( speech recognition) user. I find that the AutoIT program language has similarities with Dragon scripting (VBA). Like many others I browsed the web for more information about this program language. Having no mathematical background whatsoever, not much programming experience too. Things like variables, constants, dim etc. never seemed to make much sense ( although I read about it in various scripts), now finally start making sense. You've managed to make these things accessible. That's an accomplishment! Rob.
    1 point
  7. I also recommend you to try the example of _WinAPI_EnumDisplayMonitors, which give you the resolution and position of each monitor.
    1 point
  8. Something like this here? Global $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Global $aFullScreen = WinGetPos($hFullScreen) MsgBox(0, "Test", "Screen Resolution of 2nd monitor: " & Abs($aFullScreen[2] - @DesktopWidth) & " x " & Abs($aFullScreen[3] - @DesktopHeight)) Should work only for 2 monitors.
    1 point
  9. Not sure why you show the FileOpen() inside the FileClose(), but yes, at the end of the script execution all handles will be closed and memory freed. It will be an issue though when you do those 3 commands repeatedly in a loop leaving all those files instances open. Jos
    1 point
  10. This is invalid coding as you need to use the FileHandle returned by FileOpen! On top of that you are missing a backslash before the filename. Something like this should be the correct way: $fh = FileOpen(@ScriptDir & "\File.txt", 1) FileWriteLine($fh, "Write something") FileClose($fh) The helpfile is your friend Jos
    1 point
  11. @KickStarter15 Yes, your code of post #10 will show four tabs, one file per tab. Don't forget about the four accompanying "correct answers" files for the "Ctrl"+"Alt"+"r" hotkey to display results. Note, the file "Results.csv" that is generated with the display results can be imported into Excel or OpenOffice Calc. $path = "D:\Programs\" & @UserName & "\" Global $file[4] = [$path & "Test.ini", $path & "TestTab2.ini", $path & "TestTab3.ini", $path & "TestTab4.ini"] ; Array of files with Question and Answers. ; Path to the correct answers files could be a thumb drive. Global $sFileCorrAns[4] = [$path & "TestCorrectAns.ini", $path & "TestCorrectAnsTab2.ini", $path & "TestCorrectAnsTab3.ini", $path & "TestCorrectAnsTab4.ini"] ; Array of files with corresponding Correct Answers. And here is another version with different coloured tabs and testing a third tab, "TestTab3.ini" and "TestCorrectAnsTab3.ini" with 17 questions. (files not included) #include <GUIConstantsEx.au3> #include <Array.au3> #include <File.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <GUIScrollBars_Ex.au3> ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; "GUIScrollBars_Ex.au3" found @ https://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-new-version-16-feb-17/ ; ScrolBars Example https://www.autoitscript.com/forum/topic/125332-scrolling-problem/?do=findComment&comment=870352 ; https://www.autoitscript.com/forum/topic/189195-tab-control-need-to-shorten-the-code/ HotKeySet("^!r", "_GetCheckAnswers") ; Ctrl+Alt+r HotKeySet("^!u", "_UnCheckRadio") ; Have the cursor hover over the radio button you want unchecked then press Ctrl+Alt+u ; For testing:- "TestCorrectAns.ini" has 8 questions; "TestCorrectAnsTab2.ini" has 10 questions; and "TestCorrectAnsTab3.ini" has 17 questions. Global $sFileCorrAns[3] = ["TestCorrectAns.ini", "TestCorrectAnsTab2.ini", "TestCorrectAnsTab3.ini"] ; Array of files with correct Answers. Global $file[3] = ["Test.ini", "TestTab2.ini", "TestTab3.ini"] ; Array of files with Question and Answers. QandAonTabs() Func QandAonTabs() ; ---- Find largest number of questions on any tab ------ Global $iNumofQues, $iNum For $i = 0 To UBound($sFileCorrAns) - 1 $iNum = UBound(FileReadToArray($sFileCorrAns[$i])) - 1 If $iNum > $iNumofQues Then $iNumofQues = $iNum Next ;ConsoleWrite("$iNumofQues = " & $iNumofQues & @CRLF) ; ---- End of Find largest number of questions on any tab ------ ; <<<<<<<<<<< Calculate size of tab to accommodate the Questions and Answers.<<<<<<<<<<<<<< Global $w = 690, $h = ((Ceiling($iNumofQues / 2) * 7) + 2) * 16 ;$w = tab width, $h=(Number of buttons deep * 7 lines per question + 2 lines)* 16 pixels per line ConsoleWrite("$h " & $h & @CRLF) ;<<<<<<<<<<<< End of Calculate size of tab to accommodate the Questions and Answers.<<<<<<<< $Form1 = GUICreate("Form1", $w + 10, 650, 230, 150, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME)) $LastTheme = XPStyle() GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $Tab1 = GUICtrlCreateTab(5, 24, $w, $h, $TCS_BUTTONS) GUICtrlSetFont(-1, 10, 400) XPStyle($LastTheme) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) Global $Radio[($iNumofQues * 6)][UBound($file)] ; Array to store the id's of the $iNumofQues questions per tabs max of 1 label + 5 answers per question making 60 elements per tabs. Local $aColor[3] = [0xAAFFCC, 0xAACCFF, 0xFFAABB] ; 3 tab colours depending on $b value. For $b = 0 To UBound($file) - 1 ; Tabs loop Global $aQA2D = _FileTo2D($file[$b]) ;_ArrayDisplay($aQA2D, "$aQA2D") $iFileLineNo = 0 GUICtrlCreateTabItem($aQA2D[0][0]) _GUICtrlTabSetBkColor($Form1, $Tab1, $aColor[Mod($b, UBound($aColor))]) Local $iQuesinTab = UBound($aQA2D) - 1 Local $iN = Ceiling($iQuesinTab / 2) ; Number of Ques in tab height For $a = 1 To UBound($aQA2D) ; groups of a label(question)and $iFileLineNo radio buttons on each tab. If $a >= UBound($aQA2D) Then ExitLoop $Label1 = GUICtrlCreateLabel($aQA2D[$a][0], 10 + (Int(($a - 1) / $iN) * 330), 50 + (110 * Mod($a - 1, $iN)), 325, 32) ; FileReadLine($file, $iFileLineNo) $Radio[$iFileLineNo][$b] = "Q" & ($a) & "Next " & $aQA2D[$a][1] $iFileLineNo += 1 For $c = 2 To $aQA2D[$a][1] + 1 $Radio[$iFileLineNo][$b] = GUICtrlCreateRadio($aQA2D[$a][$c], 35 + (Int(($a - 1) / $iN) * 330), 80 + (($c - 2) * 15) + ((110) * Mod($a - 1, $iN)), 300, 18) $iFileLineNo += 1 Next GUIStartGroup() Next Next ;_ArrayDisplay($Radio) GUISetState(@SW_SHOW) ; Generate scrollbars _GUIScrollbars_Generate($Form1, $w, $h) ; This is all you need to do to get scrollbars <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 $idMsg = GUIGetMsg() If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>QandAonTabs Func _GetCheckAnswers() Global $aAnswers[$iNumofQues + 2][UBound($sFileCorrAns)] For $k = 0 To UBound($sFileCorrAns) - 1 $aRes = FileReadToArray($sFileCorrAns[$k]) $aAnswers[1][$k] = $aRes[0] ;_ArrayDisplay($aRes, "Correct Answers") ;_ArrayDisplay($aAnswers) $iAnsIndex = 2 Local $iSumCorr = 0 For $i = 0 To UBound($Radio) - 1 ; UBound($Radio) is max. 60 of one label plus $iN radio button *10 questions = 60 If $Radio[$i][$k] = "" Then ExitLoop ; Instead of ReDim this allows Array columns of different lengths in $Radio array. $iNumAns = StringRegExpReplace($Radio[$i][$k], "^Q\d+Next ", "") $iQuesNum = StringRegExpReplace($Radio[$i][$k], "^Q|Next \d+", "") For $j = 0 To $iNumAns - 1 $i += 1 If BitAND(GUICtrlRead($Radio[$i][$k]), $GUI_CHECKED) = $GUI_CHECKED Then $aAnswers[$iAnsIndex][$k] = $iQuesNum & "-" & ChrW(65 + $j) ; ChrW(65) = "A" EndIf If $aAnswers[$iAnsIndex][$k] == $aRes[$iAnsIndex - 1] Then ; $aRes[$iAnsIndex - 1] because $aAnswers array will have $iSumCorr in 1st element. $aAnswers[$iAnsIndex][$k] &= " Correct" $iSumCorr += 1 ElseIf $aAnswers[$iAnsIndex][$k] == "" Then $aAnswers[$iAnsIndex][$k] = $iQuesNum & "-Not Answered" EndIf Next $iAnsIndex += 1 Next $aAnswers[0][$k] = $iSumCorr ; Total number correct in $aAnswers[0] Next _FileWriteFromArray("Results.csv", $aAnswers, Default, Default, ",") _ArrayDisplay($aAnswers, "Results") EndFunc ;==>_GetCheckAnswers #cs ; _FileTo2D($sFileName) function takes a file and returns a 2D array. Example in file"- Tab Label 1.Question 1 A.Answer 1 B.Answer 2 C.Answer 3 2.Question 2 A.Answer 1 B.Answer 2 C.Answer 3 D.Answer 4 E.Answer 5 .... Example returned 2D array:- Tab Label|||||| 1.Question 1|3|A.Answer 1|B.Answer 2|C.Answer 3|| 2.Question 2|5|A.Answer 1|B.Answer 2|C.Answer 3|D.Answer 4|E.Answer 5 .... The return 2D array has:- $a2DArray[0][0] contains the tab's label $a2DArray[n][0] contains Question n $a2DArray[n][1] contains the number of anawers (max 5 answers); $a2DArray[n][2 to 6 inndex] contains the answers; $a2DArray[n + 1][0] contains Question n+1; $a2DArray[n + 1][1] contains the number of anawers to Question n+1; .... ; where n is the question number, or, array index. #ce Func _FileTo2D($sFileName) Local $i Local $iCount = 0 ; 2D array row index - one question with answers on each row. Local $iAnsCount = 0 ; Counts number of answers to each question - Total stored in 2nd column element of 2D array. Local $iIndexAns = 2 ; 2D array column index where to store the answers. $aQA = FileReadToArray($sFileName) ;_ArrayDisplay($aQA) Local $aQA2D[UBound($aQA)][7] $aQA2D[0][0] = $aQA[$iCount] $iCount += 1 For $i = 1 To UBound($aQA) - 1 $aQA2D[$iCount][0] = $aQA[$i] ; Enter Question into 1st element of 2D array. $i += 1 ;While (StringInStr($aQA[$i], "Question", 1) = 0) While (StringRegExp($aQA[$i], "^\d+") = 0) ; <--- Questions start with a digit. So, if 1st character in line is not a digit then continue loop. $aQA2D[$iCount][$iIndexAns] = $aQA[$i] ; Enter Answes into 2D array starting at column index 2. $i += 1 $iAnsCount += 1 $iIndexAns += 1 If $i = UBound($aQA) Then ExitLoop ;ConsoleWrite($i & " " & StringInStr($aQA[$i], "Answer") & " " & $iCount & " " & $iIndexAns & @CRLF) ;_ArrayDisplay($aQA2D) WEnd $iIndexAns = 2 $aQA2D[$iCount][1] = $iAnsCount ; Enter number of Answers into 2nd element of 2D array. $iCount += 1 $iAnsCount = 0 $i -= 1 Next ReDim $aQA2D[$iCount][7] Return $aQA2D EndFunc ;==>_FileTo2D Func XPStyle($theme = 0) If Not StringInStr(@OSType, "WIN32_NT") Then Return 0 If $theme = 0 Or Not IsArray($theme) Then $theme = DllCall("uxtheme.dll", "int", "GetThemeAppProperties") DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0) Return $theme ElseIf IsArray($theme) Then DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $theme[0]) Return $theme EndIf Return 0 EndFunc ;==>XPStyle Func _GUICtrlTabSetBkColor($hWnd, $hSysTab32, $sBkColor) ;Disabled Label to hold the color Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32) GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + 23, $aTabPos[2] - 4, $aTabPos[3] - 26) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetBkColor(-1, $sBkColor) EndFunc ;==>_GUICtrlTabSetBkColor Func _UnCheckRadio() $tPoint = _WinAPI_GetMousePos() $hWnd = _WinAPI_WindowFromPoint($tPoint) $iId = _WinAPI_GetDlgCtrlID($hWnd) ConsoleWrite(GUICtrlRead($iId) & @CRLF) GUICtrlSetState($iId, ((GUICtrlRead($iId) = 4) ? 1 : 4)) ; $GUI_UNCHECKED (4); $GUI_CHECKED (1) EndFunc ;==>_UnCheckRadio
    1 point
  12. Danp2

    Auto Fill Problem

    It's a hack, but you can try this revised version -- Func _FFSendReact($sElement, $sValue = "") If StringLeft($sElement, 7) = "OBJECT|" Then $sElement = StringMid($sElement, 8) If StringLeft($sElement, 1) = "." Then $sElement = "window.content.document" & $sElement _FFCmd('FFau3.sendReact=function sendReact(a,b){try{var c=FFau3.WCD.createEvent("KeyboardEvent");c.initKeyEvent("keypress",true,true,null,false,false,false,false,008,008);a.value=b.concat(".");a.dispatchEvent(c);return 1}catch(e){return-1}return 0};') _FFCmd("FFau3.sendReact(" & $sElement & ",'" & $sValue & "');") EndFunc
    1 point
  13. Danp2

    Auto Fill Problem

    The issue is that the charCode <> keyCode for certain characters such as comma and period, so the posted solution doesn't work as-is. I have an idea for an alternate solution, but haven't worked out all of the details of implementation.
    1 point
  14. Danp2

    Auto Fill Problem

    I don't know why the period isn't being sent successfully. Perhaps there's a better way to implement this code. <shrug>
    1 point
  15. Danp2

    Auto Fill Problem

    Please keep the discussion on the open forum so that everyone can potentially help / benefit.
    1 point
  16. Hello. You can need to use ptr and DllStructCreate to store your byte array. I'm no sure but It would be better if the function support had the byte array length as return. something like (DWORD vstHandle, BOOL isPreset, DWORD* length) Otherwise You will need to allocate an unkown memory space. Edit ;~ public static byte[] BASS_VST_GetChunk( ;~ int vstHandle, ;~ bool isPreset ;~ ) ;~ This could be something like this Local $aRet=DllCall($_ghbassVSTDll,"ptr","BASS_VST_GetChunk","int",$vstHandle,"boolean",$isPreset) Local $tByteArray=DllStructCreate("byte[1024]",$aRet[0]) ;Of couse you need to allocate more than 1024 ;if the dll call allow the return size required (as I said before) if would look like Local $aRet=DllCall($_ghbassVSTDll,"ptr","BASS_VST_GetChunk","int",$vstHandle,"boolean",$isPreset,"dword*",0) ;then you could do something like this to allocate your byte array memory space. Local $tByteArray=DllStructCreate("byte[" & $aRet[3] & "]",$aRet[0]) Saludos
    1 point
  17. @Skysnake I must admit, when I did this I was a complete nab. Okay, I still am. I played with trancexx's Resource Viewer and Compiler but I don't understand all of the code so my attempt to automate the compiling of 300+ icons was still not optimal. It's fast for the first 50 icons, then slows to a crawl. IIRC it was a recursive function that defeated me. Give this a go, it also has the added bonus of not rejecting .ico's with layers 256 x 256 or larger. ResourcesViewerAndCompilerModified.au3 Action -> Initialise compiler Action -> Generate inital dll Drag-and-drop icons in (only one drag-and-drop operation as its late and remember- im a nab) File -> Save as...
    1 point
×
×
  • Create New...