Jump to content

Leaderboard

Popular Content

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

  1. So I think it's time to publish this little tutorial I have made on using DllCall() and DllStructs. It's not near completion but I think it's a good start at least This tutorial is mostly aimed for people who have never used DllCall() before or have very limited knowledge about it. In the future I will update it with more advanced topics so more advanced users can make use of it too. Well here goes. Dealing_with_Dll.pdf Previous downloads: 31 Suggestions, language corrections and errors in the tutorial is of course welcome.
    1 point
  2. UPDATE: With the addition of the ObjCreateInterface function and enhanced COM functionality by trancexxx, these interfaces are now accessible directly in AutoIt. I've rewritten the plugin as a native UDF which will work when compiled as x64 as well. I've attached the new UDF as well as updated plugin and UDF versions of my OSD Volume script. UDF Example: #include <_AudioEndpointVolume.au3> ; ## Get current volume levels $vol = _GetMasterVolumeLevel() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (decibels)" & @CRLF) $vol = _GetMasterVolumeLevelScalar() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (scalar)" & @CRLF) ; ## Set new volume levels ConsoleWrite("Set vol to -20db..." & @CRLF) _SetMasterVolumeLevel(-20) ConsoleWrite("Set Vol Error: " & @error & @CRLF) $vol = _GetMasterVolumeLevel() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (decibels)" & @CRLF) ConsoleWrite("Set vol to scalar 30..." & @CRLF) _SetMasterVolumeLevelScalar(30) ConsoleWrite("Set Vol Error: " & @error & @CRLF) $vol = _GetMasterVolumeLevelScalar() ConsoleWrite("Get Vol Error: " & @error & @CRLF) ConsoleWrite("Volume: " & $vol & " (scalar)" & @CRLF) ; ## Get volume range information ConsoleWrite("Get range info..." & @CRLF) $aInfo = _GetVolumeRange() ConsoleWrite("Get Range Error: " & @error & @CRLF) ConsoleWrite("MinDB: " & $aInfo[0] & @CRLF) ConsoleWrite("MaxDB: " & $aInfo[1] & @CRLF) ConsoleWrite("Increment: " & $aInfo[2] & @CRLF) ; ## Set mute states ConsoleWrite("Set mute on..." & @CRLF) _SetMute(1) ConsoleWrite("Set Mute Error: " & @error & @CRLF) $mute = _GetMute() ConsoleWrite("Get Mute Error: " & @error & @CRLF) ConsoleWrite("Muted: " & $mute & @CRLF) Sleep(2000) ConsoleWrite("Set mute off..." & @CRLF) _SetMute(0) ConsoleWrite("Set Mute Error: " & @error & @CRLF) $mute = _GetMute() ConsoleWrite("Get Mute Error: " & @error & @CRLF) ConsoleWrite("Muted: " & $mute & @CRLF) ; ## Get volume step info ; ## Steps range from 0 to nStepCount - 1 ConsoleWrite("Get step info..." & @CRLF) $aInfo = _GetVolumeStepInfo() ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & $aInfo[0] & @CRLF) ConsoleWrite("Total steps: 0 to " & $aInfo[1] - 1 & @CRLF) ConsoleWrite("Increase 5 steps..." & @CRLF) For $i = 1 To 5 _VolumeStepUp() Next $aInfo = _GetVolumeStepInfo() ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & $aInfo[0] & @CRLF) ConsoleWrite("Decrease 2 steps..." & @CRLF) For $i = 1 To 2 _VolumeStepDown() Next $aInfo = _GetVolumeStepInfo() ConsoleWrite("Get Step Error: " & @error & @CRLF) ConsoleWrite("Current step: " & $aInfo[0] & @CRLF) OLD PLUGIN VERSION vista_vol_plugin.zip _AudioEndpointVolume.au3 VolumeOSD.zip VolumeOSD_plugin.zip
    1 point
  3. Iczer, I only have a red banner - not a green one..... What BrewManNH said. Have you looked at the current function? Firstly, it has nothing to do with arrays and so should not be in this library; next, it is so simple that it should never have been an #include function in the first place; and finally, its awfulness offended even my hobbyist coder sensibility. All, Without wishing to pick on Iczer, that was exactly the sort of post I was hoping not to see - a pure moan rather than sensible comment or reasoned argument about the new/modified functions. I hope my attitude to comments is sufficiently well-known that people realise that I will not take offence if you point out even the stupidest mistakes (that I hope I have not made). All I want is to get a better Array include for the next release - so by all means post, but please make the comments relevant. M23
    1 point
  4. Melba23

    _ArrayAdd issue

    SlowCoder74, Says who? #include <Array.au3> #include <MsgBoxConstants.au3> ; Start with 1 element and delete it Global $aArray[1] = [0] _ArrayDelete($aArray, 0) MsgBox($MB_SYSTEMMODAL, "Size", "Array has " & UBound($aArray) & " items") _ArrayAdd($aArray, "New Item") MsgBox($MB_SYSTEMMODAL, "Size", "Array has " & UBound($aArray) & " items") ; Or just start with none in the first place Global $aArray[0] MsgBox($MB_SYSTEMMODAL, "Size", "Array has " & UBound($aArray) & " items") _ArrayAdd($aArray, "New Item") MsgBox($MB_SYSTEMMODAL, "Size", "Array has " & UBound($aArray) & " items") M23
    1 point
  5. water

    _ArrayAdd issue

    With the latest stable version of AutoIt (3.3.10.x) you can have empty arrays: Local $aMyArray[0] The Array UDF supports empty arrays in 3.3.10.x.
    1 point
  6. A good lesson to learn indeed. One of my first scripts saved a reg hive and then parsed through it. You don't notice the extreme difference until you test out something like this: 11 seconds For $i = 1 To 10000 FileWriteLine(@DesktopDir & "\Test.txt", "Line " & $i) Next Vs. this: .767 seconds $sFile = FileOpen(@DesktopDir & "\Test.txt", 1) For $i = 1 To 10000 FileWriteLine($sFile, "Line " & $i) Next FileClose($sFile)
    1 point
  7. your getting one error and disregarding it expecting some other error that cant b shown coz your getting all the time other error... so what is that error and why are you disregarding it? just a quick note that _IELoadWait do have 2x Sleep(100) on its loops and i dnot know how fast is readyState returned
    1 point
  8. trancexx

    Obfuscator suggestions

    Who are ALL others? I remember when I was suggesting adding one particular feature to AutoIt, I was turned off because "it can't be done", because "if it would be possible other languages would have had it already", because "at least one would have done it before you". Later when I added it to the language, making it unique therefore, it was "Oh cool, it's possible". Your "ALL others" is invalid argument. I invented the current compiler which is better and more correct than the old one, and I invented new compiler which is better and more correct than the current. Why is that hard for you or anyone else to believe really isn't something I'll be losing sleep over. ...And saying I'm cracking jokes. Ouch.
    1 point
  9. Alexxander, Use _FileReadToArrayRec - that will list the files in subfolders as well if you set it up correctly. M23
    1 point
  10. Alexxander, If you are going to carry out multiple actions on a file it is quicker to open it, use the returned handle to identify the file for the actions and then close it again once everything is done. If you use the file name to identify the file then it is opened and closed for each action - the overhead for every action makes this method demonstrably slower. Of course, if all you are doing is a single write then there is no appreciable difference. But you must choose either one method or the other - do not mix file handles and filenames or it will end in tears. M23
    1 point
  11. I'm sorry to hear your experience here. Fortunetely, this is not most new members feel, including me. Me myself have been helped a lot by moderator and senior members here and now I'm trying (with my limited knowledge and experience) to help new members as much as I can. I think one of the most important thing is attitude. So behave. Anyway, I wonder who actually need who?
    1 point
  12. 1 point
  13. MISSION ACCOMPLISHED! Except for the SQL stuff I took out, this has now reached awesome! Enjoy! #include <GUIConstantsEx.au3> #include <Array.au3> #Include <GuiListBox.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ComboConstants.au3> Global $hGUI Global $hInput Global $hList Global $sPartialData Global $output = '' Local $conn = ObjCreate( "ADODB.Connection" ) Local $DSN = "DRIVER={SQL Server};SERVER=MyServer;DATABASE=MyDB;uid=MyUID;pwd=MyPaSsWoRd;" SQLQuery() $hGUI = GUICreate("Example", 200, 400) $hInput = GUICtrlCreateInput("", 5, 5, 190, 20) $hList = GUICtrlCreateList("", 5, 30, 190, 225, BitOR(0x00100000, 0x00200000)) GUICtrlSetLimit(-1, 20) GUICtrlSetState($hList, $GUI_Hide) $hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30) $hUP = GUICtrlCreateDummy() $hDOWN = GUICtrlCreateDummy() $hENTER = GUICtrlCreateDummy() GUISetState(@SW_SHOW, $hGUI) Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]] GUISetAccelerators($AccelKeys) $sCurr_Input = "" $iCurrIndex = -1 GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hList $sChosen = GUICtrlRead($hList) If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen) GUICtrlSetState($hList, $GUI_Hide) endif Case $hButton If $sPartialData <> "" Then $sFinal = GUICtrlRead($hInput) If _ArraySearch($MyVal, $sFinal) > 0 Then MsgBox(0, "Chosen", $sFinal) EndIf EndIf Case $hUP If $sPartialData <> "" Then $iCurrIndex -= 1 If $iCurrIndex < 0 Then $iCurrIndex = 0 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hDOWN If $sPartialData <> "" Then $iTotal = _GUICtrlListBox_GetCount($hList) $iCurrIndex += 1 If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hENTER If $iCurrIndex <> -1 Then $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex) GUICtrlSetData($hInput, $sText) GUICtrlSetState($hList, $GUI_Hide) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf EndSwitch If GUICtrlRead($hInput) <> $sCurr_Input Then CheckInputText() $sCurr_Input = GUICtrlRead($hInput) EndIf WEnd Func CheckInputText() $sPartialData = "|" Local $sInput = GUICtrlRead($hInput) If $sInput <> "" Then For $i = 0 To Ubound($MyVal) - 1 If StringInStr($MyVal[$i], $sInput) <> 0 Then $sPartialData &= $MyVal[$i] & "|" Next GUICtrlSetData($hList, $sPartialData) EndIf EndFunc ;==>CheckInputText Func WM_COMMAND($hWnd, $msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAND($wParam, 0x0000FFFF) If $nID = $hInput Then $hCtrl = $lParam If $nNotifyCode = $EN_CHANGE Then $txt = GUICtrlRead($hInput) For $n = 1 To UBound($MyVal) - 1 ;Msgbox(0,"Records found: " & $n, $MyVal[$n]) If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then GUICtrlSetData($hList, $MyVal[$n]) if GUICtrlRead($hInput) then GUICtrlSetState($hList, $GUI_show) else GUICtrlSetState($hList, $GUI_Hide) endif ExitLoop EndIf Next EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func SQLQuery() $conn.Open($DSN) $rs = ObjCreate( "ADODB.RecordSet" ) $rs.Open( "@@ PUT QUERY HERE @@", $conn ) If $RS.RecordCount Then While Not $RS.EOF $output = $output & StringStripWS($RS.Fields("@@ PUT TABLE HERE @@").Value,8) & "|" ; value of 4 columns on this line $RS.MoveNext WEnd EndIf global $MyVal = StringSplit($output,"|") $conn.close $sData = $output GUICtrlSetData($hList, $sData) $iCurrIndex = -1 _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndFunc Thank you everyone of the help! And if anyone is dealing with SQL issues and searches, go ahead and use this. Dont forget to put the query and table at the bottom replacing the @@ signs
    1 point
  14. taietel

    GUI design concepts.

    I use this template in my projects: #include <GuiConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #region GLOBAL VARIABLES Global $iW = 600, $iH = 400, $iT = 52, $iB = 52, $iLeftWidth = 150, $iGap = 10, $hMainGUI #endregion GLOBAL VARIABLES _MainGui() Func _MainGui() Local $hFooter, $nMsg, $aPos Local $iLinks = 5 Local $sMainGuiTitle = "Sample Title" Local $sHeader = "Sample GUI" Local $sFooter = "2012 © AutoIt" Local $aLink[$iLinks], $aPanel[$iLinks] $aLink[0] = $iLinks - 1 $aPanel[0] = $iLinks - 1 $hMainGUI = GUICreate($sMainGuiTitle, $iW, $iH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP)) GUISetIcon("shell32.dll", -58, $hMainGUI) GUICtrlCreateLabel($sHeader, 48, 8, $iW - 56, 32, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 14, 800, 0, "Arial", 5) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) GUICtrlCreateIcon("shell32.dll", -131, 8, 8, 32, 32) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) GUICtrlCreateLabel("", 0, $iT, $iW, 2, $SS_SUNKEN);separator GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT) GUICtrlCreateLabel("", $iLeftWidth, $iT + 2, 2, $iH - $iT - $iB - 2, $SS_SUNKEN);separator GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUICtrlCreateLabel("", 0, $iH - $iB, $iW, 2, $SS_SUNKEN);separator GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT) $hFooter = GUICtrlCreateLabel($sFooter, 10, $iH - 34, $iW - 20, 17, BitOR($SS_LEFT, $SS_CENTERIMAGE)) GUICtrlSetTip(-1, "AutoIt Forum", "Click to open...") GUICtrlSetCursor(-1, 0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT) ;add links to the left side $aLink[1] = _AddNewLink("Link 1") $aLink[2] = _AddNewLink("Link 2", -167) $aLink[3] = _AddNewLink("Link 3", -222) $aLink[4] = _AddNewLink("Link 4", -22) ;and the corresponding GUI's $aPanel[1] = _AddNewPanel("Title for the panel 1") $aPanel[2] = _AddNewPanel("Title for the panel 2") $aPanel[3] = _AddNewPanel("Title for the panel 3") $aPanel[4] = _AddNewPanel("Title for the panel 4") ;add some controls to the panels _AddControlsToPanel($aPanel[1]) GUICtrlCreateEdit("", 10, 37, $iW - $iLeftWidth + 2 - 20 - 5, $iH - $iT - $iB - 40, BitOR($ES_AUTOVSCROLL, $ES_NOHIDESEL, $ES_WANTRETURN, $WS_VSCROLL), $WS_EX_STATICEDGE) Local $sTestTxt = "" For $i = 1 To 10 $sTestTxt &= @TAB & "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum felis lectus, pharetra vel laoreet nec, pulvinar nec justo. Donec malesuada, nunc eu faucibus sodales, diam sem tempor neque, id condimentum turpis nunc vel lacus. Nulla a nulla libero, eget eleifend dolor. Vivamus volutpat tincidunt ultricies. Vestibulum eu libero nisi, quis tincidunt nisi. Proin tincidunt, ipsum ullamcorper posuere venenatis, libero nulla venenatis enim, ultrices tincidunt ipsum arcu nec turpis. In at erat sed ipsum gravida mattis in at felis. Vivamus diam purus, dictum ut luctus vitae, sollicitudin ut velit. Maecenas velit mauris, fringilla ut condimentum bibendum, aliquam a neque. Nulla metus eros, commodo id dictum in, interdum sed ipsum. Vivamus feugiat, mi at auctor fringilla, libero lectus vulputate tortor, eu sollicitudin nulla lacus at neque." & @CRLF $sTestTxt &= @TAB & "Sed vel ante magna. Curabitur porttitor ante in tellus bibendum non tristique diam volutpat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In tellus lectus, ultrices in tempus eget, sollicitudin quis eros. Curabitur at arcu bibendum massa feugiat euismod at a felis. Nunc molestie, enim non ornare tincidunt, ipsum nisi tempus sapien, quis elementum elit velit ut neque. Suspendisse eu adipiscing risus. Nam tempor odio ut elit auctor rhoncus. Etiam viverra elit id felis feugiat pellentesque pretium porttitor dui. Vivamus eu quam non ante suscipit vehicula a nec eros. Phasellus congue massa sed libero interdum ullamcorper. Quisque fringilla massa ut lorem fringilla pulvinar eget ullamcorper eros. Praesent faucibus, erat at consequat tempus, nulla erat sodales mi, eget sagittis nibh erat nec nunc. Phasellus risus nibh, porta viverra pretium nec, vehicula eget nisi." & @CRLF $sTestTxt &= @TAB & "Sed vel neque vel urna elementum accumsan feugiat quis mauris. Sed mi nisl, consequat dapibus molestie ac, rutrum ut elit. Praesent sed risus sem. Mauris rutrum blandit magna nec tristique. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse consequat iaculis odio nec cursus. Duis varius tincidunt ligula ac ultricies. Ut eget magna in nulla vulputate dapibus ut vel sem. Integer ac tempor risus." & @CRLF $sTestTxt &= @TAB & "Maecenas molestie semper turpis, id tristique nibh pharetra eget. Aliquam erat volutpat. In egestas, lorem quis varius vestibulum, enim diam porta lorem, quis dictum arcu ante a diam. Nullam vel nisi mauris. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam ut leo purus, eget vulputate augue. Fusce et est sagittis felis accumsan sollicitudin eget a lectus. Cras sapien sapien, rutrum eu tempor non, tempor nec velit. Vivamus interdum adipiscing felis in malesuada. Fusce quis purus est, eget molestie turpis. In hac habitasse platea dictumst." & @CRLF $sTestTxt &= @TAB & "Aenean eleifend risus vitae lorem laoreet facilisis. Suspendisse ac urna quam, vel rutrum sem. Sed bibendum porta tellus malesuada scelerisque. Vestibulum at ligula sed nulla sollicitudin tincidunt. Pellentesque mi magna, vulputate et aliquam a, auctor et nunc. Phasellus feugiat fringilla accumsan. Donec ultrices, elit id dapibus auctor, nunc odio viverra lorem, non commodo mi libero a libero. Cras vitae felis venenatis augue laoreet tincidunt scelerisque id odio. Proin lorem purus, molestie feugiat pretium nec, ornare aliquam turpis. " Next GUICtrlSetData(-1, $sTestTxt) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM) _AddControlsToPanel($aPanel[2]) GUICtrlCreateLabel("Label1", 8, 38, 36, 17) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Local $hInput1 = GUICtrlCreateInput("Input1", 56, 35, 121, 21) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Local $hButton1 = GUICtrlCreateButton("Button1", 200, 33, 75, 25) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) _AddControlsToPanel($aPanel[3]) GUICtrlCreateList("", 8, 37, 121, 93, -1, 0) GUICtrlSetData(-1, "dfgdfg|ertert|kljlkj|poipoi|qweqwe") GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) _AddControlsToPanel($aPanel[4]) GUICtrlCreateGroup("Group1", 8, 35, 129, 90) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Local $aChkBox[4] For $i = 1 To 3 $aChkBox[$i] = GUICtrlCreateRadio("Some radio " & $i, 16, 56 + ($i - 1) * 20, 113, 17) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Next GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateGroup("", -99, -99, 1, 1) ;set default to Panel1 GUISwitch($aPanel[1]) ;show the main GUI GUISetState(@SW_SHOW, $hMainGUI) While 1 Sleep(10) $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hMainGUI Switch $nMsg[0] Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE $aPos = WinGetPos($hMainGUI) $iW = $aPos[2] $iH = $aPos[3] For $i = 0 To $aPanel[0] WinMove($aPanel[$i], "", $iLeftWidth + 2, $iT, $iW - $iLeftWidth + 2, $iH - $iT - $iB - 20) Next Case $aLink[1], $aLink[2], $aLink[3], $aLink[4] For $i = 1 To $aLink[0] If $nMsg[0] = $aLink[$i] Then GUISetState(@SW_SHOW, $aPanel[$i]) Else GUISetState(@SW_HIDE, $aPanel[$i]) EndIf Next Case $hFooter ShellExecute("http://www.autoitscript.com/forum/topic/146952-gui-design-concepts/") EndSwitch Case $aPanel[2] Switch $nMsg[0] Case $hButton1 MsgBox(32, "Test", "You have " & GUICtrlRead($hInput1) & "?") EndSwitch Case $aPanel[4] Switch $nMsg[0] Case $aChkBox[1], $aChkBox[2], $aChkBox[3] For $i = 1 To 3 If GUICtrlRead($aChkBox[$i]) = $GUI_CHECKED Then MsgBox(64, "Test", "You checked nr. " & $i & "!") Next EndSwitch EndSwitch WEnd EndFunc ;==>_MainGui Func _AddNewLink($sTxt, $iIcon = -44) Local $hLink = GUICtrlCreateLabel($sTxt, 36, $iT + $iGap, $iLeftWidth - 46, 17) GUICtrlSetCursor(-1, 0) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) GUICtrlCreateIcon("shell32.dll", $iIcon, 10, $iT + $iGap, 16, 16) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) $iGap += 22 Return $hLink EndFunc ;==>_AddNewLink Func _AddNewPanel($sTxt) Local $gui = GUICreate("", $iW - $iLeftWidth + 2, $iH - $iT - $iB, $iLeftWidth + 2, $iT, $WS_CHILD + $WS_VISIBLE, -1, $hMainGUI) GUICtrlCreateLabel($sTxt, 10, 10, $iW - $iLeftWidth - 20, 17, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 9, 800, 4, "Arial", 5) GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Return $gui EndFunc ;==>_AddNewPanel Func _AddControlsToPanel($hPanel) GUISwitch($hPanel) EndFunc ;==>_AddControlsToPanel
    1 point
  15. I was searching Google for something and it led me to this link. After looking at it, and looking at guinness's concerns, I'd like to chime in. 1. IMO, there's no error for a function like this. The person(s) using the function are responsible for managing their parameters. 2. Anything using DllStruct-Create/GetData whatever, is going to be slower normally than a simple concatenation. The only time I could see this being different maybe, is if the strings are huge and memory starts to get eaten up, but AutoIt's memory management is pretty well setup, so I don't see that really happening. This is true for single Chars or 2+Chars. 3. StringFormat(); well, it's not meant for speed, that's for sure. Long story short, the only way I can see it being faster: 1. For long strings, dllcall to dll that manages the data itself without having to manage struct usage inside AutoIt. 2. Get rid of error checking. 3. We can save 1 loop cycle doing it the below way. Func _StringRepeat($sString, $nCount) If $sString = Chr(0) Then Return Local $sRStr = $sString For $i = 1 To Int($nCount) - 1 $sRStr &= $sString Next Return $sRStr EndFunc Edit: This may be faster even: Func _StringRepeat($sString, $nCount) Local $iLen = StringLen($sString) If $iLen = 0 Then Return Local $iMax = $iLen * $nCount While StringLen($sString) < $iMax $sString &= $sString WEnd Return StringLeft($sString, $iMax) EndFunc Edit2: The last one has my vote. After benchmarking each, it was the most consistent in time to finish ( loops tested from 1 to 500 repeats over and over ). At a certain point, it was never more than 3 or 4 milliseconds, while the others were 10, 20, 30+ milliseconds as the string grew (makes sense).
    1 point
  16. #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** And needed to add this code on top of your script.
    1 point
  17. Inverted

    NumLock toggle

    I made this for a friend. It sets NumLock On at start of the script and has a 'NumLock toggle' tray option. Tray icon changes indepedently according to the state of NumLock. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Res_Icon_Add="C:STUFFAutoit_stuffNumLockControlon.ico" #AutoIt3Wrapper_Res_Icon_Add="C:STUFFAutoit_stuffNumLockControloff.ico" #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Opt("SendAttachMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) TraySetClick(16) Send("{NUMLOCK on}") TrayCreateItem("Toggle NumLock") TrayItemSetOnEvent(-1, "toggleNumLock") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") While 1 updateTrayIcon() Sleep(100) WEnd Func toggleNumLock() Send("{NUMLOCK toggle}") EndFunc Func updateTrayIcon() $sState = _WinAPI_GetKeyState(0x90) If $sState Then TraySetIcon(@ScriptFullPath, -5) Else TraySetIcon(@ScriptFullPath, -6) EndIf EndFunc Func ExitScript() Exit EndFunc Func _WinAPI_GetKeyState($vkCode) Local $Ret = DllCall('user32.dll', 'int', 'GetKeyState', 'int', $vkCode) Return $Ret[0] EndFunc Compiled script exe for convenience : http://speedy.sh/6sVtN/NumLockControl.zip It only seems to work fine in win7 x64 but not in my XP virtual machine. I don't know if it's because of Virtualbox keyboard hooking or just XP incompatibility. Pleaselet me know if it works on real XP.
    1 point
  18. tip

    MsgBox_Tipped UDF

    Greetings , Some time ago I needed a custom msgbox function to use in my scripts. In time, it evolved to create quite eye candy msgboxes . It is not a very complex UDF but it does a lot of cool things without bothering user with the details. So, I thought I'd share... UDF uses some functions written by me as well as several UDF's, published by other scripters, that I gathered through time. I tried to give proper credits to each. If I did forget to mention anyone or if I have provided inaccurate information, my sincere apologies... Please let me know and I gladly make necessary corrections. I've tried to keep the syntax as clean and as easy-to-use as I can. That's why I didn't include features like custom font, custom position, timer etc. If you decide to add those parameters, you'll notice that I also tried to keep main function organized and such parameters can easily be implemented. There is always room for improvement. Please share your opinions and ideas. I'm really looking forward to your feedback. Sincerely, Tip ScreenShots: Change Log: MsgBox_Tipped Ex.zip
    1 point
  19. I knew it was possible to request a specific part of a file using the Range header, but I never tried it, so I decided to check it out. While my example is very rough and has only minimal errorchecking it seems to work ok with most files I tested it on. If you point this example to an existing destingation file, it will assume that this is a continuation of a previous download. And request to resume the download from the last downloaded byte. This means you can continue downloading the same file from a different location, but it also means that you can really mess up the destination file if it's not the same as what you are trying to download. If the file if 800 Kb it will request the download to start at the 801 byte untill complete. It can be made to handle multiple simultanious downloads. I wouldn't advise using the code as is, but it should allow you to come up with something yourself. #include "WinHttp.au3" #include <GUIConstantsEx.au3> Global $sBigFileUrl = ;Find the url to reasonably large file here. I googled a big picture for testing, which allowed me to open the incomplete file, see a part missing, finish the download and get complete picture as a result. Global $sBigFileDest = @ScriptDir & "\Bigfile.jpg" Global $aDownload[3] GUICreate("Test",500,300) Global $GuiCtrlButtonStart = GUICtrlCreateButton("Start",10,10,200) Global $GuiCtrlButtonStop = GUICtrlCreateButton("Stop",250,10,200) GUICtrlSetState($GuiCtrlButtonStop, $GUI_DISABLE) Global $GuiCtrlEdit = GUICtrlCreateEdit("",10,40,450,250) GUISetState() Global $hOpen = _WinHttpOpen() While 1 Switch GUIGetMsg() Case -3 _WinHttpCloseHandle($hOpen) Exit Case $GuiCtrlButtonStart $aDownload = _StartDownload($sBigFileUrl, $sBigFileDest) If @error Then _EditWrite("Couldn't start/resume download") Else _EditWrite("Download started") EndIf Case $GuiCtrlButtonStop _EditWrite("Download interrupted") _StopDownload($aDownload) EndSwitch If $aDownload[1] Then _AppendToFile($aDownload) WEnd Func _StartDownload($sUrl, $sDest) Local $aReturn[3] Local $aUrl = _WinHttpCrackUrl($sURL) If @error Then Return SetError(1,0,$aReturn) Local $hConnect = _WinHttpConnect($hOpen, $aUrl[2]) If @error Then Return SetError(2,0,$aReturn) Local $hRequest = _WinHttpOpenRequest($hConnect,"GET",$aUrl[6] & $aUrl[7]) If @error Then _WinHttpCloseHandle($hConnect) Return SetError(3,0,$aReturn) EndIf If FileExists($sDest) Then _WinHttpAddRequestHeaders($hRequest, "Range: bytes=" & FileGetSize($sDest) & "-") ;I used FileSize+1 before, but it distorted the picture. _EditWrite("There seems to be " & FileGetSize($sDest) & "kb downloaded already") Else _EditWrite("Creating a new file") EndIf _WinHttpSendRequest($hRequest) If @error Then _WinHttpCloseHandle($hConnect) Return SetError(4,0,$aReturn) EndIf _WinHttpReceiveResponse($hRequest) If @error Then _WinHttpCloseHandle($hConnect) Return SetError(5,0,$aReturn) EndIf If StringInStr(_WinHttpQueryHeaders($hRequest),"HTTP/1.1 416 Requested Range Not Satisfiable") Then _WinHttpCloseHandle($hConnect) Return SetError(6,0,$aReturn) EndIf $aReturn[0] = $hConnect $aReturn[1] = $hRequest $aReturn[2] = FileOpen($sDest,17) GUICtrlSetState($GuiCtrlButtonStop, $GUI_ENABLE) GUICtrlSetState($GuiCtrlButtonStart, $GUI_DISABLE) Return $aReturn EndFunc Func _AppendToFile(ByRef $aDownload) Local $bChunk = _WinHttpReadData($aDownload[1],2) If @error Then _EditWrite("Download complete") _StopDownload($aDownload) Return EndIf FileWrite($aDownload[2], $bChunk) EndFunc Func _StopDownload(ByRef $aDownload) _WinHttpCloseHandle($aDownload[0]) _WinHttpCloseHandle($aDownload[1]) FileClose($aDownload[2]) $aDownload[0] = False $aDownload[1] = False $aDownload[2] = False GUICtrlSetState($GuiCtrlButtonStop, $GUI_DISABLE) GUICtrlSetState($GuiCtrlButtonStart, $GUI_ENABLE) _EditWrite("Downloaded " & FileGetSize($sBigFileDest) & "kb to file") _EditWrite("Download stopped") Return EndFunc Func _EditWrite($sMsg) GUICtrlSetData($GuiCtrlEdit, GUICtrlRead($GuiCtrlEdit) & @CRLF & $sMsg) EndFunc P.S. The range header actually allows you to request any range of bytes you desire, so it could even be used to split your download in blocks and download all blocks from different locations, putting the file together as you go. P2P style. I doubt it's worth the hassle though.
    1 point
×
×
  • Create New...