Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/03/2016 in all areas

  1. A smart compiler can optimise memory storage better if it knows in advance that a particular subset of variables will not ever be resized. This can reduce fragmentation of virtual memory.
    2 points
  2. I started to work on this UDF and I'd like to discuss, test and improve it with other interested users. The idea is to create a UDF similar to FTPEx, but to support SFTP protocol. Given that this protocol is not natively supported by Windows, I found some candidates to manage it: cURL: http://curl.haxx.se/ PSFTP: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html FZSFTP: http://filezilla-project.org/ I'm trying to use the second one (realied by PuTTY team) and the result is the following code. It is not complete and needs to be widely tested, but main functions work and could be considered as a draft to start the discussion. A possible alternative could be to use FZSFTP (a modified version of PSFTP realized for FileZilla), that includes some interesting improvements to be used by external programs, but does not offer a related documentation. Code version: 1.0 beta 9 (not complete) Previous downloads: 132 SFTPEx.au3
    1 point
  3. Gianni

    Array viewer

    This script allows you to 'browse' an array and view it's content. It's similar to the _ArrayDisplay() command, but this one has no limit on the number of dimensions. Nested array (array of arrays) are also allowed. (I'm been inspired by this @JohnOne's Post) Since multidimensional arrays can be considered as many bidimensional arrays grouped toghether, with this script you can view any of the many 2d arrays by selecting the dimension (the sheet number) you want to see through the ComboBoxes located at the top of the viewed sheet. regarding the arrays of array, if are present, those are listed on the treeview on the left side, where you can see their locations within the tree, and easily selected to be as well browsed by a click. I'm aware that there is a wide margin of aesthetic improvement, anyway the basic functionality works quite well. I hope it can be usefull ; Func _ArrayView() ; Will display content of arrays of any dimension, and even nested arrays if any ; #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GUITreeView.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> #include <ComboConstants.au3> #include <GuiStatusBar.au3> ; -- build an example array (somewhat chaotic.. just to show something) -- ; 4D array (main array) Local $aA[10][5][6][3] For $d1 = 0 To 9 For $d2 = 0 To 4 For $d3 = 0 To 5 For $d4 = 0 To 2 $aA[$d1][$d2][$d3][$d4] = $d1 & "." & $d2 & "." & $d3 & "." & $d4 Next Next Next Next ; some 1D arrays with multi nested arrays Local $aMonths1 = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] Local $aMonths2 = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", $aMonths1] Local $aMonths3 = ["Sijecanj", "veljaca", "ožujka", "travanj", "Svibanj", "lipanj", "srpanj", "kolovoz", "rujan", "listopad", "studeni", "prosinac", $aMonths2] Local $aMonths4 = ["Janvier", "Février", "Mars", "Avril", "mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre", $aMonths3] Local $aMonths5 = ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'giu', 'Luglio', 'Agosto', 'Settembre', 'ottobre', 'Novembre', 'Dicembre', $aMonths4] Local $aMonths = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", $aMonths5] ; a simple 2D array Local $aWeekdays = [['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], _ ['Lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato', 'domenica'], _ ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'], _ ['Måndag', 'tisdag', 'onsdag', 'torsdag', 'fredag', 'lördag', 'söndag'], _ ['Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota', 'Niedziela'], _ ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag']] ; array $aMonths goes in cell [5][3] dimension [0][0] of main array $aA[5][3][0][0] = $aMonths ; array $aWeekdays goes in cell [6][3] dimension [0][0] of main array $aA[6][3][0][0] = $aWeekdays $aWeekdays[1][1] = $aWeekdays ; self nest $aWeekdays in cell [1][1] $aA[9][4][0][1] = $aWeekdays ; new $aWeekdays goes in cel [9][4] dimension [0][1] of main array _ArrayView($aA) ; show main array ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayView ; Description ...: Allows to view content of amono or multidimensional array. Array of arrays are also allowed ; Syntax ........: _ArrayView(Byref $_aInput) ; Parameters ....: $_aInput - The array that you want to 'Browse' ; Return values .: on success returns 1 ; on faillure returns 0 and set @Error to 1 (passed argument is not an array) ; Author ........: @Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _ArrayView(ByRef $_aInput) If Not IsArray($_aInput) Then Return SetError(1, 0, 0) ; if error set @Error and return 0 Local $iGUIwidth = 900 Local $iGUIheight = 600 Local $iTreeWidth = 150 Local $iCombosZone = 60 Local $hGui = GUICreate("Array viewer", $iGUIwidth, $iGUIheight) Local $StatusBar = _GUICtrlStatusBar_Create($hGui), $iStatusBarheight = 23 Local $aSubscripts[64][4] ; It holds IDs of controls ; - creates all ComboBox in an embedded window. All controls are hidden at startup. ; - Only the necessary combo will be shown at run time. One combo for each dimension Local $hSubscriptSelectors = GUICreate('', $iGUIwidth - $iTreeWidth - 6, $iCombosZone - 2, $iTreeWidth + 4, 2, BitOR($WS_CHILD, $WS_HSCROLL), -1, $hGui) ; GUISetBkColor(0xEEFFEE) For $i = 0 To 63 ; Create the labels $aSubscripts[$i][0] = GUICtrlCreateLabel('D' & $i + 1, ($i * 60) + 8, 1) GUICtrlSetFont(-1, 10, 0, 0, "Courier new") GUICtrlSetState(-1, $GUI_HIDE) ; Labels will be hidden at startup. $aSubscripts[$i][1] = GUICtrlCreateLabel('[', ($i * 60), 18) GUICtrlSetFont(-1, 13, 800) GUICtrlSetState(-1, $GUI_HIDE) $aSubscripts[$i][3] = GUICtrlCreateLabel(']', ($i * 60) + 50, 18) GUICtrlSetFont(-1, 13, 800) GUICtrlSetState(-1, $GUI_HIDE) Next For $i = 0 To 63 ; Create the ComboBox (creates separatelly from labels so that ControlIDs of ComboBaxes has it's own sequence) GUICtrlSetState(-1, $GUI_HIDE) ; ComboBox will be hidden at startup. If $i < 2 Then ; all the content of the first 2 dimensions is already shown in the listview (no need of ComboBox) $aSubscripts[$i][2] = GUICtrlCreateCombo("---", ($i * 60) + 8, 17, 40, -1, $CBS_DROPDOWNLIST) GUICtrlSetState(-1, $GUI_DISABLE) Else $aSubscripts[$i][2] = GUICtrlCreateCombo("0", ($i * 60) + 8, 17, 40, -1, $CBS_DROPDOWNLIST) EndIf GUICtrlSetFont(-1, 8, 800) GUICtrlSetState(-1, $GUI_HIDE) ; ComboBox hidden at startup. Next GUISwitch($hGui) ; back to main window ; Create the TreeView structure $hTree = GUICtrlCreateTreeView(2, 2, $iTreeWidth - 2, $iGUIheight - 4 - $iStatusBarheight, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Local $hRoot = _GUICtrlTreeView_Add($hTree, 0, "Root") ; first insert the root key in treeview _ArrayTraverse($_aInput, $hTree, $hRoot) ; Search for SubArrays (array in array) ; Create the ListView Local $idListview = GUICtrlCreateListView('', $iTreeWidth + 2, $iCombosZone + 2, $iGUIwidth - $iTreeWidth - 4, $iGUIheight - $iCombosZone - 4 - $iStatusBarheight, Default, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES)) ; If Array has many dimensions, and so all ComboBoxes doesn't fit in window, this allows to scroll GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") _GUIScrollBars_Init($hSubscriptSelectors, 60 * UBound($_aInput, 0), 0) GUISetState(@SW_SHOW, $hGui) GUISetState(@SW_SHOW, $hSubscriptSelectors) ; Main Loop until the user exits. ; ------------------------------- Local $sLastWholeKey, $sWholeKey, $vContent, $bRebuild While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE GUIDelete($hGui) ExitLoop Case $aSubscripts[2][2] To $aSubscripts[63][2] ; some ComboBox has changed _ArrayDisplayByLayer($vContent, $idListview, $aSubscripts, False) EndSwitch ; $sWholeKey = _GUICtrlTreeView_GetTree($hTree, _GUICtrlTreeView_GetSelection($hTree)) If $sLastWholeKey <> $sWholeKey Then ; clicked on a new KeyPath or (again) on the one already selected? GUISetCursor(15, 1) ; set cursor to "wait" ; Adapt the TreePath to the array access syntax $sElement = _TreePathParser($sWholeKey) ; address of main array or subarray to peek _GUICtrlStatusBar_SetText($StatusBar, StringReplace($sWholeKey, '|', '->') & ' --> ' & $sElement) ; show the 'address' of selected element on statusbar $vContent = Execute(_TreePathParser($sWholeKey)) _ArrayDisplayByLayer($vContent, $idListview, $aSubscripts, True) _GUICtrlTreeView_ClickItem($hTree, _GUICtrlTreeView_GetSelection($hTree)) $sLastWholeKey = $sWholeKey ; keep track of already clicked KeyPath so we will not redraw the same Array if clicked again GUISetCursor() ; cursor back to default EndIf ; WEnd Return SetError(0, 0, 1) ; if no errors return 1 EndFunc ;==>_ArrayView Func _ArrayDisplayByLayer(ByRef $_aInput, ByRef $idListview, ByRef $aSubscripts, $bRebuild = False) Opt('GUIOnEventMode', 1) ; Disable GUIGetMsg() so is not fired while redrawing ComboBoxes. Local $sTarghet = '$_aInput[$y]' Local $iDimensions = UBound($_aInput, 0) Local $iRows = UBound($_aInput, 1) Local $iColumnsCount, $iColumns = UBound($_aInput, 2) Local $sSubscripts = '' ; Clear the ListView _GUICtrlListView_DeleteAllItems($idListview) If $bRebuild Then ; (Re)Create the ListView $iColumnsCount = _GUICtrlListView_GetColumnCount($idListview) If $iColumnsCount Then For $i = $iColumnsCount To 1 Step -1 _GUICtrlListView_DeleteColumn($idListview, $i - 1) Next EndIf ; Hide and clear all ComboBox For $i = 0 To 63 GUICtrlSetState($aSubscripts[$i][0], $GUI_HIDE) ; Header GUICtrlSetState($aSubscripts[$i][1], $GUI_HIDE) ; '[' GUICtrlSetState($aSubscripts[$i][2], $GUI_HIDE) ; ComboBox Handle GUICtrlSetData($aSubscripts[$i][2], '') ; clear ComboBox items GUICtrlSetState($aSubscripts[$i][3], $GUI_HIDE) ; ']' Next ; (Re)Build the ListView's frame If $iDimensions = 1 Then $iColumns = 1 Else $iColumns = UBound($_aInput, 2) ; nr. of columns in the ListView (second dimension) $sTarghet &= '[$x]' EndIf _GUICtrlListView_AddColumn($idListview, 'Row') For $i = 1 To $iColumns _GUICtrlListView_AddColumn($idListview, 'Col ' & $i - 1, 100) Next For $i = 0 To $iDimensions - 1 ; Show only necessary ComboBox (one for each dimension) GUICtrlSetState($aSubscripts[$i][0], $GUI_SHOW) ; Header GUICtrlSetState($aSubscripts[$i][1], $GUI_SHOW) ; '[' GUICtrlSetState($aSubscripts[$i][2], $GUI_SHOW) ; ComboBox Handle GUICtrlSetState($aSubscripts[$i][3], $GUI_SHOW) ; ']' If $i > 1 Then $sTarghet &= '[0]' ; dimensions over the second all setting to 0 (begin showing first lyer) $sSubscripts = "" For $iSubscript = 0 To UBound($_aInput, $i + 1) - 1 $sSubscripts &= $iSubscript & '|' Next GUICtrlSetData($aSubscripts[$i][2], StringTrimRight($sSubscripts, 1)) ControlFocus('', '', $aSubscripts[$i][2]) ControlSend('', '', $aSubscripts[$i][2], 0) EndIf Next Else ; Just refill the listview with data from the Array dimension selected by ComboBoxes ; Create the 'dimension' string $sTarghet &= '[$x]' For $i = 2 To $iDimensions - 1 $sTarghet &= '[' & GUICtrlRead($aSubscripts[$i][2]) & ']' Next $iColumns = UBound($_aInput, 2) EndIf For $y = 0 To $iRows - 1 GUICtrlCreateListViewItem('', $idListview) _GUICtrlListView_SetItemText($idListview, $y, '[' & $y & ']', 0) ; row number For $x = 0 To $iColumns - 1 $vCellContent = Execute($sTarghet) If IsArray($vCellContent) Then _GUICtrlListView_SetItemText($idListview, $y, '{array}', $x + 1) Else _GUICtrlListView_SetItemText($idListview, $y, $vCellContent, $x + 1) EndIf Next Next Opt('GUIOnEventMode', 0) ; reenable GUIGetMsg() EndFunc ;==>_ArrayDisplayByLayer Func _ArrayTraverse(ByRef $aMyArray, ByRef $hTree, $hParent) #cs since this is a recursive Function, the same Func runs many times, self called from within itself. The variables declared as Global at the top of the script are able to be accessed from any instance of the function, whereas the variable declared (as Local) within the function may be different for each instance of the function. #ce If Not IsArray($aMyArray) Then Return SetError(1, 0, -1) ; we have to know how many nested for-next loops we need ; that is one loop for each dimension Local $iDimensions = UBound($aMyArray, 0) ; number of nested for-next loops Local $sArrayPointer = "$aMyArray", $sElement For $i = 0 To $iDimensions - 1 $sArrayPointer &= '[$aLoops[' & $i & '][2]]' Next ; ----------------------------------------------------------------------------------- ; This is a nested For-Next loops simulator with variable depth of nested loops ; pass a 2D zero based array[n][3] ; with as many records as nested loops needed ; as following: ; ; Example; For $i = start To end ; ----- --- ; [n][0] = Start value ; [n][1] = End value ; [n][2] = actual loop counter (at startup is = to Start value [n][0]) ; ; --- Initializes custom nested For-Next loops -------------------------------------- Local $aLoops[$iDimensions][3] ; nr of nested loops is $iDimensions For $i = 0 To $iDimensions - 1 $aLoops[$i][0] = 0 ; Start value $aLoops[$i][1] = UBound($aMyArray, $i + 1) - 1 ; End value $aLoops[$i][2] = $aLoops[$i][0] ; actual loop counter Next ; ----------------------------------------------------------------------------------- Local $x, $vContent Do $vContent = Execute($sArrayPointer) If IsArray($vContent) Then ; here there is a Nested array, populate the TreeView with a child element $sElement = "" For $i = 0 To $iDimensions - 1 $sElement &= '[' & $aLoops[$i][2] & ']' Next Local $hNode = _GUICtrlTreeView_AddChild($hTree, $hParent, $sElement) ; recursive call for this nested array to search if there are any further nested arrays _ArrayTraverse($vContent, $hTree, $hNode) ; <-- recursive call EndIf ; ------------------------------------------------------------------------------- $x = UBound($aLoops) - 1 $aLoops[$x][2] += 1 While ($aLoops[$x][2] > $aLoops[$x][1]) ; check if and which nested loops are out of bound $aLoops[$x][2] = $aLoops[$x][0] ; reset the counter of this loop ($x) $x -= 1 ; check next outer nest If $x < 0 Then ExitLoop ; if we have finished all nested loops then Exit $aLoops[$x][2] += 1 ; when a deeper loop complete, increment the outer one WEnd Until $x < 0 ; If no more nested loops then exit EndFunc ;==>_ArrayTraverse ; Tree Path to Subscript Func _TreePathParser($Input) Local $sReturn = '$_aInput' Local $aSubArrays = StringSplit($Input, '|', 3) If UBound($aSubArrays) > 1 Then For $i = 1 To UBound($aSubArrays) - 1 $sReturn &= $aSubArrays[$i] If $i < UBound($aSubArrays) - 1 Then $sReturn = '(' & $sReturn & ')' Next EndIf Return $sReturn EndFunc ;==>_TreePathParser ; this will allow the scrolling of window containing ComboBoxes (if number of Combo doesn't fit in window) ; see _GUIScrollBars_Init() in the Help of AutoIt Func WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $lParam Local $iScrollCode = BitAND($wParam, 0x0000FFFF) Local $iIndex = -1, $iCharX, $iPosX Local $iMin, $iMax, $iPage, $iPos, $iTrackPos For $x = 0 To UBound($__g_aSB_WindowInfo) - 1 If $__g_aSB_WindowInfo[$x][0] = $hWnd Then $iIndex = $x $iCharX = $__g_aSB_WindowInfo[$iIndex][2] ExitLoop EndIf Next If $iIndex = -1 Then Return 0 ; ; Get all the horizontal scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $iMin = DllStructGetData($tSCROLLINFO, "nMin") $iMax = DllStructGetData($tSCROLLINFO, "nMax") $iPage = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $iPosX = DllStructGetData($tSCROLLINFO, "nPos") $iPos = $iPosX $iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") #forceref $iMin, $iMax Switch $iScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1) Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1) Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iPos - $iPage) Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iPos + $iPage) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iTrackPos) EndSwitch ; // Set the position and then retrieve it. Due to adjustments ; // by Windows it may not be the same as the value set. DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $iPos = DllStructGetData($tSCROLLINFO, "nPos") If ($iPos <> $iPosX) Then _GUIScrollBars_ScrollWindow($hWnd, $iCharX * ($iPosX - $iPos), 0) Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL
    1 point
  4. This is a simple func I made to write colored text to a rich edit, and I thought someone else might find it useful. What it does is format the text into RTF syntax so you don't need to mess with selecting and setting the color and such with multiple commands. ; _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $underline=0, $strike=0) ; This function was created to make it simpler to use RichEdit controls. ; ; Note: to set the line spacing to a size bigger than the text, ; you need to call this function once to write the text, and then call ; it again and write a space with a larger size, and that will give you ; spacing between the lines. ; ;Peramiters ; $RichEdit = handle of RichEdit control ; $text = the string to write. You need to add @CRLF for a newline ; $font = the font family to use, default = "Arial" ; $color = the rrggbb hex color code to use, default = "000000" (black) ; $size = the font size to use in points, will be rounded to the nearest 0.5 points before use, default = 12 ; $bold = flag to make the text bold, default = 0 (not bold) ; $italic = flag to make the text italic, default = 0 (not italic) ; $strike = flag to make the text strikethrough, default = 0 ; $underline = int, what kind of underlining to use. default = 0 ; 1 = Underline ; 2 = Double Underline ; 3 = Thick Underline ; 4 = Underline words only ; 5 = Wave Underline ; 6 = Dotted Underline ; 7 = Dash Underline ; 8 = Dot Dash Underline ; ;Return value ; On success: Returns the value from _GUICtrlRichEdit_AppendText() ; On failure: Sets @error to non-0 ; 1 = Error with color ; Func _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $strike=0, $underline=0) Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] If $font <> "" Then $command &= "{\fonttbl\f0\f"&$font&";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = dec(StringRight($color,2)) if @error Then seterror(1, 1) $color = StringTrimRight($color,2) $g = dec(StringRight($color,2)) if @error Then seterror(1, 2) $color = StringTrimRight($color,2) $r = dec(StringRight($color,2)) if @error Then seterror(1, 3) If $r+$b+$g > 0 Then $command &= "{\colortbl;\red"&$r&"\green"&$g&"\blue"&$b&";}\cf1" EndIf EndIf If $size Then $command &= "\fs"&round($size*2)&" " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 and $underline < 9 Then $command &= $ul[$underline]&" " ;~ ConsoleWrite($command&$text&"}"&@CRLF) ; Debugging line Return _GUICtrlRichEdit_AppendText($RichEdit, $command&StringReplace($text,@CRLF,"\line")&"}" ) EndFuncAn example of it's use: #include <GuiRichEdit.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 331, 303, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 8, 240, 313, 21) $ButtonBob = GUICtrlCreateButton("Bob", 8, 264, 75, 25) $ButtonMar = GUICtrlCreateButton("Mary", 88, 264, 75, 25) $ButtonSus = GUICtrlCreateButton("Susan", 168, 264, 75, 25) $ButtonJoe = GUICtrlCreateButton("Joe", 248, 264, 75, 25) $RichEdit = _GUICtrlRichEdit_Create($Form1, "", 8, 8, 313, 225, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE, $ES_READONLY)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $lastuser = "" demo() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonBob If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Bob", "993333", GUICtrlRead($Input1)) Case $ButtonJoe If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Joe", "339933", GUICtrlRead($Input1)) Case $ButtonSus If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Susan", "333399", GUICtrlRead($Input1)) Case $ButtonMar If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Mary", "339999", GUICtrlRead($Input1)) EndSwitch WEnd Func demo() _Chat_SendMessage("Bob", "993333", "Testin 123") _Chat_SendMessage("Bob", "993333", "Example script here") _Chat_SendMessage("Susan", "333399", "Enter something in the input and press a button") _Chat_SendMessage("Susan", "333399", "Try experimenting with it a bit") _Chat_SendMessage("Mary", "339999", "Messages between the same user are less spaced out than between other people") EndFunc ;use a function for wrapping messages with multiple parts of different formattings Func _Chat_SendMessage($user, $color, $text) Local $temp = ControlGetFocus($Form1) _GUICtrlRichEdit_AppendTextEx($RichEdit, $user&":", "Arial", $color, 10, 1) If $lastuser <> $user and $lastuser <> "" Then ; Add line spacing between users by using a taller font size for the space _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 15) Else ; Same width as 15, but only as tall as 10 :P _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 10) _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 5) EndIf _GUICtrlRichEdit_AppendTextEx($RichEdit, $text&@CRLF, "Arial", "000000", 10) $lastuser = $user ControlFocus($Form1, "", $temp) EndFunc ; _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $underline=0, $strike=0) ; This function was created to make it simpler to use RichEdit controls. ; ; Note: to set the line spacing to a size bigger than the text, ; you need to call this function once to write the text, and then call ; it again and write a space with a larger size, and that will give you ; spacing between the lines. ; ;Peramiters ; $RichEdit = handle of RichEdit control ; $text = the string to write. You need to add @CRLF for a newline ; $font = the font family to use, default = "Arial" ; $color = the rrggbb hex color code to use, default = "000000" (black) ; $size = the font size to use in points, will be rounded to the nearest 0.5 points before use, default = 12 ; $bold = flag to make the text bold, default = 0 (not bold) ; $italic = flag to make the text italic, default = 0 (not italic) ; $strike = flag to make the text strikethrough, default = 0 ; $underline = int, what kind of underlining to use. default = 0 ; 1 = Underline ; 2 = Double Underline ; 3 = Thick Underline ; 4 = Underline words only ; 5 = Wave Underline ; 6 = Dotted Underline ; 7 = Dash Underline ; 8 = Dot Dash Underline ; ;Return value ; On success: Returns the value from _GUICtrlRichEdit_AppendText() ; On failure: Sets @error to non-0 ; 1 = Error with color ; Func _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $strike=0, $underline=0) Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] If $font <> "" Then $command &= "{\fonttbl\f0\f"&$font&";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = dec(StringRight($color,2)) if @error Then seterror(1, 1) $color = StringTrimRight($color,2) $g = dec(StringRight($color,2)) if @error Then seterror(1, 2) $color = StringTrimRight($color,2) $r = dec(StringRight($color,2)) if @error Then seterror(1, 3) If $r+$b+$g > 0 Then $command &= "{\colortbl;\red"&$r&"\green"&$g&"\blue"&$b&";}\cf1" EndIf EndIf If $size Then $command &= "\fs"&round($size*2)&" " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 and $underline < 9 Then $command &= $ul[$underline]&" " ;~ ConsoleWrite($command&$text&"}"&@CRLF) ; Debugging line Return _GUICtrlRichEdit_AppendText($RichEdit, $command&StringReplace($text,@CRLF,"\line")&"}" ) EndFuncIf this was useful to you, or if you have any ideas / suggestions to make it better, let me know.
    1 point
  5. Inpho, I like to keep busy - and it is all fun for those of us enjoying retirement!!! I see the problem you mention - very peculiar. Looking into that will be tomorrow's item to keep the "little grey cells" active. M23
    1 point
  6. TheDcoder

    Telnet

    Here is a basic TCP usage example: Global Const $SERVER = "" ; IP or Address of the server Global Const $SERVER_IP = TCPNameToIP($SERVER) Global Const $PORT = 0 ; Port of the server to connect Global $iSocket = TCPConnect($SERVER_IP, $PORT) ; Do not change this TCPSend($iSocket, "") ; Use TCPSend to send commands Global $vData ; Recived Data is stored in this variable While 1 ; This is a infinite loop which recives data from the server $vData = TCPRecv($iSocket, 100) ; Recive the data (only the first 100 bytes will be recived!) If Not $vData = "" Then ConsoleWrite($vData) ; Write the data to the Console Output Sleep(10) ; Rest the CPU a little WEnd The code is very basic and might require some modifications to work with your situation... I only made the basic because I don't know what protocol you are trying to automate . Use the above code as a base , Let me know if it works .
    1 point
  7. TheDcoder

    Telnet

    Ok, I will write some starter code for you . Give me some time and I will post it here .
    1 point
  8. TheDcoder

    Autoit CMD

    @Trong Glad you like it . I neglected that UDF a little over the months... Will get back it when I get some time
    1 point
  9. TheDcoder

    Autoit CMD

    @youtuber Not a bug, Encoding problem.
    1 point
  10. JLogan3o13

    Autoit CMD

    I see where you did this in answer to a question in GH&S. I personally would not suggest starting someone new off with Magic Numbers rather than best practices - it isn't going to do them any favors as they learn to script.
    1 point
  11. Progh0st

    DirCopy Usb

    Finally got it to work! Thanks to all of you.
    1 point
  12. JLogan3o13

    DirCopy Usb

    I would not call the 2k difference between doing it correctly and using magic numbers "bloat", personally.
    1 point
  13. EmilyLove

    DirCopy Usb

    Looks fine to me. Make sure you are including FileConstants.au3 or overwrite flag won't work. If you don't want to bloat your script with the include, then just use 1 as the flag instead of $fc_overwrite.
    1 point
  14. JLogan3o13

    DirCopy Usb

    @Progh0st the code below just worked fine for me #include <FileConstants.au3> DirCopy("E:\", @DesktopDir & "\FromUSB\", $FC_OVERWRITE) Copied an .iso and a sub directory from the USB drive
    1 point
  15. Unigod bless you!
    1 point
  16. @jchd Big THANK YOU. Local $aASCII = StringToASCIIArray($sResultData, 0, StringLen($sResultData), $SE_UTF16) $sResultData = StringFromASCIIArray($aASCII, 0, -1, $SE_UTF8) $sResultData = _HTML_DecodeEntities($sResultData) SOLVED mLipok
    1 point
  17. To deal with OLE drag-and-drop event is painful in autoit. is an exmaple from ProgAndy (thanks). But since we have AutoItObject UDF, it should go easy. However, there are still a lot of works to do. So I wrote the UDF to convert OLE drag-and-drop event to "Windows Message" event that can be easily handled by GUIRegisterMsg() in AutoIt. This UDF provides 4 kinds of message: $WM_DRAGENTER, $WM_DRAGOVER, $WM_DRAGLEAVE, and $WM_DROP. To use is easy, just register a GUI window or control as the drop target, then handle message by GUIRegisterMsg(). See example: #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include "DragDropEvent.au3" Opt("MustDeclareVars", 1) DragDropEvent_Startup() Main() Exit Func Main() Local $MainWin = GUICreate("DragDropEvent Example", 380, 130, -1, -1, -1, $WS_EX_TOPMOST) GUISetFont(12, 900) GUICtrlCreateLabel("(Drop text or files on me)", 40, 40) DragDropEvent_Register($MainWin) GUIRegisterMsg($WM_DRAGENTER, "OnDragDrop") GUIRegisterMsg($WM_DRAGOVER, "OnDragDrop") GUIRegisterMsg($WM_DRAGLEAVE, "OnDragDrop") GUIRegisterMsg($WM_DROP, "OnDragDrop") GUISetState(@SW_SHOW) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() EndFunc Func OnDragDrop($hWnd, $Msg, $wParam, $lParam) Static $DropAccept Switch $Msg Case $WM_DRAGENTER, $WM_DROP ToolTip("") Select Case DragDropEvent_IsFile($wParam) If $Msg = $WM_DROP Then Local $FileList = DragDropEvent_GetFile($wParam) MsgBox(262144, "DragDropEvent", StringReplace($FileList, "|", @LF)) EndIf $DropAccept = $DROPEFFECT_COPY Case DragDropEvent_IsText($wParam) If $Msg = $WM_DROP Then MsgBox(262144, "DragDropEvent", DragDropEvent_GetText($wParam)) EndIf $DropAccept = $DROPEFFECT_COPY Case Else $DropAccept = $DROPEFFECT_NONE EndSelect Return $DropAccept Case $WM_DRAGOVER Local $X = DragDropEvent_GetX($wParam) Local $Y = DragDropEvent_GetY($wParam) ToolTip("(" & $X & "," & $Y & ")") Return $DropAccept Case $WM_DRAGLEAVE ToolTip("") EndSwitch EndFunc == Public Functions List == DragDropEvent_Startup() ; DragDropEvent UDF startup. ; DragDropEvent_Register($hWnd, $hWndToReceiveMsg = $hWnd) ; Register a window or control that can be the target. $hWndToReceiveMsg is needed only when $hWnd is a control. ; DragDropEvent_Revoke($hWnd) ; Revokes the registration of the specified window or control. ; DragDropEvent_GetHWnd($wParam) ; Can invoke by all message handler, to get what window or control is the target. ; DragDropEvent_GetX($wParam) DragDropEvent_GetY($wParam) DragDropEvent_GetKeyState($wParam) ; Can invoke by all message handler except $WM_DRAGLEAVE, to get the modifier keys and mouse position. ; DragDropEvent_IsText($wParam) DragDropEvent_IsFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to check what data is being dragged. ; DragDropEvent_GetText($wParam) DragDropEvent_GetFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to get related data. Path of file is splited by "|". ; == Requirement == Attachment not includes above requirement files, but includes more examples. == Update 2012/3/10 == * Fix x64 problem. (Thanks to trancexx) * Remove dependency to AutoItObject and Associative Array UDF. (Suggestion by wraithdu) == Update 2012/3/15== * Remove dependency to Bianry UDF. * Remove extra DllStructGetPtr(). (Suggestion by trancexx) * Fix bug in DataObject_GetFile(). DragDropEvent.zip
    1 point
  18. I haven't the zip file, but probably these three listings were in that zip: DragDropEvent.au3 ; =============================================================================================================================== ; File : DragDropEvent.au3 (2012/3/15) ; Purpose : Convert OLE drag-and-drop event to "Windows Message" that AutoIt3 can handle by GUIRegisterMsg ; Provide 4 message: $WM_DRAGENTER, $WM_DRAGOVER, $WM_DRAGLEAVE, and $WM_DROP ; Author : Ward ; =============================================================================================================================== #Include-once #Include <Memory.au3> #Include <SendMessage.au3> #Include <WindowsConstants.au3> ; =============================================================================================================================== ; Public Functions: ; ; DragDropEvent_Startup() ; DragDropEvent UDF startup. ; ; DragDropEvent_Register($hWnd, $hWndToReceiveMsg = $hWnd) ; Register a window or control that can be the target. $hWndToReceiveMsg is needed only when $hWnd is a control. ; ; DragDropEvent_Revoke($hWnd) ; Revokes the registration of the specified window or control. ; ; DragDropEvent_GetHWnd($wParam) ; Can invoke by all message handler, to get what window or control is the target. ; ; DragDropEvent_GetX($wParam) ; DragDropEvent_GetY($wParam) ; DragDropEvent_GetKeyState($wParam) ; Can invoke by all message handler except $WM_DRAGLEAVE, to get the modifier keys and mouse position. ; ; DragDropEvent_IsText($wParam) ; DragDropEvent_IsFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to check what data is being dragged. ; ; DragDropEvent_GetText($wParam) ; DragDropEvent_GetFile($wParam) ; Can invoke by $WM_DRAGENTER or $WM_DROP, to get related data. Path of file is splited by "|". ; ; =============================================================================================================================== ; =============================================================================================================================== ; Internal Functions: ; ; IDropTarget_QueryInterface($pSelf, $pRIID, $pObj) ; IDropTarget_AddRef($pSelf) ; IDropTarget_Release($pSelf) ; IDropTarget_DragEnter($pSelf, $DataObj, $KeyState, $X, $Y, $pEffect) ; IDropTarget_DragLeave($pSelf) ; IDropTarget_DragOver($pSelf, $KeyState, $X, $Y, $pEffect) ; IDropTarget_Drop($pSelf, $DataObj, $KeyState, $X, $Y, $pEffect) ; IDropTarget_SetEffect($pEffect, $Value) ; Methods of IDropTarget interface. ; ; IDropTarget_SetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) ; IDropTarget_GetHWnd($pSelf, ByRef $hWnd, ByRef $hWndToReceiveMsg) ; To set and get data store in IDropTarget interface. ; ; DataObject_QueryText($DataObj) ; DataObject_QueryFile($DataObj) ; DataObject_GetText($DataObj) ; DataObject_GetFile($DataObj) ; Functions to handle DataObject. ; ; DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) ; DragDropEvent_Get($wParam, $Name) ; Functions to handle infomation data for DragDropEvent. ; ; __CreateCOMInterface($sFunctionPrefix, $dtagInterface, $fNoUnknown = False, $ExtraSpace = 0) ; To create vtable of a COM interface. Modify from _AutoItObject_ObjectFromDtag. ; ; =============================================================================================================================== ; =============================================================================================================================== ; Global const and variables ; =============================================================================================================================== ; Define 4 kind of DragDropEvent: DragEnter, DragOver, DragLeave, and Drop Global Enum $WM_DRAGENTER = $WM_USER + 0x1001, $WM_DRAGOVER, $WM_DRAGLEAVE, $WM_DROP ; Message handler return one of these flags, which indicates what the result of the drop operation would be. Global Enum $DROPEFFECT_NONE = 0, $DROPEFFECT_COPY = 1, $DROPEFFECT_MOVE = 2, $DROPEFFECT_LINK = 4, $DROPEFFECT_SCROLL = 0x80000000 Global Const $IID_IDataObject = "{0000010e-0000-0000-C000-000000000046}" Global Const $dtagIDropTarget = "DragEnter hresult(ptr;uint;uint64;ptr);DragOver hresult(uint;uint64;ptr);DragLeave hresult();Drop hresult(ptr;uint;uint64;ptr);" Global Const $dtagIDataObject = "GetData hresult(struct*;struct*);GetDataHere hresult(struct*;struct*);QueryGetData hresult(struct*);GetCanonicalFormatEtc hresult(struct*;struct*);SetData hresult(struct*;struct*;int);EnumFormatEtc hresult(uint;ptr);DAdvise hresult(struct*;uint;ptr;ptr);DUnadvise hresult(uint);EnumDAdvise hresult(ptr);" Global Const $tagFORMATETC = "struct;uint Format;ptr ptd;uint Aspect;int lindex;uint tymed;endstruct" Global Const $tagSTGMEDIUM = "struct;uint tymed;ptr hGlobal;ptr UnkForRelease;endstruct" Global Const $tagDragDropEventInfo = "ptr hwnd;ptr DataObj;uint KeyState;uint x;uint y" Global Const $__KERNEL32_DLL = DllOpen("kernel32.dll") Global Const $__OLE32_DLL = DllOpen("ole32.dll") Global $__IDropTargetLen = 0 ; =============================================================================================================================== ; DragDropEvent startup and register functions ; =============================================================================================================================== Func DragDropEvent_Startup() ; If @AutoItVersion < "3.3.8.0" Then Exit MsgBox(16, "DragDropEvent Fail", "Require AutoIt Version 3.3.8.0 at least") DllCall($__OLE32_DLL, "int", "OleInitialize", "ptr", 0) EndFunc Func DragDropEvent_Register($hWnd, $hWndToReceiveMsg = Default) If IsKeyword($hWndToReceiveMsg) Then $hWndToReceiveMsg = $hWnd Local $IDropTarget = __CreateCOMInterface("IDropTarget_", $dtagIDropTarget, True, 2) ; add 2 extra space to store hWnd If $IDropTarget Then $__IDropTargetLen = @Extended IDropTarget_SetHWnd($IDropTarget, $hWnd, $hWndToReceiveMsg) DllCall($__OLE32_DLL, "int", "RegisterDragDrop", "hwnd", $hWnd, "ptr", $IDropTarget) EndIf EndFunc Func DragDropEvent_Revoke($hWnd) DllCall($__OLE32_DLL, "int", "RevokeDragDrop", "hwnd", $hWnd) EndFunc ; =============================================================================================================================== ; Methods of IDropTarget interface ; =============================================================================================================================== Func IDropTarget_QueryInterface($pSelf, $pRIID, $pObj) Return 0x80004002 ; E_NOINTERFACE EndFunc Func IDropTarget_AddRef($pSelf) EndFunc Func IDropTarget_Release($pSelf) DllCall($__OLE32_DLL, "none", "CoTaskMemFree", "ptr", $pSelf) EndFunc Func IDropTarget_DragEnter($pSelf, $DataObj, $KeyState, $Point, $pEffect) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $X = BitAND($Point, 0xFFFFFFFF), $Y = Dec(StringTrimRight(Hex($Point), 8)) Local $Info = DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) Local $Ret = _SendMessage($hWndToReceiveMsg, $WM_DRAGENTER, DllStructGetPtr($Info), 0) DllStructSetData(DllStructCreate("dword", $pEffect), 1, $Ret) EndFunc Func IDropTarget_DragLeave($pSelf) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $Info = DragDropEvent_InfoCreate($hWnd, 0, 0, 0, 0) _SendMessage($hWndToReceiveMsg, $WM_DRAGLEAVE, DllStructGetPtr($Info), 0) EndFunc Func IDropTarget_DragOver($pSelf, $KeyState, $Point, $pEffect) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $X = BitAND($Point, 0xFFFFFFFF), $Y = Dec(StringTrimRight(Hex($Point), 8)) Local $Info = DragDropEvent_InfoCreate($hWnd, 0, $KeyState, $X, $Y) Local $Ret = _SendMessage($hWndToReceiveMsg, $WM_DRAGOVER, DllStructGetPtr($Info), 0) DllStructSetData(DllStructCreate("dword", $pEffect), 1, $Ret) EndFunc Func IDropTarget_Drop($pSelf, $DataObj, $KeyState, $Point, $pEffect) Local $hWnd, $hWndToReceiveMsg IDropTarget_GetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $X = BitAND($Point, 0xFFFFFFFF), $Y = Dec(StringTrimRight(Hex($Point), 8)) Local $Info = DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) Local $Ret = _SendMessage($hWndToReceiveMsg, $WM_DROP, DllStructGetPtr($Info), 0) DllStructSetData(DllStructCreate("dword", $pEffect), 1, $Ret) EndFunc Func IDropTarget_SetHWnd($pSelf, $hWnd, $hWndToReceiveMsg) Local $Buffer = DllStructCreate("ptr[" & ($__IDropTargetLen + 2) & "]", $pSelf) DllStructSetData($Buffer, 1, $hWnd, $__IDropTargetLen + 1) DllStructSetData($Buffer, 1, $hWndToReceiveMsg, $__IDropTargetLen + 2) EndFunc Func IDropTarget_GetHWnd($pSelf, ByRef $hWnd, ByRef $hWndToReceiveMsg) Local $Buffer = DllStructCreate("ptr[" & ($__IDropTargetLen + 2) & "]", $pSelf) $hWnd = DllStructGetData($Buffer, 1, $__IDropTargetLen + 1) $hWndToReceiveMsg = DllStructGetData($Buffer, 1, $__IDropTargetLen + 2) EndFunc ; =============================================================================================================================== ; Functions to handle DataObject ; =============================================================================================================================== Func DataObject_QueryText($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) DllStructSetData($FORMATETC, "Format", 13) ; 13 = CF_UNICODETEXT DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Local $Ret = $IDataObj.QueryGetData($FORMATETC) If $Ret <> 0 Then DllStructSetData($FORMATETC, "Format", 1) ; 1 = CF_TEXT $Ret = $IDataObj.QueryGetData($FORMATETC) EndIf Return $Ret EndFunc Func DataObject_QueryFile($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) DllStructSetData($FORMATETC, "Format", 15) ; 15 = CF_HDROP DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Return $IDataObj.QueryGetData($FORMATETC) EndFunc Func DataObject_GetText($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) Local $STGMEDIUM = DllStructCreate($tagSTGMEDIUM) DllStructSetData($FORMATETC, "Format", 13) ; 13 = CF_UNICODETEXT DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Local $IsUnicode = True Local $Ret = $IDataObj.QueryGetData($FORMATETC) If $Ret <> 0 Then $IsUnicode = False DllStructSetData($FORMATETC, "Format", 1) ; 1 = CF_TEXT $Ret = $IDataObj.QueryGetData($FORMATETC) EndIf If $Ret <> 0 Then Return SetError(1, 0, "") Local $Error = 1, $Text = "" If $IDataObj.GetData($FORMATETC, $STGMEDIUM) = 0 Then If DllStructGetData($STGMEDIUM, "tymed") = 1 Then Local $Ptr = _MemGlobalLock(DllStructGetData($STGMEDIUM, "hGlobal")) Local $Tag If $IsUnicode Then $Tag = "wchar[" & (_MemGlobalSize($Ptr) / 2) & "]" Else $Tag = "char[" & _MemGlobalSize($Ptr) & "]" EndIf $Text = DllStructGetData(DllStructCreate($Tag, $Ptr), 1) _MemGlobalUnlock($Ptr) If DllStructGetData($STGMEDIUM, "UnkForRelease") = 0 Then _MemGlobalFree($Ptr) $Error = 0 EndIf EndIf Return SetError($Error, 0, $Text) EndFunc Func DataObject_GetFile($DataObj) Local $IDataObj = ObjCreateInterface($DataObj, $IID_IDataObject, $dtagIDataObject) If Not IsObj($IDataObj) Then Return -1 $IDataObj.AddRef() Local $FORMATETC = DllStructCreate($tagFORMATETC) Local $STGMEDIUM = DllStructCreate($tagSTGMEDIUM) DllStructSetData($FORMATETC, "Format", 15) ; 15 = CF_HDROP DllStructSetData($FORMATETC, "Aspect", 1) DllStructSetData($FORMATETC, "lindex", -1) DllStructSetData($FORMATETC, "tymed", 1) ; 1 = TYMED_HGLOBAL Local $Error = 1, $FileList = "" If $IDataObj.GetData($FORMATETC, $STGMEDIUM) = 0 Then If DllStructGetData($STGMEDIUM, "tymed") = 1 Then Local $Ptr = _MemGlobalLock(DllStructGetData($STGMEDIUM, "hGlobal")) Local $StrPtr = $Ptr + DllStructGetData(DllStructCreate("dword", $Ptr), 1) Do Local $Ret = DllCall($__KERNEL32_DLL, "uint", "lstrlenW", "ptr", $StrPtr) Local $StrLen = $Ret[0] If $StrLen Then Local $Str = DllStructGetData(DllStructCreate("wchar[" & $StrLen & "]", $StrPtr), 1) $FileList &= $Str & "|" $StrPtr += $StrLen * 2 + 2 EndIf Until $StrLen = 0 If StringRight($FileList, 1) = "|" Then $FileList = StringTrimRight($FileList, 1) _MemGlobalUnlock($Ptr) If DllStructGetData($STGMEDIUM, "UnkForRelease") = 0 Then _MemGlobalFree($Ptr) $Error = 0 EndIf EndIf Return SetError($Error, 0, $FileList) EndFunc ; =============================================================================================================================== ; Functions to handle infomation data for DragDropEvent ; =============================================================================================================================== Func DragDropEvent_InfoCreate($hWnd, $DataObj, $KeyState, $X, $Y) Local $Info = DllStructCreate($tagDragDropEventInfo) DllStructSetData($Info, "hwnd", $hWnd) DllStructSetData($Info, "DataObj", $DataObj) DllStructSetData($Info, "KeyState", $KeyState) DllStructSetData($Info, "x", $X) DllStructSetData($Info, "y", $Y) Return $Info EndFunc Func DragDropEvent_Get($wParam, $Name) If Not $wParam Then Return SetError(1, 0, 0) Local $Info = DllStructCreate($tagDragDropEventInfo, $wParam) Return DllStructGetData($Info, $Name) EndFunc Func DragDropEvent_GetHWnd($wParam) Local $Ret = DragDropEvent_Get($wParam, "hwnd") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_GetX($wParam) Local $Ret = DragDropEvent_Get($wParam, "x") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_GetY($wParam) Local $Ret = DragDropEvent_Get($wParam, "y") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_GetKeyState($wParam) Local $Ret = DragDropEvent_Get($wParam, "KeyState") Return SetError(@Error, 0, $Ret) EndFunc Func DragDropEvent_IsText($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_QueryText($DataObj) = 0 EndFunc Func DragDropEvent_IsFile($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_QueryFile($DataObj) = 0 EndFunc Func DragDropEvent_GetText($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_GetText($DataObj) EndFunc Func DragDropEvent_GetFile($wParam) Local $DataObj = DragDropEvent_Get($wParam, "DataObj") Return DataObject_GetFile($DataObj) EndFunc ; =============================================================================================================================== ; Functions to create COM interface ; =============================================================================================================================== Func __CreateCOMInterface($sFunctionPrefix, $dtagInterface, $fNoUnknown = False, $ExtraSpace = 0) ; Original is _AutoItObject_ObjectFromDtag in AutoItObject.au3 by AutoItObject-Team ; Modify by Ward Local Const $__PtrSize = DllStructGetSize(DllStructCreate('ptr', 1)) Local Const $dtagIUnknown = "QueryInterface hresult(ptr;ptr*);AddRef dword();Release dword();" If $fNoUnknown Then $dtagInterface = $dtagIUnknown & $dtagInterface Local $sMethods = StringReplace(StringRegExpReplace($dtagInterface, "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF) If $sMethods = $dtagInterface Then $sMethods = StringReplace(StringRegExpReplace($dtagInterface, "\h*(\w+)\h*(;|;*\z)", "$1\|" & @LF), ";" & @LF, @LF) $sMethods = StringTrimRight($sMethods, 1) $sMethods = StringReplace(StringReplace(StringReplace(StringReplace($sMethods, "object", "idispatch"), "variant*", "ptr"), "hresult", "long"), "bstr", "ptr") Local $aMethods = StringSplit($sMethods, @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback Local $AllocSize = $__PtrSize * ($iUbound + 1 + $ExtraSpace) Local $Ret = DllCall($__OLE32_DLL, "ptr", "CoTaskMemAlloc", "uint_ptr", $AllocSize) If @error Then Return SetError(1, 0, 0) Local $AllocPtr = $Ret[0] Local $tInterface = DllStructCreate("ptr[" & $iUbound + 1 & "]", $AllocPtr) If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams ; To avoid repeat allocate the same callback, a memory leakage $hCallback = Eval(":Callback:" & $sMethod) If Not $hCallback Then $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) Assign(":Callback:" & $sMethod, $hCallback, 2) EndIf DllStructSetData($tInterface, 1, DllCallbackGetPtr($hCallback), $i + 2) Next DllStructSetData($tInterface, 1, $AllocPtr + $__PtrSize) ; Interface method pointers are actually pointer size away Return SetExtended($iUbound + 1, $AllocPtr) ; Return interface size as @Extended for access extra space EndFunc DragDropEvent_Example_1.au3 ; =============================================================================================================================== ; File : DragDropEvent_Example_1.au3 (2012/3/9) ; Purpose : Demonstrate the usage of DragDropEvent UDF ; Author : Ward ; =============================================================================================================================== #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include "DragDropEvent.au3" Opt("MustDeclareVars", 1) DragDropEvent_Startup() Main() Exit Func Main() Local $MainWin = GUICreate("DragDropEvent Example", 380, 130, -1, -1, -1, $WS_EX_TOPMOST) GUISetFont(12, 900) GUICtrlCreateLabel("(Drop text or files on me)", 40, 40) DragDropEvent_Register($MainWin) GUIRegisterMsg($WM_DRAGENTER, "OnDragDrop") GUIRegisterMsg($WM_DRAGOVER, "OnDragDrop") GUIRegisterMsg($WM_DRAGLEAVE, "OnDragDrop") GUIRegisterMsg($WM_DROP, "OnDragDrop") GUISetState(@SW_SHOW) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() EndFunc Func OnDragDrop($hWnd, $Msg, $wParam, $lParam) Static $DropAccept Switch $Msg Case $WM_DRAGENTER, $WM_DROP ToolTip("") Select Case DragDropEvent_IsFile($wParam) If $Msg = $WM_DROP Then Local $FileList = DragDropEvent_GetFile($wParam) MsgBox(262144, "DragDropEvent", StringReplace($FileList, "|", @LF)) EndIf $DropAccept = $DROPEFFECT_COPY Case DragDropEvent_IsText($wParam) If $Msg = $WM_DROP Then MsgBox(262144, "DragDropEvent", DragDropEvent_GetText($wParam)) EndIf $DropAccept = $DROPEFFECT_COPY Case Else $DropAccept = $DROPEFFECT_NONE EndSelect Return $DropAccept Case $WM_DRAGOVER Local $X = DragDropEvent_GetX($wParam) Local $Y = DragDropEvent_GetY($wParam) ToolTip("(" & $X & "," & $Y & ")") Return $DropAccept Case $WM_DRAGLEAVE ToolTip("") EndSwitch EndFunc DragDropEvent_Example_2.au3 ; =============================================================================================================================== ; File : DragDropEvent_Example_2.au3 (2012/3/9) ; Purpose : Demonstrate the usage of DragDropEvent UDF ; Author : Ward ; =============================================================================================================================== #Include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include "DragDropEvent.au3" Opt("MustDeclareVars", 1) Global $Button1, $Button2, $Button3, $Button4 DragDropEvent_Startup() Main() Exit Func Main() Local $MainWin = GUICreate("DragDropEvent Example", 460, 400, -1, -1, -1, $WS_EX_TOPMOST) GUISetFont(12, 900) $Button1 = GUICtrlCreateButton("Drop Text", 20, 20, 200, 150) $Button2 = GUICtrlCreateButton("Drop Files", 240, 20, 200, 150) $Button3 = GUICtrlCreateButton("Drop Anything", 20, 190, 200, 150) $Button4 = GUICtrlCreateButton("Don't Drop", 240, 190, 200, 150) GUICtrlCreateLabel("(Click button to revoke the target)", 40, 350) DragDropEvent_Register(GUICtrlGetHandle($Button1), $MainWin) DragDropEvent_Register(GUICtrlGetHandle($Button2), $MainWin) DragDropEvent_Register(GUICtrlGetHandle($Button3), $MainWin) DragDropEvent_Register(GUICtrlGetHandle($Button4), $MainWin) GUIRegisterMsg($WM_DRAGENTER, "OnDragDrop") GUIRegisterMsg($WM_DRAGOVER, "OnDragDrop") GUIRegisterMsg($WM_DRAGLEAVE, "OnDragDrop") GUIRegisterMsg($WM_DROP, "OnDragDrop") GUISetState(@SW_SHOW) While 1 Local $Msg = GUIGetMsg() Switch $Msg Case $Button1, $Button2, $Button3, $Button4 DragDropEvent_Revoke(GUICtrlGetHandle($Msg)) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() EndFunc Func OnDragDrop($hWnd, $Msg, $wParam, $lParam) Static $DropAccept Switch $Msg Case $WM_DRAGENTER, $WM_DROP ToolTip("") Local $Target = DragDropEvent_GetHWnd($wParam) Select Case DragDropEvent_IsFile($wParam) If $Target = GUICtrlGetHandle($Button1) Or $Target = GUICtrlGetHandle($Button4) Then $DropAccept = $DROPEFFECT_NONE Else If $Msg = $WM_DROP Then Local $FileList = DragDropEvent_GetFile($wParam) MsgBox(262144, "DragDropEvent", StringReplace($FileList, "|", @LF)) EndIf $DropAccept = $DROPEFFECT_COPY EndIf Case DragDropEvent_IsText($wParam) If $Target = GUICtrlGetHandle($Button2) Or $Target = GUICtrlGetHandle($Button4) Then $DropAccept = $DROPEFFECT_NONE Else If $Msg = $WM_DROP Then MsgBox(262144, "DragDropEvent", DragDropEvent_GetText($wParam)) EndIf $DropAccept = $DROPEFFECT_COPY EndIf Case Else $DropAccept = $DROPEFFECT_NONE EndSelect Return $DropAccept Case $WM_DRAGOVER Local $X = DragDropEvent_GetX($wParam) Local $Y = DragDropEvent_GetY($wParam) Local $KeyState = DragDropEvent_GetKeyState($wParam) ToolTip("(" & $X & "," & $Y & "," & $KeyState & ")") Return $DropAccept Case $WM_DRAGLEAVE ToolTip("") EndSwitch EndFunc
    1 point
  19. ahmeddzcom, You were given the solution above. You have set the script to run using OnEvent mode - doing so prevents GUIGetMsg from working and so to capture the button event you will need to use GUICtrlSetOnEvent to assign a function to it. I suggest reading the <GUIReference - GUI Concepts> section of the Help file to understand the difference between OnEvent & MessageLoop modes.. M23
    1 point
  20. The string you get is UTF-8 encoded, as the charset=utf-8 header parameter implies. At first look it sounds easy to convert but there's a catch: once you obtain the string as an AutoIt native string variable, it's likely it will be encoded natively, i.e. as UTF-16-LE. Say the string sent is a price like "3€" which is the UTF-8 hex byte sequence 33 E2 82 AC. This may become the hex 16-bit words sequence 0033 00E2 0082 00AC as AutoIt string variable. Then if you just convert the latter string from what you believe is UTF8 to UTF16 the conversion won't make sense. Only the former non-native string of bytes will convert correctly. First check the actual type (binary or string) and content (StringToAsciiArray) of the received string and code accordingly.
    1 point
  21. Here, take my updated UDFs Request AutoIt3 UDF.7z
    1 point
  22. i like it when it all works the first time very nice work Adventurer -- you made it really easy to use psftp
    1 point
  23. I am glad that you were able to solve the problem. Thank you for sharing your comments with which to solve the problem.
    1 point
  24. Thanks for the input guys. I worked out what I needed to do. I was not sending my header information the way it needed to be. I ended up with something like what is shown below. <HOST> referes to my server name that is hosting the REST service. $restReq = ObjCreate("winhttp.winhttprequest.5.1") $restReq.Open("GET", "http://<host>/RevitServerAdminRESTService2013/AdminRESTService.svc/|ssd testing\01\01 Production\SharedData\Models\Contents", False) $restReq.setRequestHeader ("User-Name", "Jeff") $restReq.setRequestHeader ("User-Machine-Name", "B700") $restReq.setRequestHeader ("Operation-GUID", "1640EA28-0C15-40BF-8DDA-5DB9D917D1F4") $restReq.Send() $oReceived = $restReq.ResponseText $oStatusCode = $restReq.Status If $oStatusCode == 200 then $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) FileClose($file) EndIf
    1 point
  25. Hi, This will work for SOAP requests. I might work for your needs? You would need to modiy this to suit. Ignore if thisis not useful. Notice the 'setRequestHeader' taking Header name and value Refer to MSDN also: http://msdn.microsoft.com/en-us/library/windows/apps/hh453379.aspx http://msdn.microsoft.com/en-us/library/windows/apps/hh453349.aspx http://msdn.microsoft.com/en-us/library/windows/apps/hh453367.aspx Local $objHTTP = ObjCreate("Microsoft.XMLHTTP") Local $objReturn = ObjCreate("Msxml2.DOMDocument.3.0") ; Set up to post to the URL $objHTTP.open ("post", $sURL, False) ; Set a standard SOAP/ XML header for the content-type $objHTTP.setRequestHeader ("Content-Type", "text/xml") ; Set a header for SOAPAction $objHTTP.setRequestHeader ("SOAPAction", $sSOAPAction) ; Make the SOAP call $objHTTP.send ($sSoapEnvelope) ; Get the return envelope $strReturn = $objHTTP.responseText ; Load the return envelope into a DOM $objReturn.loadXML ($strReturn) ;return the XML DOM Object (to be filtered/searched) Return $objReturn;
    1 point
  26. Sure, this is what I had. Haven't touched it since the original playing around since the GUI issues discouraged me too much and got busy with other things. This would definitely need a lot of cleaning up and more error handling, but this was a working model... I tried to take out everything except the parts that really pertain to the authorization and using it. You can piece it together depending on your application. Func Authorize($verifier_input = "") If $verifier_input = "" Then ; initial auth setup $path = "/oauth/request_token" $postdata = "oauth_consumer_key=" & $oauth_consumer_key $header = 'Authorization: OAuth oauth_consumer_key="' & $oauth_consumer_key & '"' $header &= ',oauth_signature_method="PLAINTEXT"' $header &= ',oauth_timestamp="' & Timestamp() & '"' $header &= ',oauth_nonce="' & Nonce() & '"' $header &= ',oauth_signature="' & $oauth_signature & '"' $response = MakeRequest("POST", $path, $postdata, $header) SetTokenStrings($response[1]) $path = "/oauth/authorize" $postdata = $response[1] $header = "" $link = "https://" & $host & $path & "?" & $postdata ShellExecute($link) Else ; returning setup, process verifier $oauth_verifier = $verifier_input $path = "/oauth/access_token" $postdata = "oauth_consumer_key=" & $oauth_consumer_key $header = 'Authorization: OAuth oauth_consumer_key="' & $oauth_consumer_key & '"' $header &= ',oauth_token="' & $oauth_token & '"' $header &= ',oauth_signature_method="PLAINTEXT"' $header &= ',oauth_timestamp="' & Timestamp() & '"' $header &= ',oauth_nonce="' & Nonce() & '"' $header &= ',oauth_signature="' & $oauth_signature & '"' $header &= ',oauth_verifier="' & $oauth_verifier & '"' $response = MakeRequest("POST", $path, $postdata, $header) SetTokenStrings($response[1]) IniWrite($ini, "auth", "tk", $oauth_token) IniWrite($ini, "auth", "sig", $oauth_signature) AuthStuff("HIDE") Refresh() EndIf EndFunc Func Refresh() ; make sure it isn't too recent first If Timestamp() - $last_refresh > 44 Then $last_refresh = Timestamp() $path = "/api/v1/messages.xml" $postdata = "" $header = 'Authorization: OAuth oauth_consumer_key="' & $oauth_consumer_key & '"' $header &= ',oauth_token="' & $oauth_token & '"' $header &= ',oauth_signature_method="PLAINTEXT"' $header &= ',oauth_timestamp="' & Timestamp() & '"' $header &= ',oauth_nonce="' & Nonce() & '"' $header &= ',oauth_signature="' & $oauth_signature & '"' $response = MakeRequest("GET", $path, $postdata, $header) $last_xml = $response[1] Else MsgBox(0, "", "Too soon to refresh!") EndIf _XMLLoadXML($last_xml) $nNodes = _XMLGetNodeCount("/response/messages/message") For $i = 1 To $nNodes $body = _XMLGetValue("/response/messages/message[" & $i & "]/body/plain") $text = $body[1] Next EndFunc Func Post($s) $path = "/api/v1/messages.xml" $postdata = "body=" & $s ; need to encode this $header = 'Authorization: OAuth oauth_consumer_key="' & $oauth_consumer_key & '"' $header &= ',oauth_token="' & $oauth_token & '"' $header &= ',oauth_signature_method="PLAINTEXT"' $header &= ',oauth_timestamp="' & Timestamp() & '"' $header &= ',oauth_nonce="' & Nonce() & '"' $header &= ',oauth_signature="' & $oauth_signature & '"' $header &= ' Content-Type: application/x-www-form-urlencoded' $response = MakeRequest("POST", $path, $postdata, $header) _ArrayDisplay($response) ;~ Refresh() EndFunc Func Startup() ; see if ini file is there first If Not FileExists($ini) Then FileOpen($ini, 10) FileClose($ini) EndIf $temp_token = IniRead($ini, "auth", "tk", "") $temp_signature = IniRead($ini, "auth", "sig", "") If $temp_token = "" Then ; if blank, do initial authorization first AuthStuff("SHOW") MsgBox(16, "Initial setup required", "It appears that you have not set up authorization.") Authorize() Else $oauth_token = $temp_token $oauth_signature = $temp_signature ;~ Refresh() EndIf EndFunc Func MakeRequest($req_type, $req_path, $req_postdata, $req_header, $req_return_type = 1) ; set up connection, pass arguments and return something ... options for returning? Local $t_or_f Switch $req_return_type Case 1 ; default return type $t_or_f = "True" Case 2 $t_or_f = "False" EndSwitch Local $session = _WinHttpOpen() Local $connection = _WinHttpConnect($session, $host) Local $response = _WinHttpSimpleSSLRequest($connection, $req_type, $req_path, $req_postdata, Default, $req_header, $t_or_f) _WinHttpCloseHandle($connection) _WinHttpCloseHandle($session) Return $response EndFunc Func SetTokenStrings($s) ; we need oauth_token and oauth_token_secret from string and might be out of order $aResponse = StringSplit($s, "&") For $i = 0 To UBound($aResponse) -1 If StringInStr($aResponse[$i], "oauth_token=") Then $oauth_token = StringReplace($aResponse[$i], "oauth_token=", "") ElseIf StringInStr($aResponse[$i], "oauth_token_secret=") Then $oauth_token_secret = StringReplace($aResponse[$i], "oauth_token_secret=", "") EndIf Next $oauth_signature = $oauth_consumer_secret & "%26" & $oauth_token_secret EndFunc Func Timestamp() Local $rslt = DllCall("msvcrt.dll", "int:cdecl", "time", "int", 0) If @error = 0 Then Return $rslt[0] Return -1 EndFunc Func Nonce() Return Random(100000000, 999999999, 1) EndFunc
    1 point
  27. jennico

    BigNum UDF

    problem of this thread is, that you cannot find it because there is hardly text in here with keywords. so i will add some tags: BigInt BigDec BigNum BigNumber BigDecimal BigInteger overflow stringnumber floating float limitation limit big factorial fibonacci pi calculation arbitrary precision _BigNum_Add _BigNum_Sub _BigNum_Mul _BigNum_Div _BigNum_Mod _BigNum_Round _BigNum_Compare _BigNum_Swap Addition subtrction multiplication division number range size signed some more operations could be useful: sqrt, exponentiantion, random, abs j.
    1 point
×
×
  • Create New...