Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/23/2018 in all areas

  1. I've been testing the subclassing technique in recent months and have used ComboBox examples for tests. Here is one of the examples. More examples will be added over the coming weeks. All examples are small and simple. However, all of them are based on the subclassing technique. It's the interesting aspect of the examples. Some are implemented with complete UDFs. Others are made as code examples only. First post becomes a list of examples as well as the first example. ComboBox Examples Color Combo (just below) Checkbox Combo Checkbox Combo slightly modified ListView Combo Other Control Examples Tabs and subtabs on demand My first script in the Examples forum. Well. You have to start somewhere. Windows Explorer address bar Colors and fonts in TreeViews Implementing Virtual TreeViews Hot-Track Enabled Toolbar Menu Simulating a modeless Choose Color Dialog Color Combo The first example is about color selection. It's an owner drawn ComboBox created with the $CBS_OWNERDRAWVARIABLE style so that colors can be displayed directly in the ComboBox by responding to $WM_DRAWITEM messages. There are already many of these examples, but none are implemented through the subclassing technique. The big advantage of subclassing is that a user of the UDF still can use his own $WM_DRAWITEM message handler through GUIRegisterMsg. The same Windows message can be used in both techniques without any conflicts. This is an example with a single ComboBox: #include <GUIConstantsEx.au3> #include "..\Includes\ComboColors.au3" Example() Func Example() ; Create GUI GUICreate( "1 ComboBox", 220, 264 ) ; Create ComboBox for color selection GUICtrlCreateLabel( "Named colors:", 10, 10, 200, 16 ) Local $aInfo = ComboColors_Create( "Tomato", 10, 26, 200, 26, 10, "Colors\NamedColors.txt", 9 ) ; $aInfo = [ $idComboBox, $aColors, $oColors, $sColors, $iColors ] ; $aColors = [ "Color name", 0xBackColor, 0xTextColor, 0xBrush ] ; $oColors dict obj: Key = "Color name", Val = index in $aColors ; $sColors = "Color0|Color1|Color2|..." ; $iColors = Number of colors ; Show GUI GUISetState() ; Message loop While 1 Switch GUIGetMsg() Case $aInfo[0] Local $sColor = GUICtrlRead( $aInfo[0] ) Local $iIndex = $aInfo[2]($sColor) ConsoleWrite( "Color = " & $sColor & @CRLF & _ "Index = " & $iIndex & @CRLF & _ "Back = 0x" & Hex( ($aInfo[1])[$iIndex][1], 6 ) & @CRLF & _ "Fore = 0x" & Hex( ($aInfo[1])[$iIndex][2], 6 ) & @CRLF & _ "Brush = " & ($aInfo[1])[$iIndex][3] & @CRLF & @CRLF ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete() EndFunc Two different sources can be used to specify colors: An array and a text file. It's demonstrated in examples. ComboColors_Create() is defined this way: ; Create ComboBox for color selection ; ; Error code in @error Return value ; 1 => Invalid color info file/array Success => [ $idComboBox, $aColors, $oColors, $sColors, $iColors ] ; 2 => Error creating ComboBox Failure => 0 ; 3 => Too many ComboBoxes ; Func ComboColors_Create( _ $sColorInit, _ ; Initial ComboBox color $x, $y, $w, $h, _ ; Left, top, width, height $iListRows, _ ; Rows in drop-down ListBox $vColorInfo, _ ; File/array with color info $iFirstRow = 0 ) ; First row with color info There is also a ComboColors_Delete() function. This is a picture of an example with two ComboBoxes: The example above and this example is included in zip-file. Zip-file You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. ColorSelection.7z
    4 points
  2. First 2 characters of the replacement are NP. If C is the 2nd character of the match then A is the last letter of the replacement. If L is the 2nd character of the match then B is the last letter of the replacement, and the 3rd character is the same as the previous replacement. Meaning the only replacement information you really need is the 3rd character of every other entry. If the live data allows that character to be derived this entire operation gets real quick.
    2 points
  3. TheSaint

    INItoSQL DB

    Here is a simple program that some of you might appreciate. It is a more full fleshed out version of something I worked on a while back as a proof of concept. I will just quote the information found in the Program Information dialog. Older Screenshot INItoSQL DB.zip 1.27 MB (205 downloads) INItoSQL DB v1.1.zip 1.27 MB (181 downloads) (see Post #3 for update details) INItoSQL DB v1.4.zip 1.27 MB (166 downloads) (see Post #4 for update details) INItoSQL DB v1.6.zip (see Post #7 for update details) BIG THANKS to ResNullius for huge speed improvement etc. Program requires the sqlite3.dll, not included, but easily enough obtained. I have also included the beginnings of a new UDF (SimpleSQL_UDF) I am working, which you can use with the included 'Check conversion.au3' file to check a resulting conversion ... just modify the values for a few variables to suit your situation. I've not yet gotten around to coding a testing/checking results script, so I recommend the following open source program, which I have been using for some time. It was here, but is now here at GitHub - DB Browser for SQLite
    1 point
  4. Run the script as a 32bit script.
    1 point
  5. Just using the wrong tool for the job. 😁
    1 point
  6. TheSaint

    SimpleSQL_UDF

    Being the completist I am, I decided to finish what I started, even though I have taken a different route now with INItoSQL DB, which this UDF will shortly follow. So all the following functions are done (some could do with more error checking etc), but essentially mimic all the INI functions plus some. So in a very real way, you could kind of update your INI based program to an SQL based one, just by replacing those functions, especially with those in my next update, which will also give you a lot more flexibility than the current lot. Perhaps use my INItoSQL DB program first (original version probably), to convert existing INI files ... or I would advise waiting really, for my improvements, which will make a more proper SQL file. Changes In This Update Added several functions, plus improved greatly the way the example (test) Job system works ... now with auto advance and dialog prompts & feedback. _SQLite_Delete() can delete a Key, Section or Table. _SQLite_WriteSection() could do with some improving to check on existing. Same with the Rename functions. I was going to add them in, but a few SQL quirks wasted a fair amount of my time today, and I am more enthused about developing the improved versions instead.
    1 point
  7. You state the existence of exe2aut as if it isn't something we've known about for years. This has been discussed numerous times, and even has its own sticky thread: Yes, compiled scripts can be decompiled Yes, regardless of what you do a determined person can get your source code. Yes, there are programs to specifically decompile scripts - this is not something we can control or stop people from doing Yes, if you want 100% protection, AutoIt is not the language for you (good luck finding 100% in any language). No, we're not going to get into yet another long discussion on the topic - thread closed.
    1 point
  8. Test this script: #include <FTPEx.au3> #include <MsgBoxConstants.au3> _Example() Func _Example() Local $sServer = 'ftp.csx.cam.ac.uk' ; UNIVERSITY OF CAMBRIDGE ANONYMOUS FTP SERVER Local $sUsername = '' Local $sPass = '' Local $sPath ='/pub/README' Local $hFile, $sText Local $hOpen = _FTP_Open('MyFTP Control') Local $hConn = _FTP_Connect($hOpen, $sServer, $sUsername, $sPass) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else $hFile=_FTP_FileOpen($hConn,$sPath) $sText=BinaryToString(_FTP_FileRead($hFile,9999)) ;aus Datei lesen und in Format wandeln _FTP_FileClose($hFile) MsgBox($MB_APPLMODAL, 'README: ',$sText) EndIf _FTP_Close($hConn) _FTP_Close($hOpen) EndFunc ;==>_Example and after testing change to your needs.
    1 point
  9. TheSaint

    INItoSQL DB

    Please be advised, that my program only does very basic things and takes quite a simplistic approach. It does not setup any cross-referencing or indexing. To be sure, there is plenty of room for improvement, especially as my background is primarily INI files and Spreadsheets (Excel). One of the great benefits from sharing, is that you sometimes get input from others, even if it is only in private, and I always appreciate the time and effort taken to do so, so thank you @jchd for doing so in this instance ... quite the expert in SQL so I am told. It is clear to me, that I am only at the beginning of what is likely to be a long journey with SQL, especially as its possibilities impress me greatly. I also like to share my learning with others, hence the scripts and programs I provide ... hopefully they assist others on occasion ... even if it's just what not to do. P.S. If some of you have been observant enough, you will have noticed I am involved in a few SQL based projects right now ( CalibBrowser and most recently SimpleSQL_UDF ), and I am basically teaching myself as I go. For me, that means simplify in the first instance, paring things back to a level that I can understand, even if that means oversimplified and not fully correct. It is a beginning that I will continue to work upon as my experience and understanding grows. I first talked about eventually trying out SQL a few years ago, and earlier this year, I finally made the jump. I once went through a similar process with XML, but I never really took to it ... I learnt enough to utilize it in some projects of my own, plus work with XML files in general ... I never found it intuitive enough to ever really like it though ... and I always felt like I was reinventing the wheel almost, every time I used it ... no doubt due to some limitation of my own mind and how I recall things ... certainly if not used constantly enough. I already like SQL far more than I ever liked XML.
    1 point
  10. The attached Script Adds Scite Call tips for all functions in all the AU3 files in the (specified) UDF folder. This is great if you (like me) have heaps of UDFs and you can't remember the syntax for them. It will also use the description: or description . . . : comment above a function as the Call tip description (and if the text "Internal function" is in an above comment then it will ignore that function) Lastly, it will add a comment "header" to the functions in your UDFs if they don't have one, allowing you to edit the file, give better descriptions for the functions, then run this script again to update your Call tips. CAUTION: This script modifies your AU3 UDF files (as mentioned in the previous paragraph), use at your own risk (it does back them up to c:\temp\UDF-backup first), I have only done limited testing. ;NOT A UDF #include <file.au3> ;add NOT A UDF description to the top of an AU3 file to let this script know to skip it ; ;This script will parse all the AU3 files in [$UDFFolder] and then add Scite Calltips for them ;(A CallTip is that popup that appears after your type a command in Scite) ;It will also add description headers to your functions that look like the following: ; #FUNCTION# ==================================================================================================================== ; Name ..........: Example ; Description ...: (Requires: example.au3) ; =============================================================================================================================== ;-------------------------------------------------------------------------------------------------------------------------------- ;SETTINGS: ;-------------------------------------------------------------------------------------------------------------------------------- Local $AutoITIncludesFolder = RegRead("HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt", "Include") $AutoITIncludesFolder = StringSplit($AutoITIncludesFolder, ";") $UDFFolder = FileSelectFolder("Select your UDF folder",$AutoITIncludesFolder[1],6,$AutoITIncludesFolder[1]) $bAutoAddFunctionHeadersToUDFFiles = True ;the original UDF files will be backed up in $UDFBackupLocation (unless they already exist, to prevent good backups being overwritten by bad ones) $bDeleteExistingFiles = True ;delete (and regenerate) the existing user CallTip and Keyword files $UDFBackupLocation = "c:\temp\UDF-Backup" ;-------------------------------------------------------------------------------------------------------------------------------- ;Global Variables Global $array[1] ;[row][0] = Function Name, [row][1] = Function Parameters, [row][2] = Function Description Global $SciTEUserFolder = FindSciteUserFolder() Global $CallTipFile = $SciTEUserFolder & "\au3.user.calltips.api" Global $KeywordFile = $SciTEUserFolder & "\au3.userudfs.properties" If $bDeleteExistingFiles Then FileDelete($CallTipFile) FileDelete($KeywordFile) endif ConsoleWrite("Calltip file: "&$CallTipFile&@CRLF) ConsoleWrite("Keyword file: "&$KeywordFile&@CRLF) ConsoleWrite("UDF Folder: " &$UDFFolder&@CRLF) main() Func main() loadCallTipFile() ;load $array from CallTip file $UDFFiles = _FileListToArrayRec($UDFFolder,"*.au3",$FLTAR_FILES ,$FLTAR_RECUR,$FLTAR_NOSORT,$FLTAR_FULLPATH) ;Load list of UDF files in UDF path and subfolders ParseAll($UDFFiles) ;find all the functions in all the UDF files WriteKeywordFile() ;write them all to the keyword file WriteCallTipFile() ;write them all to the calltip file ConsoleWrite ("Displaying list of Functions"&@CRLF) _ArrayDisplay($array,"List of User Defined Functions") ;show the user the array EndFunc Func loadCallTipFile() Local $aKeywordFile ; Read in existing CallTip file _FileReadToArray($CallTipFile, $aKeywordFile) If Not IsArray($aKeywordFile) Then local $aKeywordFile[1] ;if file doesn't exist start with a blank array ;Remove any empty lines For $i = $aKeywordFile[0] To 1 Step -1 If $aKeywordFile[$i] = "" Then _ArrayDelete($aKeywordFile,$i) Next ;Sort array _ArraySort($aKeywordFile, 0, 1) ;split data to 3 columns (function name, params, description) ReDim $array[UBound($aKeywordFile)][3] $array[0][0] = $aKeywordFile[0] For $i = 1 To $aKeywordFile[0] $read = $aKeywordFile[$i] $array[$i][0] = StringBefore($read, "(",true) $array[$i][1] = StringFormatParam(StringBetween($read, "(",")",true)) $array[$i][2] = StringAfter($read, ")",true) Next EndFunc Func ParseAll($UDFFiles) ;parse UDF files one by one, adding functions inside For $i = 1 To $UDFFiles[0] ConsoleWrite ("Parsing "&$UDFFiles[$i]&@CRLF) Parse($UDFFiles[$i]) Next EndFunc Func Parse($fileName) Local $bFileModified Local $aData[1] Local $isInternal ;is this an internal function? (has Internal Function in comment prior Local $description _FileReadToArray($fileName,$aData) For $i = 1 To $aData[0] $read = $aData[$i] $read = StringStripWS($read,1) select Case StringLeft($read,1) = ";" ;comment $read = StringTrimLeft($read,1) If $read = "NOT A UDF" Then Return ;skip this file, it is not a UDF If Not $description Then If StringInStr($read,"Description:") Then $description = StringAfter($read,":",true) elseIf StringInStr($read,"Description ...:") Then $description = StringAfter($read,":",true) endif endif If Not $isInternal Then If StringInStr($read,"Internal Function") Then $isInternal = true endif Case StringLeft($read,5) = "func " ;function If Not $isInternal Then $read = StringTrimLeft($read,5) ;take off the "func " at the front $function = StringBefore($read,"(",true) $param = StringBetween($read,"(",")",true) $param = StringFormatParam($param) $StringRequiresInclude = "(Requires: " & FileTrimFolder($fileName) & ")" If $description Then ;add the Requires Include text on the end of the description if it isn't already there If StringRight($description,StringLen($StringRequiresInclude)) <> $StringRequiresInclude Then $description &= " " &$StringRequiresInclude endif ElseIf $bAutoAddFunctionHeadersToUDFFiles Then ;no description, lets add a header to this function so a description can more easily be added $bFileModified = true $write = @CRLF $write &= "; #FUNCTION# ===================================================================================================================="&@CRLF $write &= "; Name ..........: "&$function&@CRLF $write &= "; Description ...: "&$StringRequiresInclude&@CRLF $write &= "; ==============================================================================================================================="&@CRLF $write &= $aData[$i] $aData[$i] = $write endif If AddToArray($function,$param,$description) Then ConsoleWrite (" +"&$function&" "&$param&" "&$description&@CRLF) Else ConsoleWrite (" "&$function&" "&$param&" "&$description&@CRLF) endif endif ;reset variables $isInternal = false $description = "" EndSelect Next If $bFileModified Then ConsoleWrite ("Added headers to "&$fileName&@CRLF) DirCreate($UDFBackupLocation) FileMove($fileName,$UDFBackupLocation,0) _FileWriteFromArray($fileName ,$aData,1) endif EndFunc Func AddToArray($function,$param,$description) For $i = 1 To $array[0][0] If $array[$i][0] = $function Then $array[$i][1] = $param $array[$i][2] = $description Return false EndIf Next ;add item to array ReDim $array[UBound($array)+1][3] $array[0][0]+= 1 $count = $array[0][0] $array[$count][0] = $function $array[$count][1] = $param $array[$count][2] = $description Return true EndFunc Func WriteKeywordFile() ;Backup existing Keyword file ConsoleWrite ("Backing up Keyword File ("&$KeywordFile&")"&@CRLF) FileMove($KeyWordFile, $KeyWordfile & ".bak", 1) If FileExists($KeywordFile) Then ConsoleWrite ("!Failed to backup Keyword File ("&$KeywordFile&")"&@CRLF) Return endif ConsoleWrite ("Writing Keyword File ("&$KeywordFile&")"&@CRLF) Local $output Local $buffer = "au3.keywords.user.udfs=" For $i = 1 To $array[0][0] $FunctionName = $array[$i][0] $buffer &= StringLower($FunctionName) If StringLen($buffer) > 100 Then $buffer &= " \" & @CRLF $output &= $buffer $buffer = @TAB Else $buffer &= " " EndIf Next $output &= $buffer FileWrite($KeywordFile,$output) EndFunc Func WriteCallTipFile() ;Backup existing CallTip file ConsoleWrite ("Backing up CallTip File ("&$CallTipFile&")"&@CRLF) FileMove($CallTipFile, $CallTipFile & ".bak", 1) If FileExists($CallTipFile) Then ConsoleWrite ("!Failed to backup CallTip File ("&$CallTipFile&")"&@CRLF) Return endif ConsoleWrite ("Writing CallTip File ("&$CallTipFile&")"&@CRLF) For $i = 1 To $array[0][0] $FunctionName = $array[$i][0] $param = $array[$i][1] $description= $array[$i][2] FileWriteLine($CallTipFile,$FunctionName&" "&$param&" "&$description) Next EndFunc Func StringFormatParam($text) Local $output Local $start = "( " Local $end $text = StringStripWS($text,7) $aParam = StringSplit($text,",") For $i = 1 To $aParam[0] $read = $aParam[$i] If StringLeft($read,5) = "ByRef" Then $read = StringReplace($read,"ByRef","ByRef") ;fix the case If StringInStr($read,"=") Then $read = StringBefore($read,"=",true) $output &= "[, "&$read $end &= "]" Else $output &= ", "&$read endif Next $output = StringTrimLeft($output,2) $output = $start & $output & $end&" )" Return $output EndFunc Func FindSciteUserFolder() ; Check for SCITE_USERHOME Env variable and used that when specified. ; Else when OS is better than Winxp we use the INI from LocalAPPDATA If EnvGet("SCITE_USERHOME") <> "" And FileExists(EnvGet("SCITE_USERHOME")) Then Return EnvGet("SCITE_USERHOME") ElseIf EnvGet("SCITE_HOME") <> "" And FileExists(EnvGet("SCITE_HOME")) Then return EnvGet("SCITE_HOME") Else return @UserProfileDir ; original sciTE default location EndIf EndFunc func FileGetFolder($fileName) ;Get the file Path/folder if FileIsFolder($fileName) then return $fileName ;already is a foldername if FileIsFile($fileName) or StringInStr($fileName,".") then ;looks to be a filename Local $tmp = StringInStr ($fileName,"\",0,-1) if $tmp <> 0 Then $fileName = StringLeft($fileName,$tmp-1) endif endif $fileName = FilePathRemoveTrailingSlash($fileName) return $fileName EndFunc Func FileTrimFolder($fileName) $folder = FileGetFolder($fileName) return StringTrimleft($fileName,StringLen($folder)+1) ;chop the folder and the \ after teh folder EndFunc Func StringBetween($text, $startString, $endString, $StringStripWS = False) Local $loc, $loc2 $loc = StringInStr($text, $startString) If $loc = 0 Then Return $loc += StringLen($startString) $loc2 = StringInStr($text, $endString, 0, 1, $loc) If $loc2 = 0 Then Return $return = StringMid($text, $loc, $loc2 - $loc) If $StringStripWS Then $return = StringStripWS($return, 3) EndIf Return $return EndFunc ;==>StringBetween Func StringBefore($string, $substring, $StringStripWS = False) Local $return Local $loc = StringInStr($string, $substring) If $loc Then $Return = StringLeft($string, $loc - 1) EndIf If $StringStripWS Then $return = StringStripWS($return, 3) EndIf Return $return EndFunc ;==>StringBefore Func StringAfter($string, $substring, $StringStripWS = False) Local $return Local $loc = StringInStr($string, $substring) If $loc Then $return = StringTrimLeft($string, $loc + StringLen($substring)-1) EndIf If $StringStripWS Then $return = StringStripWS($return, 3) EndIf Return $return EndFunc ;==>StringAfter func FileIsFolder($fileName) ;is this file actually a folder? if not FileExists($fileName) then return false ;doesn't exist if StringInStr(FileGetAttrib($fileName),"D") then return true ;filename is a folder EndFunc func FileIsFile($fileName) ;Does this file exist, but its not a folder? if not FileExists($fileName) then return false ;doesn't exist if not FileIsFolder($fileName) then return true ;not a folder EndFunc Func FilePathRemoveTrailingSlash($fileName) while StringRight($fileName,1) = "\" $fileName = StringTrimRight($fileName,1) WEnd return $fileName EndFunc Also - I am aware of The User CallTip Manager in the Scite Config script (I used it as my starting point) It didn't meet my needs in that it required me to enter each function one by one (and I have a large mess of a UDF folder) _DanAddCallTips.au3
    1 point
  11. and some other stuff: #include "array.au3" Local $sEMLPath = "EMAIL.eml" $sAttachment = "image.jpg" ..... Local $aAttachments = GetAttachmentList($sEMLPath) _ArrayDisplay($aAttachments) .... Func GetAttachmentList($sEMLPath) Local $oErrHandler = ObjEvent("AutoIt.Error", GetAttachmentSize) ; Red Jon fucked up COM Local $oMessage = ObjCreate("{CD000001-8B95-11D1-82DB-00C04FB1625D}") ; with all the downsides If @error Then Return SetError(1, 0, -1) Local $oMessageStream = $oMessage.GetStream() If @error Then Return SetError(2, 0, -1) $oMessageStream.LoadFromFile($sEMLPath) If @error Then Return SetError(3, 0, -1) $oMessageStream.Flush() ; this is essential Local $sAttachments = '' For $oAttachment In $oMessage.Attachments $sAttachments &= $oAttachment.FileName & '|' Next If $sAttachments <> '' Then StringTrimRight($sAttachments,1) Local $aAttachments = StringSplit($sAttachments,'|') Return SetError(0, 0, $aAttachments) Else Return SetError(4, 0, -1) EndIf Return SetError(5, 0, -1) EndFunc ;==>SaveAttachment btw. Good material for the new UDF. If I find time, I'll do it.
    1 point
  12. You could try with CDO. It would be something like this $sEML = "sample.eml" $sAttachment = "canada plane.jpg" $iSize = GetAttachmentSize($sEML, $sAttachment) If @error Then $sErrDesc = "You can't use this method because " Switch @error Case 1 $sErrDesc &= "CDO sucks for you." Case 2 $sErrDesc &= "getting stream failed." Case 3 $sErrDesc &= "loading EML failed." Case 4 $sErrDesc &= "of some dumb error." Case 5 $sErrDesc = "No such attachment exists." EndSwitch MsgBox(4096, "Error", $sErrDesc & @CRLF) Else MsgBox(4096, "...", 'Attachment named "' & $sAttachment & '" is ' & $iSize & " bytes big" & @CRLF) EndIf Func GetAttachmentSize($sEMLPath, $sAttachmentName) Local $oErrHandler = ObjEvent("AutoIt.Error", GetAttachmentSize) ; Red Jon fucked up COM Local $oMessage = ObjCreate("{CD000001-8B95-11D1-82DB-00C04FB1625D}") ; with all the downsides If @error Then Return SetError(1, 0, -1) Local $oMessageStream = $oMessage.GetStream() If @error Then Return SetError(2, 0, -1) $oMessageStream.LoadFromFile($sEMLPath) If @error Then Return SetError(3, 0, -1) $oMessageStream.Flush() ; this is essential Local $iSize For $oAttachment In $oMessage.Attachments If $oAttachment.FileName = $sAttachmentName Then $iSize = $oAttachment.GetDecodedContentStream().Size If @error Then Return SetError(4, 0, -1) If $iSize Then Return $iSize Next Return SetError(5, 0, -1) EndFuncIf you want the size of all attachments then just add up to $iSize inside the loop and remove second parameter.
    1 point
×
×
  • Create New...