Leaderboard
Popular Content
Showing content with the highest reputation on 06/27/2024 in all areas
-
Google Translation with GUI
argumentum reacted to pixelsearch for a topic
Update June 27, 2024 (version 10) this will be probably my final update (unless a bug is discovered in the script) + Added code to take care of possible RTL edit fields (10 languages amongst 133) during Edit controls creation, or during the registered WM_COMMAND function (test on $CBN_CLOSEUP, $CBN_KILLFOCUS etc...) + Minor cosmetic changes1 point -
Looks nice. I modified my example above a little bit: ;Coded by UEZ build 2024-06-27 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $STM_SETIMAGE = 0x0172 _GDIPlus_Startup() ;initialize GDI+ Global Const $iWidth = 600, $iHeight = 300, $iBgColor = 0x303030 ;$iBgColor format RRGGBB Global $hGUI = GUICreate("GDI+ Test", $iWidth, $iHeight) ;create a test GUI GUISetBkColor($iBgColor, $hGUI) ;set GUI background color GUISetState(@SW_SHOW) Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) Global $iW = $iWidth * 0.8, $iH = 30 Global $aImage_PB1 = _GDIPlus_BitmapCreateProgressbar($iW, $iH, 0xFFFFFF00, 0, 0, 1) Global $aImage_PB2 = _GDIPlus_BitmapCreateProgressbar($iW, $iH, 0xFF400000, 0xFFFF4040, 0, 2) Global $aImage_PB3 = _GDIPlus_BitmapCreateProgressbar($iW, $iH, 0xFF004000, 0xFF40FF40, 0xF0E0FFE0, 3, $iW / 2, $iH / 2) _GDIPlus_GraphicsDrawImageRect($hGraphics, $aImage_PB1[0], ($iWidth - $iW) / 2, $iHeight * 0.10, $iW, $iH) _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $aImage_PB1[1], 0, 0, $iW / 2, $iH, ($iWidth - $iW) / 2, $iHeight * 0.10, $iW / 2, $iH) _GDIPlus_GraphicsDrawImageRect($hGraphics, $aImage_PB2[0], ($iWidth - $iW) / 2, $iHeight * 0.40, $iW, $iH) _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $aImage_PB2[1], 0, 0, $iW / 2, $iH, ($iWidth - $iW) / 2, $iHeight * 0.40, $iW / 2, $iH) _GDIPlus_GraphicsDrawImageRect($hGraphics, $aImage_PB3[0], ($iWidth - $iW) / 2, $iHeight * 0.70, $iW, $iH) _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $aImage_PB3[1], 0, 0, $iW / 2, $iH, ($iWidth - $iW) / 2, $iHeight * 0.70, $iW / 2, $iH) Global $iSleep = 10, $fProgress = 0, $aPos = WinGetPos($hGUI) Global $hGUI_PB = GUICreate("Progressbar Example", $iW + 10, $iH + 10, -1, $aPos[1] + $aPos[3] - $iH) Global $iPB = GUICtrlCreatePic("", 5, 5, $iW, $iH), $hPB = GUICtrlGetHandle($iPB) GUISetState(@SW_SHOW, $hGUI_PB) GUIRegisterMsg($WM_TIMER, "SetProgressbar") DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIRegisterMsg($WM_TIMER, "") ;cleanup GDI+ resources _GDIPlus_ImageDispose($aImage_PB1[0]) _GDIPlus_ImageDispose($aImage_PB1[1]) _GDIPlus_ImageDispose($aImage_PB2[0]) _GDIPlus_ImageDispose($aImage_PB2[1]) _GDIPlus_ImageDispose($aImage_PB3[0]) _GDIPlus_ImageDispose($aImage_PB3[1]) _WinAPI_DeleteObject($aImage_PB1[2]) _WinAPI_DeleteObject($aImage_PB1[3]) _WinAPI_DeleteObject($aImage_PB2[2]) _WinAPI_DeleteObject($aImage_PB2[3]) _WinAPI_DeleteObject($aImage_PB3[2]) _WinAPI_DeleteObject($aImage_PB3[3]) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) Func SetProgressbar() $fProgress = Mod($fProgress + 0.1, 100) Local $fP = Max(Min(100, $fProgress), 0) Local $fWidth = $fP / 100 * $iW Static $cx = 0 Local $aBitmap = _GDIPlus_BitmapCreateProgressbar($iW, $iH, 0xFF004000, 0xFF40FF40, 0xF0E0FFE0, 3, Abs(Sin($cx / 100) * 2 * $iW) - $iW, $iH / 2) $cx += 1 Local Const $hBmp = _GDIPlus_BitmapCloneArea($aImage_PB3[0], 0, 0, $iW, $iH, $GDIP_PXF32ARGB), _ $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsDrawImageRectRect($hGfx, $aBitmap[1], 0, 0, $fWidth, $iH, 0, 0, $fWidth, $iH) Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iH / 3, 0) Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) _GDIPlus_GraphicsDrawStringEx($hGfx, Int($fP) & "%", $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushDispose($hBrush) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_FontDispose($hFont) Local Const $hBmp_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) Local Const $hB = GUICtrlSendMsg($iPB, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp_GDI) If $hB Then _WinAPI_DeleteObject($hB) _GDIPlus_ImageDispose($hBmp) _GDIPlus_GraphicsDispose($hGfx) _WinAPI_DeleteObject($hBmp_GDI) _GDIPlus_ImageDispose($aBitmap[0]) _GDIPlus_ImageDispose($aBitmap[1]) _WinAPI_DeleteObject($aBitmap[2]) _WinAPI_DeleteObject($aBitmap[3]) EndFunc Func Max($a, $b) Return $a > $b ? $a : $b EndFunc Func Min($a, $b) Return $a < $b ? $a : $b EndFunc Func _GDIPlus_BitmapCreateProgressbar($iW, $iH, $iStartColor = 0xFF004000, $iEndColor = 0xFF40FF40, $iCenterColor = 0xF0E0FFE0, $iMode = 3, $fXC = 0, $fCY = 0, $iBlur = 5, $iWrapMode = 3) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $hBrush, $hPath = _GDIPlus_PathCreate() Switch $iMode Case 1 $hBrush = _GDIPlus_BrushCreateSolid($iStartColor) Case 2 Local $tRECTF = _GDIPlus_RectFCreate(0, 0, $iW, $iH / 2) $hBrush = _GDIPlus_LineBrushCreateFromRectWithAngle($tRECTF, $iStartColor, $iEndColor, 90, False, $iWrapMode) _GDIPlus_LineBrushSetGammaCorrection($hBrush, True) Case 3 $hBrush = _GDIPlus_BrushCreateSolid($iStartColor) _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iW, $iH, $hBrush) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PathAddRectangle($hPath, 0, 0, $iW, $iH) $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath) Local $aColors[3] = [2, $iStartColor, $iEndColor] _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColors) _GDIPlus_PathBrushSetCenterColor($hBrush, $iCenterColor) _GDIPlus_PathBrushSetCenterPoint($hBrush, $fXC, $fCY) _GDIPlus_PathBrushSetWrapMode($hBrush, $iWrapMode) _GDIPlus_PathBrushSetGammaCorrection($hBrush, True) EndSwitch _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iW, $iH, $hBrush) _GDIPlus_BrushDispose($hBrush) Local $iColor Switch $iMode Case 1 $iColor = ColorChange($iStartColor, 0.4) Case 2 $iColor = 0x20FFFFFF Case 3 $iColor = 0x60FFFFFF EndSwitch $hBrush = _GDIPlus_BrushCreateSolid($iColor) _GDIPlus_GraphicsFillRect($hCtxt, 0, $iH * 0.85, $iW, $iH, $hBrush) Switch $iMode Case 1 $iColor = ColorChange($iStartColor, 0.5) Case 2 $iColor = ColorChange($iStartColor) Case 3 $iColor = ColorChange($iStartColor) EndSwitch _GDIPlus_BrushSetSolidColor($hBrush, $iColor) _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iW * 0.03, $iH, $hBrush) _GDIPlus_GraphicsFillRect($hCtxt, $iW * 0.97, 0, $iW, $iH, $hBrush) Switch $iMode Case 1 $iColor = ColorChange($iStartColor, 0.1) Case 2 $iColor = 0x40FFFFFF Case 3 $iColor = 0x50FFFFFF EndSwitch _GDIPlus_BrushSetSolidColor($hBrush, $iColor) _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iW, $iH * 0.225, $hBrush) Local $hEffect = _GDIPlus_EffectCreateBlur($iBlur) _GDIPlus_BitmapApplyEffect($hBitmap, $hEffect) _GDIPlus_EffectDispose($hEffect) Local $hBitmap_Bg = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $iW, $iH, $GDIP_PXF32ARGB) Local $tColorMatrix = _GDIPlus_ColorMatrixCreateGrayScale() $hEffect = _GDIPlus_EffectCreateColorMatrix($tColorMatrix) _GDIPlus_BitmapApplyEffect($hBitmap_Bg, $hEffect) _GDIPlus_EffectDispose($hEffect) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_PathDispose($hPath) Local $aBitmaps[] = [$hBitmap_Bg, $hBitmap, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Bg), _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)] Return $aBitmaps EndFunc Func ColorChange($iColor, $fFactor = 0.99) Local $iR = BitShift(BitAND($iColor, 0xFF0000), 16), $iG = BitShift(BitAND($iColor, 0xFF00), 8), $iB = BitAND($iColor, 0xFF) Return BitOR(BitAND($iColor, 0x20000000), BitShift($iR * $fFactor, -16), BitShift($iG * $fFactor, -8), $iB * $fFactor) EndFunc1 point
-
FuzzyString-UDF - fuzzy string comparison and search in string arrays
ioa747 reacted to AspirinJunkie for a topic
This UDF provides algorithms for fuzzy string comparison and the associated similarity search in string arrays. It offers functions for character-based comparisons, comparing the phonetics of words and the geometric distance of characters on a keyboard. In this way, typing errors can be recognized, similar-sounding words can be detected and other spellings of words can be included in further processing. The current function list of the UDF: --------- fuzzy array handling: _FS_ArraySearchFuzzy - finds similar entries for a search value in an array _FS_ArrayToPhoneticGroups - groups the values of an array according to their phonetics --------- character-based metrics: _FS_Levenshtein - calculate the levenshtein distance between two strings _FS_OSA - calculate the OSA ("optimal string alignment") between two strings _FS_Hamming - calculate the hamming distance between two strings --------- phonetic metrics: _FS_Soundex_getCode - calculate the soundex code for a given word to represent the pronounciation in english _FS_Soundex_distance - calculate the soundex-pattern for both input values _FS_SoundexGerman_getCode - calculate the modified soundex code for german language for a given word to represent the pronounciation in german _FS_SoundexGerman_distance - calculate the soundexGerman-pattern for both input values _FS_Cologne_getCode - calculate the cologne phonetics code for german language for a given word to represent the pronounciation in german _FS_Cologne_distance - calculate the cologne phonetics distance between both input values --------- key-position based metrics: _FS_Keyboard_GetLayout - return a map with coordinates for the characters for using in _FS_Keyboard_Distance_Chars() _FS_Keyboard_Distance_Chars - calculates the geometric key spacing between two characters on a keyboard _FS_Keyboard_Distance_Strings - calculate the keyboard-distance between two strings >>sourcecode and download on github<<1 point -
An example of the Add and Update methods of ADO Recordset object (with MS Access): Opt("MustDeclareVars", 1) ;Opt("TrayIconDebug", 1) OnAutoItExitRegister("OnAutoItExit") Global $sFilePath = @DesktopDir & "\test.mdb" ;Help: COM Error Handling ;_ErrADODB From spudw2k ;https://www.autoitscript.com/forum/topic/105875-adodb-example/ Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") Global $cn, $rst, $sSQL Global $CreateTestDataBase = True Global Const $iCursorType = 3 ;0 adOpenForwardOnly, 3 adOpenStatic Global Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" ;Global $sADOConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" ;Global $sADOConnectionString = 'Driver={Microsoft Access Driver (*.mdb)};Dbq=' & $sFilePath & ';uid=;pwd=MyPassword;' If $CreateTestDataBase Then ;mLipok, https://www.autoitscript.com/forum/topic/180848-example-xls-mdb-from-scratch-with-adox/ ;https://forums.autodesk.com/t5/visual-basic-customization/ado-connection-create-file-excel/td-p/1675928 ;https://msdn.microsoft.com/en-us/library/ms675849(v=vs.85).aspx ;https://msdn.microsoft.com/en-us/library/ms680934(v=vs.85).aspx Global $oCatalog = ObjCreate('ADOX.Catalog') FileDelete(@DesktopDir & "\test.mdb") ; <<< I'm not using $sFilePath for security: in reusing parts of the code $cn = $oCatalog.Create($sADOConnectionString) ;https://docs.microsoft.com/es-es/office/client-developer/access/desktop-database-reference/create-table-statement-microsoft-access-sql ;https://www.w3schools.com/sql/sql_create_table.asp ;http://www.vbforums.com/showthread.php?529221-RESOLVED-create-table-as-select-in-MS-Access ;https://docs.microsoft.com/es-es/office/client-developer/access/desktop-database-reference/select-into-statement-microsoft-access-sql $sSQL = "CREATE TABLE EMPLOYEES" _ & " (ID int identity, LastName varchar(40), FirstName varchar(40), Title varchar(40)," _ & " CONSTRAINT MyTableConstraint_PrimaryKey PRIMARY KEY (ID)," _ & " CONSTRAINT MyTableConstraint_Unique UNIQUE (LastName, FirstName));" $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 ;Some notes: ;Create Table Using Another Table ;A copy of an existing table can also be created using CREATE TABLE. ;The new table gets the same column definitions. All columns or specific columns can be selected. ;CREATE TABLE new_table_name AS ;SELECT column1, column2,... ;FROM existing_table_name ;WHERE ....; ;The following SQL creates a new table called "TestTables" (which is a copy of the "Customers" table): ;CREATE TABLE TestTable AS ;SELECT customername, contactname ;FROM customers; ;$sSQL = "SELECT *" _ ; & " INTO NEWTABLE" _ ; & " FROM [" & $sFilePath2 & ";PWD=123].SOMETABLE" ;$cn.Execute($sSQL, Default, 1 + 0x80) ;~ For $i = 1 To 5 ;~ $sSQL = "INSERT INTO EMPLOYEES (LastName, FirstName, Title)" _ ;~ & " VALUES ('" & "LastName_" & $i & "', '" & "FirstName_" & $i & "', '" & "Title_" & $i & "')" ;~ $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 ;~ Next $rst.Open("EMPLOYEES", $cn, $iCursorType, $iLockType, 2) ;Source (table name), ActiveConnection, CursorType, LockType, Options (adCmdTable) $cn.BeginTrans For $i = 1 To 5 $rst.AddNew $rst("LastName").Value = "LastName_" & $i $rst.Fields("FirstName") = "FirstName_" & $i $rst(3).Value = "Title_" & $i Next $rst.Update MsgBox(0,"","Last Auto-increment value is: " & $rst(0).Value) $rst.Close $cn.CommitTrans Else $cn = ObjCreate("ADODB.Connection") ; Create a connection object $cn.Open($sADOConnectionString) ; Open the connection EndIf ;MsgBox(0, "", $cn.ConnectionString) $cn.CursorLocation = 2 ;2 adUseServer, 3 adUseClient $cn.CommandTimeout = 60 ;https://support.microsoft.com/en-us/help/194973/prb-ado-recordcount-may-return--1 ;When you request the RecordCount for a serverside recordset, a -1 may return. This occurs with ActiveX Data Objects (ADO) version 2.0 or later when the CursorType is adOpenForwardonly or adOpenDynamic. Testing with the OLEDB provider for JET and SQL Server produces varying results, depending on the provider. ;Cause: The number of records in a dynamic cursor may change. Forward only cursors do not return a RecordCount. ;Resolution: Use either adOpenKeyset or adOpenStatic as the CursorType for server side cursors ;or use a client side cursor. Client side cursors use only adOpenStatic for CursorTypes regardless of which CursorType you select. ;https://stackoverflow.com/questions/31941487/open-adodb-connection-to-excel-file-in-read-only-mode ;https://www.w3schools.com/asp/prop_rec_mode.asp ;$cn.Mode = 1 ;Read-only ;To update an existing record, create a Recorset with one record at a time. ;This requires that there is some kind of unique key when identifying the records. ;After opening the recordset, use the .Fields property to change the field in question ;and then the .Update method to make changes to the database. $sSQL = "SELECT LastName, FirstName, Title FROM EMPLOYEES WHERE ID = 1" $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ; Issue the SQL query If Not $rst.EOF = True Then $rst("LastName").Value = "Davolio" $rst.Fields("FirstName") = "Nancy" $rst.Fields(2) = "President" EndIf $rst.Update MsgBox(0, "UPDATED RECORD", $rst.RecordCount) $rst.Close $rst = 0 $cn.Close ;Close the connection $cn = 0 ;Release the connection object Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext, 5) Local $err = $errADODB.number If $err = 0 Then $err = -1 $rst = 0 $cn.Close $cn = 0 Exit EndFunc Func OnAutoItExit() $rst = 0 ; Release the recordset object If IsObj($cn) Then If $cn.State > 0 Then $cn.Close ;adStateOpen Close the connection $cn = 0 ; Release the connection object EndIf EndFunc1 point