Leaderboard
Popular Content
Showing content with the highest reputation on 07/19/2015 in all areas
-
This is an AutoIt UDF to help you upload images using Imgur API. Simple example: #NoTrayIcon #include 'Imgur.au3' Global $fp = FileOpenDialog('Open', @ScriptDir, 'Images (*.jpg;*.gif;*.png;*.bmp)', 1) If Not @error Then Local $image_url = _imgur_upload($fp) If @error Then MsgBox(16 + 262144, 'Error', 'Upload image failed!') Else ; Open with default browser ShellExecute($image_url) EndIf EndIfDownload: Imgur UDF by Juno_okyo.zip Github: https://github.com/J2TeaM/AutoIt-Imgur-UDF ----- In the UDF, I have used Base64 and JSON UDF by @Ward. Thank you!4 points
-
Wait, that's exactly what netsh shows. Right? Then maybe try it like this: Global Const $dtag_IMbnPinManagerEvents = _ 'OnPinListAvailable hresult();' & _ 'OnGetPinStateComplete hresult(' & _ 'ptr;' & _ ; /* [in] */ __RPC__in_opt IMbnPinManager *pinManager 'int;int;ulong;' & _ ; /* [in] */ MBN_PIN_INFO pinInfo 'ulong;' & _ ; /* [in] */ ULONG requestID 'hresult;)' ; /* [in] */ HRESULT status ;... Func oIMbnPinManagerEvents_OnGetPinStateComplete($pSelf, $pIMbnPinManager, $pinState, $pinType, $attemptsRemaining, $iRequestID, $iStatus) ;~ https://msdn.microsoft.com/en-us/library/windows/desktop/dd323119%28v=vs.85%29.aspx ConsoleWrite('+ OnGetPinStateComplete event' & @CRLF) ConsoleWrite('> $pIMbnPinManager: ' & $pIMbnPinManager & @CRLF) ConsoleWrite('> $pinState: ' & $pinState & @CRLF) ConsoleWrite('> $pinType: ' & $pinType & @CRLF) ConsoleWrite('> $attemptsRemaining: ' & $attemptsRemaining & @CRLF) ConsoleWrite('> $iRequestID: ' & $iRequestID & @CRLF) ConsoleWrite('> $iStatus: ' & $iStatus & @CRLF) Return $S_OK EndFunc3 points
-
I had sex yesterday. Several times. Then I went nightswimming to cool-off. Then I had more sex. I'm sure now you can understand why it took me this long to reply3 points
-
Hi, I think, you all know this: You look at a script containing color values. You have a rough idea of the colors, but would like to know how it looks like. I have created a Lua script that displays the color of the value in SciTE as Calltip. Set the cursor in the Hex-value, press the hotkey. Above the value a Call tip appears. The background color corresponds to the hex value. Read the function header to obtain installation instructions. So it looks. EDIT: I think it's better to bind the function not only of AutoIt. If it can be called in all files, also the color settings in the * .properties can view. For this purpose remove the file attachment from the call. Use: command.13.*= instead of: command.13.*.au3= EDIT 20.07.2015: Now I've made some changes - You can switch to show colors as RGB or BGR - added new function: PreviewBackForeColor To have a preview for back and fore color: - Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)". If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true" - No other color value may be included in this line. If any - the first and second color will used. - Set the cursor in this line and hit the Hotkey. - A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value. - If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color. In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0" Because you've different functions in one script, you need another way to install and call it. Read the instructions inside the script. First color used as back color, second as fore color. Function called with flag - first color is now the fore color. EDIT 2018-01-16: Added: Now be also recognized in au3 scripts, variables/constants which have an color assignment inside the script or inside an include file from this script. But it can only be one assignment per line. If the assignment is inside a comment line or -block, it will ignored. The assignment can also be build by using function(s) [from script or include files]. example: "Local $COLOR = '0x' & Hex(Mod(@SEC, 2) ? Random(0,0x000FFF, 1) : Random(0x001000, 0xFFF000, 1), 8)" But the functions must NOT CONTAIN any VARIABLES! This would require a recursive assignment search. Impossible if variables get values only at runtime. You can disable the search inside include files with an entry in SciTEUser.properties: #~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1 NO/YES) Get.Color.Assignment.Includes=0 The default value (without settings) is '1', enabled. Includes in comments will ignored. current version v0.8 EDIT 2018-02-22: Changed: Read assignment from function call got any problems - removed. Fixed: Unexpected behavior if caret doesn't touch any hex value while calling the function. Added: Recognition of hex values from length 1 hex character. Added: Instead of default behavior for hiding the calltip, [line 75] local bCALLTIP_END_ANYKEY = true can be used to immediately fade out the tip every time you press a key or move a mouse. current version v0.10 -- TIME_STAMP 2018-02-22 10:26:36 v 0.10 --[[------------- I N S T A L L A T I O N A N D U S I N G I N S T R U C T I O N -------------- Save the file. At first, make an entry in your SciTEStartup.lua LoadLuaFile("ShowHexColorFromCursor.lua", "C:\\Your Path\\with Backslash\\") Select free command-numbers from your SciTEUser.properties. Customize the following settings with this numbers. # 13 Show HexColor RGB command.name.13.*=Show RGB-Color From Cursor command.13.*=dostring ShowHexColorFromCursor() command.mode.13.*=subsystem:lua,savebefore:yes command.shortcut.13.*=Ctrl+Shift+F11 # 14 Show HexColor BGR command.name.14.*=Show BGR-Color From Cursor command.14.*=dostring ShowHexColorFromCursor(true) command.mode.14.*=subsystem:lua,savebefore:yes command.shortcut.14.*=Ctrl+Alt+F11 Set the cursor in the Hex-value, press the hotkey to show the color as RGB or as BGR. Above the value a Call tip appears. The background color corresponds to the hex value. A possible alpha component is ignored. [NEW] Now be also recognized in au3 scripts, variables/constants which have an color assignment inside the script or inside an include file from this script. PLEASE NOTE: Each line may only contain one assignment! If the assignment is inside a comment line or -block, it will ignored. You can disable the search inside include files with an entry in SciTEUser.properties: #~ "ShowHexColorFromCursor.lua", Dis/Enable search in Includes (0/1 NO/YES) Get.Color.Assignment.Includes=0 The default value (without settings) is '1', enabled. Includes in comments will ignored. Be recognized AutoIt hex color code "0x12AB34" and also HTML hex color code "#12AB34" with length from 1 to 6 hex characters. Possible alpha information will ignored. PREVIEW FOR BACK AND FORE COLOR: - Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)". If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true" - No other color value may be included in this line. If any - the first and second color will used. - Set the cursor in this line and hit the Hotkey. - A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value. - If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color. In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0" For use with AutoIt color values only. To have both calls (w/wo flag) make two commands: # 11 Preview Back and Fore Color / first color value is back color command.name.11.*.au3=Preview Back and Fore Color command.11.*.au3=dostring PreviewBackForeColor() command.mode.11.*.au3=subsystem:lua,savebefore:yes command.shortcut.11.*.au3=Ctrl+Shift+F12 # 16 Preview Fore and Back Color / first color value is fore color command.name.16.*.au3=Preview Fore and Back Color command.16.*.au3=dostring PreviewBackForeColor(true) command.mode.16.*.au3=subsystem:lua,savebefore:yes command.shortcut.16.*.au3=Ctrl+Alt+F12 --------------------------------------------------------------------------------------------------]] local bDEBUG = false -- set "true" to get debug output local bCALLTIP_END_ANYKEY = false -- set "true" to cancel the calltip with any key or mouse move ------------------------------------------------------------ list object to manipulate simple tables local objList = { list = {}, delall = function(self) self.list = {} return self end, addonce = function(self, _val, _casesense) -- return true, if added local exists = function(_val, _casesense) for k in pairs(self.list) do if _casesense then if self.list[k] == _val then return true end else if tostring(self.list[k]):upper() == tostring(_val):upper() then return true end end end return false end if not exists(_val, _casesense) then table.insert(self.list, _val) return true end return nil end, new = function(self, _obj) _obj = _obj or {} setmetatable(_obj, self) self.__index = self return _obj end } --------------------------------------------------------------------------------------- /object list --------------------------------------------------------------------------------------- object color local objColor = { --------------------------------------------- variable will un/set if color-calltip is not/shown colortip_show = false, --------------------------------- user can disable search inside include files, default: enabled search_in_includes = true, ------------------------------------------------------------------- the default calltip position calltips_pos_def = false, ------------------------------------------------------------ the default calltip highlight color calltips_colorhlt_def = 0x0000FF, -- BGR (red) ---------------------------------------------------------- list with include storage directories lInclPathes = objList:new(), -------------------------------------------------- list/string with includes from current buffer lIncl = objList:new(), sIncl = '', ---------------------------------------------------------------------------------------- pattern pattHex = '()0x([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])', pattHex2 = '[0-9a-fA-F][0-9a-fA-F]', pattHexN = '0-[x#]([0-9a-fA-F]+)', pattHexEnd = '0x[0-9a-fA-F]+()', pattCS1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ss][Tt][Aa][Rr][Tt]', pattCE1 = '^#[Cc][Oo][Mm][Mm][Ee][Nn][Tt][Ss]%-[Ee][Nn][Dd]', pattCS2 = '^#[Cc][Ss]', pattCE2 = '^#[Cc][Ee]', pattComment = '^%s*;', ----------------------------------------------------------------------------------------- pathes sPathGetColorAU3, sFileResult, TEMPDIR = props['SciteUserHome']..'\\..\\..\\Temp', sAU3exe = props['SciteDefaultHome']..'\\..\\AutoIt3.exe', ------------------------------------------------------------------------------------------------ ------------------------------------------------------------ set calltip values back to defaults SetCalltipsDefault = function(self) self.colortip_show = false scite.SendEditor(SCI_CALLTIPSETBACK, 0xFFFFFF) scite.SendEditor(SCI_CALLTIPSETFOREHLT, self.calltips_colorhlt_def) scite.SendEditor(SCI_CALLTIPSETPOSITION, self.calltips_pos_def) if bDEBUG then output:AppendText('> DEBUG: Calltips set to defaults') end end, ---------------------------------------------------------------------------- /SetCalltipsDefault ------------------------------------------------------------------------------ initialize values Startup = function(self) if props['Get.Color.Assignment.Includes'] == '0' then self.search_in_includes = false end if tonumber(props['calltips.set.above']) == 1 then self.calltips_pos_def = true end if props['calltips.color.highlight'] ~= '' then local colorhlt_user = myCallTips:BGR2Decimal(props['calltips.color.highlight']) if colorhlt_user ~= nil then self.calltips_colorhlt_def = colorhlt_user end end local sProp = props['openpath.$(au3)'] for w in sProp:gmatch('([^;]+)') do self.lInclPathes:addonce(w) end self.sPathGetColorAU3 = self.TEMPDIR..'\\ExecLineGetColor.au3' self.sFileResult = self.TEMPDIR..'\\ExecLineColor.txt' end, --------------------------------------------------------------------------------------- /Startup -------- check for comment line/block. Return "true/false, 0/1/-1" (0=comment line/1=#cs/-1=#ce) -- returned number for de/increase comment counter CheckComment = function(self, _s) local iMatch = _s:find(self.pattComment) if iMatch ~= nil then return true, 0 end iMatch = _s:find(self.pattCS1) or _s:find(self.pattCS2) if iMatch ~= nil then return true, 1 end iMatch = _s:find(self.pattCE1) or _s:find(self.pattCE2) if iMatch ~= nil then return true, -1 end return false, 0 end, ------------------------------------------------------------------------------------------------ --------------------------------------------------------- read include files from current buffer IncludesFromBuffer = function(self) local sText, boolCmnt, countCmnt, n, incl = editor:GetText(), false, 0 self.lIncl:delall() self.sIncl = '' for line in sText:gmatch('([^\r\n]+)') do boolCmnt, n = self:CheckComment(line) if boolCmnt then countCmnt = countCmnt + (n) end if not boolCmnt and countCmnt == 0 then -- none comment line or block -- #include <abc.au3> incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-<([%w%s_.]+)>") if incl ~= nil then if self.lIncl:addonce(incl) then self.sIncl = self.sIncl..'#include <'..incl..'>\n' if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include <'..incl..'>"\n') end end else -- #include 'abc.au3' or #include "abc.au3" _, incl = line:match("#[iI][nN][cC][lL][uU][dD][eE]%s-([\"'])([%w%s_.:\\]+)%1") if incl ~= nil then if incl:sub(1,1) == '\\' then incl = incl:sub(2,-1) end if self.lIncl:addonce(incl) then if incl:sub(2,2) == ':' then self.sIncl = self.sIncl..'#include "'..incl..'"\n' if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include '.."'"..incl.."'"..'"\n') end else self.sIncl = self.sIncl..'#include "'..props['FileDir']..'\\'..incl..'"\n' if bDEBUG then output:AppendText('> DEBUG: IncludesFromBuffer.Add "#include '.."'"..props['FileDir']..'\\'..incl.."'"..'"\n') end end end end end end end end, ---------------------------------------------------------------------------- /IncludesFromBuffer ------------------------------------------ create the au3 file for executing the assignment line CreateAU3 = function(self, _sLineAssignment) local sTextAU3 = self.sIncl.. 'Global $sFileExport = @TempDir & "\\ExecLineColor.txt"\n'.. 'FileDelete($sFileExport)\n'.. 'Global $sLine = "'.._sLineAssignment..'" ; line: $Variable = assignment\n'.. 'If $sLine = "NONE" Then Exit\n'.. 'Global $sExec = StringTrimLeft($sLine, StringInStr($sLine, "="))\n'.. 'Global $sColor = "0x" & Hex(Execute($sExec), 6)\n'.. 'If Not StringRegExp($sColor, "^0x[0-9A-F]{6}$") Then Exit\n'.. 'FileWrite($sFileExport, $sColor)\n' local fH = io.open(self.sPathGetColorAU3, 'w+') fH:write(sTextAU3) fH:close() end, ------------------------------------------------------------------------------------- /CreateAU3 --------------------------------- check, if file containing the assignment for selected variable FindAssignment = function(self, _path, _sSelection) local fH = io.open(_path) if fH ~= nil then local sRead, boolCmnt, countCmnt, n = fH:read('*all'), false, 0 fH:close() for line in sRead:gmatch('([^\r\n]+)') do boolCmnt, n = self:CheckComment(line) if boolCmnt then countCmnt = countCmnt + (n) end if not boolCmnt and countCmnt == 0 then -- none comment line or block if line:find(_sSelection..'%s*=') then if bDEBUG then output:AppendText('> DEBUG: Assignment line "'..line..'"\n') end return line end end end end return nil end, -------------------------------------------------------------------------------- /FindAssignment -------------------------------------------------------------------- detects color from variable GetColorValueFromVariable = function(self, _sSelection, _iCursor, _var_beginPos, _var_endPos, _fBGR) local sLine = self:FindAssignment(props['FilePath'], _sSelection) if sLine == nil then -- search inside include files -- do it not, if the user has disabled: "Get.Color.Assignment.Includes=0" (default = 1 - enabled) if self.search_in_includes then self:IncludesFromBuffer() -- get include files if #self.lIncl.list ~= 0 then -- open each include file, search line with assignment "_sSelection =" for i=1, #self.lIncl.list do if self.lIncl.list[i]:sub(2,2) == ':' then -- include has full path, search only in this file sLine = self:FindAssignment(self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end end if sLine == nil and self.lIncl.list[i]:find('\\') then -- include has partial path, check first if exist in @ScriptDir sLine = self:FindAssignment(props['FileDir']..'\\'..self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..props['FileDir']..'\\'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end end if sLine == nil then -- include has filename only (or partial path), -- .. concanate all directories with this for searching for j=1, #self.lInclPathes.list do sLine = self:FindAssignment(self.lInclPathes.list[j]..'\\'..self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..self.lInclPathes.list[j]..'\\'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end if sLine == nil then sLine = self:FindAssignment(props['FileDir']..'\\'..self.lIncl.list[i], _sSelection) if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" in "'..props['FileDir']..'\\'..self.lIncl.list[i]..'" --> '..tostring(sLine ~= nil)..'\n') end end if sLine ~= nil then break end end end end end end end if sLine == nil then sLine = 'NONE' else -- trim characters right from assignment sLine = sLine:sub(1,sLine:match(self.pattHexEnd)) end if bDEBUG then output:AppendText('> DEBUG: Search "'.._sSelection..'" \n> DEBUG: Result "'..sLine..'"\n') end -- create the au3-file for executing the assignment line, with 'NONE' - the last result file will delete self:CreateAU3(sLine) -- run the au3-file local sCmd = '"'..self.sAU3exe..'" /AutoIt3ExecuteScript "'..self.sPathGetColorAU3..'"'..' "'..sLine..'"' if shell then shell.exec(sCmd, nil, true, true) else os.execute('start "" '..sCmd) end -- check for result local fH = io.open(self.sFileResult) if fH == nil then scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' NONE COLOR ASSIGNED! ')) scite.SendEditor(SCI_CALLTIPSETHLT, 0, 22) scite.SendEditor(SCI_CALLTIPSETBACK, 0x33FFFF) scite.SendEditor(SCI_CALLTIPSETFOREHLT, 0x0000FF) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if bDEBUG then output:AppendText('> DEBUG: Set Calltip "'.._sSelection..'" --> "NONE COLOR ASSIGNED!"\n') end else local sValue = fH:read() fH:close() local R,G,B = sValue:match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$') local iLen = _var_endPos - _var_beginPos -1 scite.SendEditor(SCI_CALLTIPSHOW, _var_beginPos +1, (' '):rep(iLen)) scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if _fBGR == true then scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip BGR "'.._sSelection..'" --> "'..string.format('0x%s%s%s', R,G,B)..'"\n') end else scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip RGB "'.._sSelection..'" --> "'..string.format('0x%s%s%s', B,G,R)..'"\n') end end end self.colortip_show = true editor:SetSelection(_iCursor, _iCursor) end, --------------------------------------------------------------------- /GetColorValueFromVariable ----------------------------------------- grabs the color value or variable from cursor position FromCursor = function(self, _fBGR) local function isHexChar(_asc) local sChar = string.char(_asc) if sChar:find('[#x0-9a-fA-F]') then return true else return false end end local cursor = editor.CurrentPos -- check if cursor is possible inside a variable local var_beginPos, var_endPos = cursor if string.char(editor.CharAt[cursor]) ~= '$' then -- cursor is inside or behind the variable (if its a variable) editor:WordLeft() -- skip to the left end var_beginPos = editor.CurrentPos -- is it a variable? if string.char(editor.CharAt[var_beginPos]) == '$' then -- now the cursor is in front of variable editor:WordRight() var_endPos = editor.CurrentPos editor:SetSelection(var_beginPos, var_endPos) local sSelection = editor:GetSelText() local iLenSel = sSelection:len() -- trim spaces on right site, if any sSelection = sSelection:gsub('%s+$','') var_endPos = var_endPos - (iLenSel - sSelection:len()) if bDEBUG then output:AppendText('> DEBUG: Cursor on variable "'..sSelection..'"\n') end return self:GetColorValueFromVariable(sSelection, cursor, var_beginPos, var_endPos, _fBGR) end -- cursor inside hex value? local beginPos, endPos = cursor, cursor while isHexChar(editor.CharAt[beginPos-1]) do beginPos = beginPos - 1 end while isHexChar(editor.CharAt[endPos]) do endPos = endPos + 1 end if beginPos ~= endPos then if beginPos > endPos then editor:SetSelection(endPos, beginPos) else editor:SetSelection(beginPos, endPos) end local sMatch = tostring(editor:GetSelText()):match(self.pattHexN) if sMatch == nil then return editor:SetSelection(cursor, cursor) end local sHex6 = '0x'..('0'):rep(6-sMatch:len())..sMatch local iLen = sMatch:len() +2 local R,G,B = tostring(sHex6):match('('..self.pattHex2..')('..self.pattHex2..')('..self.pattHex2..')$') if bDEBUG then output:AppendText('> DEBUG: Cursor on hex value\n') end editor:SetSelection(cursor, cursor) scite.SendEditor(SCI_CALLTIPSHOW, beginPos+1, (' '):rep(iLen-1)) scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen-1) scite.SendEditor(SCI_CALLTIPSETPOSITION, true) if _fBGR == true then scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip BGR hex value --> "'..string.format('0x%s%s%s', R,G,B)..'"\n') end else scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R))) if bDEBUG then output:AppendText('> DEBUG: Set Calltip RGB hex value --> "'..string.format('0x%s%s%s', B,G,R)..'"\n') end end self.colortip_show = true else editor:SetSelection(cursor, cursor) end end, ------------------------------------------------------------------------------------ /FromCursor ----------------------------------------------------------------------- show back and fore color PreviewBackForeColor = function(self, _fFore1st) local iBackCol, iForeCol = 0xF0F0F0, 0x000000 local cursor = editor.CurrentPos local sLine, iColumn = editor:GetCurLine() local iLineStartPos = cursor - iColumn local tMatch, beginPos = {}, nil for s, r, g, b in sLine:gmatch(self.pattHex) do if beginPos == nil then beginPos = s end local t = {} t['R']=r t['G']=g t['B']=b table.insert(tMatch, t) end if #tMatch == 0 then if bDEBUG then output:AppendText('> DEBUG: Search back/fore color --> "FAILED"\n') end return elseif #tMatch == 1 then if _fFore1st == true then iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end else iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end end else if _fFore1st == true then iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) iBackCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)..'"\n') end else iForeCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)) iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)) if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "ForeColor" --> "'..string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R)..'"\n') end if bDEBUG then output:AppendText('> DEBUG: Search back/fore color "BackColor" --> "'..string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R)..'"\n') end end end if bDEBUG then output:AppendText('> DEBUG: Set calltip back/fore color\n') end scite.SendEditor(SCI_CALLTIPSHOW, iLineStartPos + beginPos, ' FORE-COLOR ') scite.SendEditor(SCI_CALLTIPSETHLT, 0, 12) scite.SendEditor(SCI_CALLTIPSETBACK, iBackCol) scite.SendEditor(SCI_CALLTIPSETFOREHLT, iForeCol) self.colortip_show = true end -------------------------------------------------------------------------- /PreviewBackForeColor } -------------------------------------------------------------------------------------- /object color ---------------------------------------------------------------------------------- region EventClass ShowColorEvt = EventClass:new(Common) function ShowColorEvt:OnKey() if objColor.colortip_show then if bCALLTIP_END_ANYKEY then scite.SendEditor(SCI_CALLTIPCANCEL) end objColor:SetCalltipsDefault() end end function ShowColorEvt:OnDwellStart() if objColor.colortip_show then if bCALLTIP_END_ANYKEY then scite.SendEditor(SCI_CALLTIPCANCEL) end objColor:SetCalltipsDefault() end end --------------------------------------------------------------------------------- /region EventClass -------------------------------------------------------------------------- function call redirection function ShowHexColorFromCursor(_fBGR) objColor:FromCursor(_fBGR) end --> ShowHexColorFromCursor function PreviewBackForeColor(_fFore1st) objColor:PreviewBackForeColor(_fFore1st) end --> PreviewBackForeColor ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- run startup objColor:Startup() ---------------------------------------------------------------------------------------------------- ShowHexColorFromCursor[0.10].lua2 points
-
trancexx, Well spotted. It's probably all that swimming.2 points
-
Heavenly! I could barely walk before it, and afterwards I was like new.2 points
-
Virtual listviews are lightning fast and can handle millions of rows. Virtual listviews are of interest when you have to insert more than 10,000 rows. When there are less than 10,000 rows, the standard listviews are sufficiently rapid. See the section "Using standard listviews" below. In a virtual listview data are not stored directly in the listview. Data are stored in an array, a structure (DllStructCreate), a flat fixed-length record file, a database or similar. The listview only contains the rows which are visible depending on the height of the listview. See About List-View Controls in the MicroSoft documentation for more information. An array or a structure can be used for listviews with 10,000 - 100,000 rows. If there are more than 100,000 rows a fixed-length record file or a database seems to be the best solution, because they have low impact on memory usage. But you get nothing for free. The costs is that a part of the built-in features does not work, and you will have to implement these features yourself. Because data isn't stored in the listview the Set- and Get-functions to manipulate data doesn't work. You have to manipulate the data source directly. And sorting is not supported at all by virtual listviews. If you need sorting, a database seems to be the best solution in all cases, because sorting can be handled by the database. Below you'll find the following sections: Data stored in arrays Data stored in databases Data stored in fixed-length record files Sorting rows in a virtual listview $LVN_ODFINDITEM notifications Using standard listviews Updates Zip file Examples The next two sections shows how to use virtual listviews, when data are stored in arrays or databases. In first section data are stored in 3 arrays with 10,000/50,000/100,000 rows and 10 columns. In second section data are stored in 3 databases with 100,000/1,000,000/10,000,000 rows and 10 columns. Data stored in arrays For a virtual listview rows are displayed with $LVN_GETDISPINFO notifications and the $tagNMLVDISPINFO structure. Code for $LVN_GETDISPINFO messages in the WM_NOTIFY function can be implemented in this manner: Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $sItem = $aItems[DllStructGetData($tNMLVDISPINFO,"Item")][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) EndIf Run LvVirtArray.au3. It takes some time to create the arrays. But when the arrays are created, switching from one array to another (which means updating the listview) is instantaneous. Data stored in databases When data are stored in a database, $LVN_ODCACHEHINT notifications and the $tagNMLVCACHEHINT structure is used to insert the rows in an array cache before they are displayed with $LVN_GETDISPINFO messages. The $tagNMLVCACHEHINT structure is defined in this way: Global Const $tagNMLVCACHEHINT = $tagNMHDR & ";int iFrom;int iTo" Note that $tagNMLVCACHEHINT is not included in GuiListView.au3 or StructureConstants.au3. Code for $LVN_ODCACHEHINT messages in the WM_NOTIFY function can be implemented in this manner: Case $LVN_ODCACHEHINT Local $tNMLVCACHEHINT = DllStructCreate( $tagNMLVCACHEHINT, $lParam ), $iColumns $iFrom = DllStructGetData( $tNMLVCACHEHINT, "iFrom" ) Local $sSQL = "SELECT * FROM lvdata WHERE item_id >= " & $iFrom & _ " AND item_id <= " & DllStructGetData( $tNMLVCACHEHINT, "iTo" ) & ";" _SQLite_GetTable2d( -1, $sSQL, $aResult, $iRows, $iColumns ) $aResult is the array cache. The purpose of the cache is to limit the number of SELECT statements. When the listview is displayed for the first time, all visible rows (in this example about 20) have to be updated. In this case $aResult will contain 20 rows and 10 columns. 20 rows is also the maximum number of rows in $aResult. A virtual listview will never update more than the visible number of rows at one time. Code for $LVN_GETDISPINFO messages can be implemented in this way: Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $iIndex = DllStructGetData( $tNMLVDISPINFO, "Item" ) - $iFrom + 1 If $iIndex > 0 And $iIndex < $iRows + 1 Then Local $sItem = $aResult[$iIndex][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) EndIf EndIf The zip below contains a small GUI, CreateDB.au3, to create 3 SQLite databases with 100,000/1,000,000/10,000,000 rows. The databases will use about 10/100/1000 MB of diskspace, and the creation will take about ½/5/40 minutes (on an old XP). You must select a database and click a button to start the creation. If you get tired of waiting, you can cancel (checked for every 10,000 rows) the process and continue another time. The process will continue where it stopped. You can run the examples even though the databases might only contain 30,000/200,000/1,500,000 rows. You do not have to create all three databases. Run LvVirtDB.au3. Data stored in fixed-length record files (update 2015-04-01) Extracting data directly from a fixed-length record file by setting the file pointer to the current record and reading the required number of bytes is another example, where $LVN_ODCACHEHINT messages should be used to insert records in an array cache before they are displayed. Code for $LVN_ODCACHEHINT and $LVN_GETDISPINFO messages can be implemented as shown: Case $LVN_ODCACHEHINT Local $tNMLVCACHEHINT = DllStructCreate( $tagNMLVCACHEHINT, $lParam ) $iFrom = DllStructGetData( $tNMLVCACHEHINT, "iFrom" ) $iRows = DllStructGetData( $tNMLVCACHEHINT, "iTo" ) - $iFrom + 1 FileSetPos( $hFile, $iFrom * 12, 0 ) ; Each line is 10 chars + CR + LF $aCache = StringSplit( FileRead( $hFile, $iRows * 12 - 2 ), @CRLF, 3 ) The purpose of the cache is to limit the number of FileRead statements. Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $iIndex = DllStructGetData( $tNMLVDISPINFO, "Item" ) - $iFrom If -1 < $iIndex And $iIndex < $iRows Then DllStructSetData( $tText, 1, $aCache[$iIndex] ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", 10 ) ; Each line is 10 chars EndIf EndIf Run LvVirtFile.au3. A fixed-length record file with 10,000 records (LvVirtFile.txt) is included in the zip. I have tested this example on a 1,1 GB file and 100,000,000 rows. The listview responds immediately. The solution with a flat fixed-length record file is extremely fast. Much faster than a database. But also with very much limited functionality compared to a database. Sorting rows in a virtual listview (update 2015-04-01) Sorting is not supported at all by virtual listviews. If you want rows to be sorted, you have to feed the listview with the rows in sorted order. If the rows are stored in an array, you have to sort the array before you feed the listview. If you want to sort the rows by two or more columns, you have to store the rows in two or more arrays which are sorted for the current column. Or you have to create two or more indexes to handle the sorting. Sorting arrays and creating indexes is time consuming. If you need sorting, a database seems to be the best solution, because sorting can be handled by the database. Nevertheless, here's an example that stores 10,000/20,000/30,000 rows and 3 columns in arrays, and creates indexes to handle the sorting. The columns are strings, integers and floating point numbers, and indexes are calculated for all 3 columns. To be able to create the indexes as fast as possible, structures (DllStructCreate) are used to create the indexes. This is the function to create indexes for integers and floating point numbers. The function for strings is equivalent. $tIndex = DllStructCreate( "uint[" & $iRows & "]" ) Func SortNumbers( ByRef $aItems, $iRows, $iCol, $pIndex, $tIndex ) Local $k, $n, $lo, $hi, $mi, $gt HourglassCursor( True ) WinSetTitle( $hGui, "", "Virtual ListViews. Sort numbers: 0 rows" ) For $i = 0 To $iRows / 10000 - 1 $k = $i * 10000 For $j = 0 To 9999 $n = $aItems[$k+$j][$iCol] ; Binary search $lo = 0 $hi = $k + $j - 1 While $lo <= $hi $mi = Int( ( $lo + $hi ) / 2 ) If $n < $aItems[DllStructGetData($tIndex,1,$mi+1)][$iCol] Then $gt = 0 $hi = $mi - 1 Else $gt = 1 $lo = $mi + 1 EndIf WEnd ; Make space for the new value DllCall( $hKernel32Dll, "none", "RtlMoveMemory", "struct*", $pIndex+($mi+1)*4, "struct*", $pIndex+$mi*4, "ulong_ptr", ($k+$j-$mi)*4 ) ; Insert new value DllStructSetData( $tIndex, 1, $k+$j, $mi+1+$gt ) Next WinSetTitle( $hGui, "", "Virtual ListViews. Sort numbers: " & $k + 10000 & " rows" ) Next HourglassCursor( False ) WinSetTitle( $hGui, "", "Virtual ListViews (sorted)" ) EndFunc Run LvVirtArraySort.au3. It takes some time to create the arrays and indexes. But when everything is created, sorting by different columns and switching from one array to another is instantaneous. Because it's easy and fast to save/load a structure to/from a binary file, it may be advantageous to calculate the arrays and indexes in another script before the GUI is opened. $LVN_ODFINDITEM notifications (update 2015-04-01) Three notifications are important for virtual listviews. $LVN_GETDISPINFO (to get information about the rows to display in the listview) and $LVN_ODCACHEHINT (to store rows from a file or database in an array cache before they are displayed with $LVN_GETDISPINFO messages) are already mentioned above. The last is $LVN_ODFINDITEM, which is used to find a row when you press one or a few keys on the keyboard. Information from $LVN_ODFINDITEM is stored in the $tagNMLVFINDITEM structure. The codebox shows the code for $LVN_ODFINDITEM notifications: Case $LVN_ODFINDITEMW Local $tNMLVFINDITEM = DllStructCreate( $tagNMLVFINDITEM, $lParam ) If BitAND( DllStructGetData( $tNMLVFINDITEM, "Flags" ), $LVFI_STRING ) Then Return SearchText( DllStructGetData( $tNMLVFINDITEM, "Start" ), _ ; Start DllStructGetData( DllStructCreate( "wchar[20]", DllStructGetData( $tNMLVFINDITEM, "Text" ) ), 1 ) ) ; Text EndIf Start is the row where you start the search. Text contains the key presses to search for. You have to implement the search function (here SearchText) yourself. If the function finds a row, it should return the index of the row. If not, it should return -1. Run LvVirtArrayFind.au3. Using standard listviews (update 2015-04-01) If not more than 10,000 rows have to be inserted in a listview, a standard listview is sufficiently rapid. Because of speed you should use native (built-in) functions to fill the listview and not functions in GuiListView.au3 UDF. When the listview is filled, you can use all the functions in the UDF. This code shows how to quickly fill a listview with native functions: Func FillListView( $idLV, ByRef $aItems, $iRows ) Local $tLVITEM = DllStructCreate( $tagLVITEM ) Local $pLVITEM = DllStructGetPtr( $tLVITEM ), $k, $s DllStructSetData( $tLVITEM, "Mask", $LVIF_IMAGE ) ; Icon (or image) DllStructSetData( $tLVITEM, "SubItem", 0 ) ; First column HourglassCursor( True ) For $i = 0 To $iRows / 10000 - 1 $k = $i * 10000 For $j = 0 To 9999 ; Text $s = $aItems[$k+$j][0] For $l = 1 To 9 $s &= "|" & $aItems[$k+$j][$l] Next GUICtrlCreateListViewItem( $s, $idLV ) ; Add item and all texts ; Icon Select Case Mod( $k + $j, 3 ) = 0 DllStructSetData( $tLVITEM, "Image", 2 ) ; Icon index Case Mod( $k + $j, 2 ) = 0 DllStructSetData( $tLVITEM, "Image", 1 ) Case Else DllStructSetData( $tLVITEM, "Image", 0 ) EndSelect DllStructSetData( $tLVITEM, "Item", $k + $j ) ; Row GUICtrlSendMsg( $idLV, $LVM_SETITEMW, 0, $pLVITEM ) ; Add icon Next WinSetTitle( $hGui, "", "GUICtrlCreateListViewItem ListViews. Fills listview: " & $k + 10000 & " rows" ) Next HourglassCursor( False ) WinSetTitle( $hGui, "", "GUICtrlCreateListViewItem ListViews" ) EndFunc Run LvStandard.au3. LvStandardIni.au3 shows how to quickly load an inifile (LvStandardIni.ini, created with IniWriteSection) into a listview. Because an inifile is a small file (only the first 32767 chars are read) it should always be loaded into a standard listview. Updates Update 2015-03-24 Added two array-examples. An example (LvVirtArrayIcons.au3) that shows how to use checkboxes and icons, and an example (LvVirtArrayColors.au3) that shows how to draw every second row with a different background color. In this post you can find an example where all items are drawn with a random background color. Update 2015-04-01 Cleaned up code in previous examples. Added more examples as described above. Zip updated. UDF versions (2018-04-27) Over the past weeks, new display functions have been added to Data display functions based on virtual listviews, and new functions have been added to use the listviews as embedded GUI controls. All the functions work and are used in much the same way. Apart from the data source, the function parameters are the same for all functions. The display functions support a wide range of features, all specified via a single function parameter $aFeatures, which is the last parameter. The central code to handle $LVN_ODCACHEHINT and $LVN_GETDISPINFO notifications is very optimized code. First of all, the code is implemented through the subclassing technique. This means that messages are received directly from the operating system and not from AutoIt's internal message management code. Messages are returned again directly to the operating system and again without interference with AutoIt's internal message handling code. Next, the code is divided into different include files each taking care of a particular feature. That way, it's avoided that a lot of control statements makes the code slow. And it's enough to include the code that's actually used. One reason why so much work has been done in optimizing code and developing features is that these functions will also work as UDF versions for the examples here. It's far from a trivial task to develop UDF versions of examples like these. Since the first version of the display functions was created in this thread 2½ years ago and then has been continuously developed, it's obvious to use the functions as UDF versions of these examples. The following examples are implemented as UDF versions: Data stored in arrays Data stored in CSV files Data stored in SQLite databases Zip file Examples in zip: LvVirtArray.au3 - Data stored in arrays LvVirtArrayColors.au3 - Alternating row colors LvVirtArrayFind.au3 - $LVN_ODFINDITEM notifications LvVirtArrayIcons.au3 - Checkboxes and icons LvVirtArraySort.au3 - Sorting rows in a virtual listview LvVirtDB.au3 - Data stored in databases (use CreateDB.au3 to create DBs) LvVirtFile.au3 - Data stored in fixed-length record files LvStandard.au3 - Using standard listviews LvStandardIni.au3 - Load inifile into a listview The size of the zip is caused by a 118 KB txtfile, LvVirtFile.txt, used by LvVirtFile.au3, and a 28 KB inifile, LvStandardIni.ini, used by LvStandardIni.au3. Tested with AutoIt 3.3.10 on Windows 7 64 bit and Windows XP 32 bit. Should work on all AutoIt versions from 3.3.10 and all Windows versions. Virtual ListViews.7z Examples Examples based on virtual listviews. Array examples: A lot of rows and random background colors for each cell - This post in another thread Incremental search (update as you type) in a virtual listview - Post 29 Sorting arrays: Rows can be sorted by strings, integers, floats and checkboxes, checked rows in top - Post 48 File sources: A CSV-file with 100,000 rows and 10 columns is data source - Post 56 SQLite examples: Various issues related to the use of a database - Post 34, 35, 43 An example that shows a way to implement a search box - Post 411 point
-
Advanced Math UDF
robertocm reacted to scintilla4evr for a topic
I started writing this UDF a while ago, so I decided to share it here. This is an UDF full of advanced mathematical functions. It allows to work with primes, create number sequences, interpolate, calculate values of functions like Riemann zeta. Full list of functions: Changelog: Download1 point -
Actually, msdn documents that struct can be defined as parameter. It's also documented how to handle it. For example on x64 it's like this:1 point
-
SafeArray.au3 it`s LarsJ udf. Ifound it in IUIAutomation MS framework automate chrome, FF, IE topic. #include-once #cs Global Const $tagSAFEARRAY = _ "ushort cDims;" & _ ; The number of dimensions. "ushort fFeatures;" & _ ; Flags, see below. "ulong cbElements;" & _ ; The size of an array element. "ulong cLocks;" & _ ; The number of times the array has been locked without a corresponding unlock. "ptr pvData;" & _ ; The data. "ulong cElements;" & _ ; The number of elements in the dimension. "long lLbound" ; The lower bound of the dimension. ; fFeatures flags Global Const $FADF_AUTO = 0x0001 ; An array that is allocated on the stack. Global Const $FADF_STATIC = 0x0002 ; An array that is statically allocated. Global Const $FADF_EMBEDDED = 0x0004 ; An array that is embedded in a structure. Global Const $FADF_FIXEDSIZE = 0x0010 ; An array that may not be resized or reallocated. Global Const $FADF_RECORD = 0x0020 ; An array that contains records. When set, there will be a pointer to the IRecordInfo interface at negative offset 4 in the array descriptor. Global Const $FADF_HAVEIID = 0x0040 ; An array that has an IID identifying interface. When set, there will be a GUID at negative offset 16 in the safe array descriptor. Flag is set only when FADF_DISPATCH or FADF_UNKNOWN is also set. Global Const $FADF_HAVEVARTYPE = 0x0080 ; An array that has a variant type. The variant type can be retrieved with SafeArrayGetVartype. Global Const $FADF_BSTR = 0x0100 ; An array of BSTRs. Global Const $FADF_UNKNOWN = 0x0200 ; An array of IUnknown*. Global Const $FADF_DISPATCH = 0x0400 ; An array of IDispatch*. Global Const $FADF_VARIANT = 0x0800 ; An array of VARIANTs. Global Const $FADF_RESERVED = 0xF008 ; Bits reserved for future use. #ce Func SafeArrayCreateVector( $sType, $iRows ) Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound" Local Const $FADF_HAVEIID = 0x0040, $FADF_HAVEVARTYPE = 0x0080, $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200 Local Const $VT_INT = 22, $VT_INT_PTR = 37 Local $iVarType, $iFeatures Switch $sType Case "int" $iVarType = $VT_INT Case "ptr" ; IUIAutomationCondition interface pointer $iVarType = $VT_INT_PTR $iFeatures = $FADF_UNKNOWN ; $FADF_UNKNOWN must be included in fFeatures in the SafeArray structure. ; Otherwise an E_INVALIDARG error will occur when the condition is created. If @OSVersion <> "WIN_XP" Then $iFeatures = BitOR( $iFeatures, $FADF_HAVEIID ) ; On Windows later than XP $FADF_HAVEIID is used instead of $FADF_HAVEVARTYPE. Case "str" ; BSTR (binary string) $iVarType = $VT_INT_PTR $iFeatures = $FADF_BSTR Case Else Return SetError(1, 0, 0) EndSwitch Local $aRet = DllCall( "oleaut32.dll", "ptr", "SafeArrayCreateVector", "int", $iVarType, "long", 0, "ulong", $iRows ) If @error Then Return SetError(2, 0, 0) Local $pSafeArray = $aRet[0] Switch $sType Case "ptr" Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray ) Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" ) $fFeatures = BitOR( $fFeatures, $iFeatures ) If @OSVersion <> "WIN_XP" Then $fFeatures = BitXOR( $fFeatures, $FADF_HAVEVARTYPE ) ; On Windows later than XP $FADF_HAVEIID is used instead of $FADF_HAVEVARTYPE. DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures ) Case "str" Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray ) Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" ) $fFeatures = BitOR( $fFeatures, $iFeatures ) DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures ) EndSwitch Return $pSafeArray EndFunc Func SafeArrayGetElement( $pSafeArray, $iIndex, ByRef $vValue ) Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound" Local Const $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200 Local $fFeatures = DllStructGetData( DllStructCreate( $tagSAFEARRAY, $pSafeArray ), "fFeatures" ) Local $sType Select Case BitAND( $fFeatures, $FADF_BSTR ) OR BitAND( $fFeatures, $FADF_UNKNOWN ) $sType = "ptr*" Case Else $sType = "int*" EndSelect Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayGetElement", "ptr", $pSafeArray, "long*", $iIndex, $sType, 0 ) If @error Then Return SetError(1, 0, 1) $vValue = $aRet[3] If BitAND( $fFeatures, $FADF_BSTR ) Then $vValue = SysReadString( $vValue ) If @error Then Return SetError(2, 0, 1) EndIf Return $aRet[0] EndFunc Func SafeArrayPutElement( $pSafeArray, $iIndex, $vValue ) Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound" Local Const $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200 Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray ) Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" ) Local $sType Select Case BitAND( $fFeatures, $FADF_BSTR ) $sType = "ptr*" DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures - $FADF_BSTR ) ; This is a workaround. String is not inserted if $fFeatures includes $FADF_BSTR. $vValue = SysAllocString( $vValue ) If @error Then Return SetError(1, 0, 1) Case BitAND( $fFeatures, $FADF_UNKNOWN ) $sType = "ptr*" DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures - $FADF_UNKNOWN ) ; This is a workaround. The DllCall crashes if $fFeatures includes $FADF_UNKNOWN. Case Else $sType = "int*" EndSelect Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayPutElement", "ptr", $pSafeArray, "long*", $iIndex, $sType, $vValue ) If @error Then Return SetError(2, 0, 1) Select Case BitAND( $fFeatures, $FADF_BSTR ) OR BitAND( $fFeatures, $FADF_UNKNOWN ) DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures ) ; This will undo the workaround. EndSelect Return $aRet[0] EndFunc Func SafeArrayGetUBound( $pSafeArray, ByRef $iUBound ) Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayGetUBound", "ptr", $pSafeArray, "uint", 1, "long*", 0 ) If @error Then Return SetError(1, 0, 1) $iUBound = $aRet[3] Return $aRet[0] EndFunc Func SafeArrayDestroy( $pSafeArray ) Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayDestroy", "ptr", $pSafeArray ) If @error Then Return SetError(1, 0, 1) Return $aRet[0] EndFunc ; BSTR functions ; Copied and slightly modified from AutoItObject.au3 by the AutoItObject-Team Func SysAllocString( $str ) Local $aRet = DllCall( "oleaut32.dll", "ptr", "SysAllocString", "wstr", $str ) If @error Then Return SetError(1, 0, 0) Return $aRet[0] EndFunc Func SysFreeString( $pBSTR ) If Not $pBSTR Then Return SetError(1, 0, 0) DllCall( "oleaut32.dll", "none", "SysFreeString", "ptr", $pBSTR ) If @error Then Return SetError(2, 0, 0) EndFunc Func SysReadString( $pBSTR, $iLen = -1 ) If Not $pBSTR Then Return SetError(1, 0, "") If $iLen < 1 Then $iLen = SysStringLen( $pBSTR ) If $iLen < 1 Then Return SetError(2, 0, "") Return DllStructGetData( DllStructCreate( "wchar[" & $iLen & "]", $pBSTR ), 1 ) EndFunc Func SysStringLen( $pBSTR ) If Not $pBSTR Then Return SetError(1, 0, 0) Local $aRet = DllCall( "oleaut32.dll", "uint", "SysStringLen", "ptr", $pBSTR ) If @error Then Return SetError(2, 0, 0) Return $aRet[0] EndFunc1 point
-
UIA Invoke click for a UIA_ListItemControlTypeId - Is that possible?
mycloutier reacted to junkew for a topic
Not sure but study example 18. I normally scroll till item is visible. If invoke or click is possible you can see with inspect.exe of windows sdk tools.1 point -
You can now use @extended instead of UBound() Local $aArray = FileReadToArray('Filepath') For $i = 0 To @extended - 1 ; ... NextDocumentation has been updated by the way, as I noticed an example didn't exist showcasing this.1 point
-
I know, I added the feature to the code above for @compact21.1 point
-
Don't think anything is wrong in the existing UDF as it does return 0 and sets the @error when the requested line doesn't exists. #include <File.au3> $rc = _FileWriteToLine(@ScriptDir & "\test.txt", 12, "something to write", 1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug ConsoleJos1 point
-
#include <Array.au3> #include <FileConstants.au3> _FileWriteToLine_Mod(@ScriptDir & "\Example_FileWriteToLineMod.txt", 16, "Data", True) MsgBox($MB_SYSTEMMODAL, '', @error) Func _FileWriteToLine_Mod($sFilePath, $iLine, $sText, $bOverWrite = False) If $iLine <= 0 Then Return SetError(4, 0, 0) If Not IsString($sText) Then $sText = String($sText) If $sText = "" Then Return SetError(6, 0, 0) EndIf If $bOverWrite = Default Then $bOverWrite = False If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) ; For old versions. If Not FileExists($sFilePath) Then Return SetError(2, 0, 0) Local $aArray = FileReadToArray($sFilePath) Local $iUBound = UBound($aArray) - 1 If $iUBound = -1 Then Dim $aArray[1] ; Dim is required to set the return value of FileReadToArray() as an array. EndIf ; If $iUBound < $iLine Then Return SetError(1, 0, 0) If $iUBound < $iLine Then ; Redim the array to a new size, so the line number can be written to. ReDim $aArray[$iLine] $iUBound = $iLine EndIf Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) + $FO_OVERWRITE) If $hFileOpen = -1 Then Return SetError(3, 0, 0) ; As the array is 0-based, reduce the line number by 1. $iUBound -= 1 $iLine -= 1 ; Set to the specific line. $aArray[$iLine] = ($bOverWrite ? $sText : $aArray[$iLine] & @CRLF & $sText) & @CRLF ; Loop through the data and concatenate. Local $sData = "" For $i = 0 To $iUBound $sData &= $aArray[$i] & @CRLF Next $sData = StringTrimRight($sData, StringLen(@CRLF) * 2) ; Required to strip trailing EOL FileWrite($hFileOpen, $sData) FileClose($hFileOpen) Return 1 EndFunc ;==>_FileWriteToLine_Mod I am in doubt people will want this in the library. If they do then make a feature request in the bug tracker.1 point
-
This isn't a bug, it's a feature request. I will refactor the code and post here for test.1 point
-
I'm pretty sure that _GDIPlus_ImageLoadFromFile keeps the file open until the image is released with _GDIPlus_ImageDispose. That's the reason for the error.1 point
-
Check that there are enough lines with _FileCountLines() and append enough @CRLF to the file first? Jos1 point
-
blackrainbow, Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. See you soon with a legitimate question I hope. M23 Edit: JohnOne, I remembered to lock this one.1 point
-
First of all so or so it will get bug when starting or comiling because in your the $MyProgramName was just = TEESSTT" #include <Crypt.au3> Global $MyCompanyName = "Test" Global $MyProgramName = "TEESSTT" Global $_HasUserAlreadyEnteredCorrectSerial = RegRead("HKCU\software\" & $MyCompanyName, $MyProgramName) If @error Or $_HasUserAlreadyEnteredCorrectSerial <> 1 Then $_InputBox = InputBox($MyCompanyName, "Please Enter Serial Number","","#") $AG5InputBox = _Crypt_HashData($_InputBox, $CALG_MD5) If $AG5InputBox <> "0x77777777777777777777777777777777777777" Then Exit MsgBox(0, 0, "Sorry Incorrect Serial") Else RegWrite("HKCU\software\" & $MyCompanyName, $MyProgramName, "REG_DWORD", 1) EndIf EndIf _StartOfProject() Func _StartOfProject() MsgBox(0, $MyCompanyName, $MyProgramName) EndFunc This would work and replace everything typed in with "#" so the Password shouldn't be seen what is being typed in.1 point
-
Change the regular expression for $BA from (?is).* to (?is).*? (/edit: because currently it picks up the last members instead of the first one.) That's the quickfix. But I agree with using a real XML parser if you want this to be more robust. Parsing xml with regex is just shaky.1 point
-
FileReadLine condition
mycloutier reacted to Danyfirex for a topic
my Try. Just for fun. #Include <Array.au3> Local $aData= FileReadToArray("1.txt") Local $Find = "Standard Serial over Bluetooth link" Local $NewArray[0] For $i=0 to UBound($aData)-1 If StringInStr($aData[$i],$Find) Then ReDim $NewArray[UBound($NewArray)+1] $NewArray[UBound($NewArray)-1]=Number(StringMid($aData[$i],StringInStr($aData[$i],"COM")+3)) EndIf Next _ArrayDisplay($NewArray)Saludos1 point -
FileReadLine condition
mycloutier reacted to mikell for a topic
? #Include <Array.au3> $txt = FileRead("ports.txt") $exp = "Standard Serial over Bluetooth link" $res = StringRegExp($txt, '(?m)^.*' & $exp & '.*COM(\d+)', 3) _ArrayDisplay($res)1 point -
FileReadLine condition
mycloutier reacted to BrewManNH for a topic
StringInStr would help. #include <MsgBoxConstants.au3> #include <File.au3> #include <FileConstants.au3> COMPorts() Func COMPorts() $file = "C:\GunTSTool\ports.txt" $hFile = FileOpen($file) While 1 $line = FileReadLine($hFile) If @error Then ExitLoop Select Case StringInStr($line, "Standard Serial over Bluetooth link") MsgBox($MB_SYSTEMMODAL, '', '' & '' & $line) Case StringInStr($line, "Prolific USB Cable") MsgBox($MB_SYSTEMMODAL, '', '' & '' & $line) Case StringInStr($line, "Prolific USB to serial Cable") MsgBox($MB_SYSTEMMODAL, '', '' & '' & $line) EndSelect WEnd FileClose($hFile) EndFunc ;==>COMPorts1 point -
-or- just add this in your properties file assuming you have the full version: save.session.advanced=1Jos1 point