Leaderboard
Popular Content
Showing content with the highest reputation since 04/27/2024 in Posts
-
I have been creating few controls with round corners for awhile for my own needs and I felt it was time to make an UDF and share it with the community. The idea behind this UDF is to use essentially simple basic AutoIt GUI functions. I did not want to embark in GDI+ to create the controls. I wanted to be easy to use with enough features that it would answer most requirements. The functions contained in the UDF : _RGUI_RoundLabel _RGUI_RoundButton _RGUI_RoundInput _RGUI_RoundEdit _RGUI_RoundGroup _RGUI_RoundScrollBar _RGUI_ScrollBarSet _RGUI_ScrollBarDestroy _RGUI_RoundRect _RGUI_DrawLine _RGUI_ButtonPress _RGUI_ButtonReset Version 2025-04-06 * Solved an issue where scroll bar and control are not in the same GUI child * Added 4th example on how to use scrollbar with ListView over a background generated by GDI+ Version 2025-03-28 * Added support to auto-size label and button controls (by passing -1 for width and/or height) * Removed the requirement to pass handle of the GUI to _RGUI_RoundGroup * Added 3rd example on how to use scrollbar with RichEdit Version 2025-03-21 * Added support of round corner scrollbar * Added a 2nd example on how to use scrollbar with ListBox Version 2025-03-15 * Basic framework for the UDF Here an example of what could be done with the UDF : If you feel there should be new controls, I will consider adding them to the UDF. RoundGUI.zip12 points
-
We have changed the login to require your Email address and disabled the option to use your member name to make the hacking of accounts harder, as that was happening regularly lately. We can assist in case you don't remember the Email address used at signup. Just use the "Contact us" link at the bottom of the page.11 points
-
Visual Studio Code Extension currently available and future plans for SciTE?
jaberwacky and 9 others reacted to Jos for a topic
All, I see that there are multiple efforts to create/maintain an AutoIt3 Visual Studio Code extension, and I would like to open a discussion to see how that can be streamlined/merged/done more effectively so we can come up with the one that's preferred. I have been toying with the idea to stop the development of all the LUA extra's used by SciTE and start using VSCode for the more advanced way of developing AutoIt3 scripts, as many things a way after when the extension supports it, like running au3check on save so you just click the problems tab to see the warnings/errors of the currently opened scripts. So I have been working on making the utilities packaged with SciTE4AutoIt3 suitable to run stand-alone without the need for wrapping them with AutoIt3Wrapper, with the plan to be able to make them all more generic usable for any editor. They need to support UTF8 & ANSI encoded files, even when through includes the encoding is mixed. I have modified AutoIt3Wrapper to stop renaming and changing encoding of script/include files, and updated Tidy/Au3check/Au3stripper to support special characters in filenames and mixed ANSI/UTF8 file encoding and the generated console output is UTF8. I have been toying a bit with the VSCODE extension maintained by Damian (just picked one without looking at any others) and made some modifications locally for testing. Run au3check (Ctrl+F5), Tidy (Ctrl+t), Au3Stripper (Ctrl+Shift+o) without using AutoIt3Wrapper. Other already standardly available option (Run/Compile) still run via AutoIt3Wrapper as there is an added value doing it that way. I really like what I see and think this is a good way forward. So... I like to hear how you all think about this and possibly your preferred VSCode autoIt3 extension with reasons why. Also feels as a waste of effort when so many are making their own version of an extension instead of bundling the effort making one really nice one with all required features. Thoughts/Opinions?10 points -
Google Translation with GUI
dmob and 9 others reacted to pixelsearch for a topic
Hi everybody With the help of this thread, @AspirinJunkie @Nine and @Musashi , I was able to add a GUI to Google translation with AutoIt. Please note the 3 colors possible (green / yellow / red) found in these 3 pics, we'll discuss them later (need some sleep now) The maximum number of characters allowed for the original text is 65535, but imho it's too much. If you experience some slowness with 65535, then you can modify this variable at the very beginning of the script and indicate a lower value : Local $iMaxInputLength = 65535 There are different ways to import the text to translate : * Paste it directly from the clipboard (Ctrl+V) inside the upper edit control * Click the "Paste ClipBoard" button in the GUI * Drag a text file inside the upper edit control * Click the "Open File" button in the GUI (only .txt files for the moment) Then choose in each combo box the language you want ("Detect language" is useful for the Original) and click Translate. After the translation is done, if you want to copy the translated text, then a click on the "Copy Translated" button is possible. During the translation process, you have the possibility to press the "Escape" key if you want to stop the translation. ; Version 11 (June 30, 2024) ; This script requires AutoIt 3.3.16.1 (which includes Maps, as Json.au3 requires Maps for some translations) ; It also requires the file "Google Translate (languages list #3).txt" to be placed in same folder as the script ; To translate pdf files, it requests "pdftotext.exe" (a free command line tool from Xpdf downloadable at https://www.xpdfreader.com) #include "Json.au3" ; by @AspirinJunkie, download from https://github.com/Sylvan86/autoit-json-udf #include <Array.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #Include <GUIMenu.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <StringConstants.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Opt("GUICloseOnESC", 0) ;1=ESC closes (default), 0=ESC won't close Global $iMaxInputLength = 65535 ; In theory, 65535 is the maximum length of the original encoded string, when it is only composed of ; letters, digits, etc... which have an ascii code < 128 and coded on 1 byte only. ; But in practice, this variable should probably be lower (5000 as Google Translate site ?) or 10000, 15000 ... ; to avoid the warning message that will appear when the original encoded string becomes > 65535 bytes length. ; Also _JSON_Parse() may take some time on slow computers with "big" original encoded strings, we'll see... ; Global $iMaxInputLength = 5460 ; this value allows any encoded string to be < 65536 length, even if each character is a Unicode character ; requiring 4 bytes. In this case, each character will be coded on 12 bytes in the string "%..%..%..%.." ; 5460 * 12 = 65520 bytes (which is < 65536) ; user can choose amongst 39 GUI languages (this has nothing to do with 133 translatable languages) Global $aLangGui = _FillArrayLangGui("Google Translate (languages list #3).txt") Global $sIniFile = StringTrimRight(@ScriptFullPath, 4) & ".ini" ; ".au3" | ".a3x" | ".exe" => ".ini" Global $aLang, $aLink, $sLang = "", $iLangGui = -1, $bRTL Global $aIni = _ReadIniFile($sIniFile, $aLang, $aLink, $sLang) ; _ArrayDisplay($aLang, Ubound($aLang) & " codes & languages", Default, $ARRAYDISPLAY_NOROW, Default, "Code|Language|In Combo ?") #Region ### START Koda GUI section ### Form=C:\Temp\koda_1.7.3.0\Forms\google translate #4.kxf Global $sGUI_Title, $hGUI, $idPasteClip, $idOpenFile, $idLabelFrom, $idLangFrom, $idFontSizeFrom, $idWordWrapFrom, $idLanguageFilter Global $idLabelTo, $idLangTo, $idFontSizeTo, $idWordWrapTo, $idTranslate, $idCopyTrans, $idTextFrom, $idTextTo, $idCharStatus Global $idMsg, $sFileName, $sFileExt, $sEmpty = "" ; variable $sEmpty created only because ByRef doesn't accept literals _CreateGui() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $GUI_EVENT_CLOSE _WriteIniFile($sIniFile, $aLink) ExitLoop Case $idPasteClip ; in edit control containing the original text _UpdateGUI(StringLeft(ClipGet(), $iMaxInputLength)) Case $idOpenFile, $GUI_EVENT_DROPPED ; in edit control containing the original text $sFileName = ($idMsg = $idOpenFile) ? _OpenFile() : @GUI_DragFile If $sFileName Then $sFileExt = StringMid($sFileName, 1 + StringInStr($sFileName, ".", 0, -1)) ; -1 to start search from the right If StringLen($sFileExt) = StringLen($sFileName) Then $sFileExt = "no dot found" ; no "." found in $sFileName If StringInStr(FileGetAttrib($sFileName), "D") Then $sFileExt = "this is a folder" Select Case $sFileExt = "txt" ; no problem with txt extension Case $sFileExt = "pdf" ; extract pdf content to txt file using pdftotext.exe $sFileName = _PdfToText($sFileName) ; $sFileName (xxx.pdf) => $sFileName (TextExtractedFromPDF.txt) if success. If Not $sFileName Then ContinueLoop ; ... if extraction of txt fails, then $sFileName becomes "" (0 in fact) Case Else MsgBox($MB_TOPMOST, "File extension error ", _ "File extension '" & $sFileExt & "' can't be processed" & @crlf & _ "Only .txt or .pdf file can be processed", 0, $hGUI) _UpdateGUI($sEmpty) ContinueLoop EndSelect _UpdateGUI(StringLeft(FileRead($sFileName), $iMaxInputLength)) EndIf Case $idFontSizeFrom GUICtrlSetFont($idTextFrom, Int(GUICtrlRead($idFontSizeFrom))) GUICtrlSetState($idTextFrom, $GUI_FOCUS) ; keep showing an eventual selection Case $idWordWrapFrom $idTextFrom = _EditRecreate_From(Int(GUICtrlRead($idFontSizeFrom)), GUICtrlRead($idWordWrapFrom)) ; Font size, WordWrap GUICtrlSetState($idTextFrom, $GUI_FOCUS) Case $idFontSizeTo GUICtrlSetFont($idTextTo, Int(GUICtrlRead($idFontSizeTo))) GUICtrlSetState($idTextTo, $GUI_FOCUS) Case $idWordWrapTo $idTextTo = _EditRecreate_To(Int(GUICtrlRead($idFontSizeTo)), GUICtrlRead($idWordWrapTo)) ; Font size, WordWrap GUICtrlSetState($idTextTo, $GUI_FOCUS) Case $idTranslate GUICtrlSetState($idTranslate, $GUI_DISABLE) ; prevent accidental double click on the button GUICtrlSetData($idTextTo, "") WinSetTitle($hGUI, "", _GuiTitle()) HotKeySet("{ESC}", "_Wanna_Quit") ; in case user keys Esc during the translation process _Translate() HotKeySet("{ESC}") GUICtrlSetState($idTranslate, $GUI_ENABLE) Case $idCopyTrans ClipPut(GUICtrlRead($idTextTo)) MsgBox($MB_TOPMOST, "Copy", "Done", 1, $hGUI) ; timeout 1s Case $idLanguageFilter GUIRegisterMsg($WM_COMMAND, "") GUISetState(@SW_DISABLE, $hGUI) _LanguageFilter($aLang, $aLink, $sLang) ; in a new temporary GUI ($hGUI2) GUISetState(@SW_RESTORE, $hGUI) ; only flag that seems to do the job correctly, even on a non-minimized window !? GUISetState(@SW_ENABLE, $hGUI) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Case $idLabelFrom ; clickable label to decrease both combobox font size (some GUI languages appear much smaller than others) If $aIni[8] - 1 < 8.3 Then ContinueLoop $aIni[8] -= 1 GUICtrlSetFont($idLangFrom, $aIni[8]) GUICtrlSetFont($idLangTo, $aIni[8]) ; if a language is displayed as squares in the combobox, try instead the 2 following lines ; GUICtrlSetFont($idLangFrom, $aIni[8], 400, 0, "Ms Shell Dlg", 2) ; GUICtrlSetFont($idLangTo, $aIni[8], 400, 0, "Ms Shell Dlg", 2) Case $idLabelTo ; clickable label to increase both combobox font size (some GUI languages appear much smaller than others) If $aIni[8] + 1 > 16.3 Then ContinueLoop $aIni[8] += 1 GUICtrlSetFont($idLangFrom, $aIni[8]) GUICtrlSetFont($idLangTo, $aIni[8]) ; if a language is displayed as squares in the combobox, try instead the 2 following lines ; GUICtrlSetFont($idLangFrom, $aIni[8], 400, 0, "Ms Shell Dlg", 2) ; GUICtrlSetFont($idLangTo, $aIni[8], 400, 0, "Ms Shell Dlg", 2) EndSwitch WEnd GUIDelete($hGUI) ;============================================== Func _UpdateGUI(ByRef $sText) GUICtrlSetData($idTextFrom, $sText) _UpdateCharStatus() GUICtrlSetData($idTextTo, "") WinSetTitle($hGUI, "", _GuiTitle()) EndFunc ;==>_UpdateGUI ;============================================== Func _CreateGui() $sGUI_Title = "Google Translation (v11)" $hGUI = GUICreate(_GuiTitle(), 900, 700, -1, -1, $WS_OVERLAPPEDWINDOW, $WS_EX_ACCEPTFILES) $idPasteClip = GUICtrlCreateButton("Paste Clipboard", 10, 10, 100, 30) $idOpenFile = GUICtrlCreateButton("Open File", 10, 50, 100, 30) GUICtrlCreateGroup(" Original text options ", 120, 10, 310, 70) $idLabelFrom = GUICtrlCreateLabel("Language From", 133, 32, 110, 17) GUICtrlSetTip(-1, "click to decrease both combobox font size", "", 0, 1) $idLangFrom = GUICtrlCreateCombo("", 128, 50, 140, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL), _ ; $CBS_HASSTRINGS always forced ? $bRTL _ ? BitOr($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT) _ : -1) GUICtrlSetFont(-1, $aIni[8]) ; if a language is displayed as squares in the combobox, try instead the following line ; GUICtrlSetFont(-1, $aIni[8], 400, 0, "Ms Shell Dlg", 2) GUICtrlSetData(-1, $aLangGui[$iLangGui + 2] & "|" & $sLang) ; ex. item 0 is "Detect language" or "Sprache erkennen" or etc... GUICtrlSendMsg($idLangFrom, $CB_SETCURSEL, $aIni[0], 0) GUICtrlCreateLabel("Font size", 290, 32, 54, 17) $idFontSizeFrom = GUICtrlCreateInput($aIni[1], 288, 50, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER)) GUICtrlSetLimit(-1, 2) GUICtrlCreateUpdown($idFontSizeFrom) GUICtrlSetLimit(-1, 72, 8) GUICtrlCreateLabel("Word wrap", 364, 32, 64, 17) $idWordWrapFrom = GUICtrlCreateCheckbox("", 382, 46, 17, 25) GUICtrlSetState(-1, $aIni[2]) ; $GUI_CHECKED = 1 , $GUI_UNCHECKED = 4 GUICtrlCreateGroup("", -99, -99, 1, 1) $idLanguageFilter = GUICtrlCreateButton("?", 437, 48, 25, 25) GUICtrlCreateGroup(" Translated text options ", 470, 10, 310, 70) $idLabelTo = GUICtrlCreateLabel("Language To", 483, 32, 110, 17) GUICtrlSetTip(-1, "click to increase both combobox font size", "", 0, 1) $idLangTo = GUICtrlCreateCombo("", 478, 50, 140, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL), _ ; $CBS_HASSTRINGS always forced ? $bRTL _ ? BitOr($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT) _ : -1) GUICtrlSetFont(-1, $aIni[8]) ; if a language is displayed as squares in the combobox, try instead the following line ; GUICtrlSetFont(-1, $aIni[8], 400, 0, "Ms Shell Dlg", 2) GUICtrlSetData(-1, $sLang) GUICtrlSendMsg(-1, $CB_SETCURSEL, $aIni[3], 0) GUICtrlCreateLabel("Font size", 640, 32, 54, 17) $idFontSizeTo = GUICtrlCreateInput($aIni[4], 638, 50, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER)) GUICtrlSetLimit(-1, 2) GUICtrlCreateUpdown($idFontSizeTo) GUICtrlSetLimit(-1, 72, 8) GUICtrlCreateLabel("Word wrap", 714, 32, 64, 17) $idWordWrapTo = GUICtrlCreateCheckbox("", 732, 46, 17, 25) GUICtrlSetState(-1, $aIni[5]) ; $GUI_CHECKED = 1 , $GUI_UNCHECKED = 4 GUICtrlCreateGroup("", -99, -99, 1, 1) $idTranslate = GUICtrlCreateButton("Translate", 790, 10, 100, 30) $idCopyTrans = GUICtrlCreateButton("Copy Translated", 790, 50, 100, 30) $idTextFrom = _EditRecreate_From($aIni[1], $aIni[2]) ; Font size, WordWrap (for edit control containing the original text) $idTextTo = _EditRecreate_To ($aIni[4], $aIni[5]) ; same, for edit control containing the translated text. $idCharStatus = GUICtrlCreateLabel("", 790, 380, 80, 25, BitOR($SS_CENTER,$SS_CENTERIMAGE)) _UpdateCharStatus() EndFunc ;==>_CreateGui ;============================================== Func _Translate() Local $iItemTo = GUICtrlSendMsg($idLangTo, $CB_GETCURSEL, 0, 0) If $iItemTo = - 1 Then ; no "Language To" selected WinSetTitle($hGUI, "", _GuiTitle()) MsgBox($MB_TOPMOST, "'Language To' is undefined", "Please choose a target language from the list", 0, $hGUI) Return EndIf Local $sEncoded = _URIEncode(GUICtrlRead($idTextFrom)) If StringLen($sEncoded) = 0 Then WinSetTitle($hGUI, "", _GuiTitle()) MsgBox($MB_TOPMOST, "No original text", "Nothing to translate", 0, $hGUI) Return EndIf ; ConsoleWrite(BinaryToString(StringToBinary("$sEncoded: " & $sEncoded, $SB_UTF8), $SB_ANSI) & @crlf) Local $iBytes = StringLen($sEncoded) ; ConsoleWrite("Length of $sEncoded : " & $iBytes & @crlf & @crlf) If $iBytes > 65535 Then ; tested (not 65536 !) Local $iYesNo = MsgBox(BitOr($MB_TOPMOST, $MB_YESNO, $MB_DEFBUTTON2, $MB_ICONWARNING), _ "Warning : Encoded text is too big", _ "Encoded text size: " & @Tab & $iBytes & @crlf & _ "Max. allowed:" & @Tab & " 65535" & @crlf & _ "" & @crlf & _ "Do you want to truncate the original text ?", 0, $hGUI) If $iYesNo = $IDNO Then Return $sEncoded = _URIEncode_Truncate(GUICtrlRead($idTextFrom)) EndIf Local $iItemFrom = GUICtrlSendMsg($idLangFrom, $CB_GETCURSEL, 0, 0) Local $sLangFrom = ($iItemFrom = 0) ? "auto" : $aLang[$aLink[$iItemFrom - 1]][0] ; ex. "auto", "en", de", ... ; Local $iItemTo = GUICtrlSendMsg($idLangTo, $CB_GETCURSEL, 0, 0) ; moved at beginning of function, to test if a "Language To" is selected Local $sLangTo = $aLang[$aLink[$iItemTo]][0] ; ex. "en", "de", ... Local $sLangUsed, $sTranslated = _GoogleAPITranslate($sEncoded, $sLangFrom, $sLangTo, $sLangUsed) If $sLangUsed Then ; translation has succeeded and $sLangUsed always contains the code that Google used for its last translation ; ConsoleWrite("$sLangUsed: >>>" & $sLangUsed & "<<<" & @crlf) _GUICtrlEdit_SetText($idTextTo, $sTranslated) If $sLangFrom = "auto" Then Local $sLangUsedFull For $i = 0 To Ubound($aLang) - 1 If $sLangUsed = $aLang[$i][0] Then $sLangUsedFull = $aLang[$i][1] ; ex. "English", "German" , ... ExitLoop EndIf Next WinSetTitle($hGUI, "", "Translated From " & _ ($sLangUsedFull ? $sLangUsedFull : $sLangUsed & " (???)") & _ " To " & $aLang[$aLink[$iItemTo]][1]) Else WinSetTitle($hGUI, "", "Translated From " & $aLang[$aLink[$iItemFrom - 1]][1] & " To " & $aLang[$aLink[$iItemTo]][1]) EndIf Else ; translation failed as $sLangUsed is still empty WinSetTitle($hGUI, "", _GuiTitle()) MsgBox($MB_TOPMOST, "Error", _ "Something went wrong during translation" & @crlf & _ "(Internet connection ok ?)", 0, $hGUI) EndIf EndFunc ;==>_Translate ;============================================== Func _GoogleAPITranslate(Const ByRef $sEncoded, $sFrom, $sTo, ByRef $sLangUsed) Local $oLocalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncLocal") ; format and send request With ObjCreate("WinHttp.WinHttpRequest.5.1") ; thanks AspirinJunkie for correct syntax of the Object methods below. .Open("POST", "https://translate.googleapis.com/translate_a/single", False) .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") .Send(StringFormat("client=gtx&sl=%s&tl=%s&dt=t&q=%s", $sFrom, $sTo, $sEncoded)) Local $sResponse = .ResponseText EndWith ; ConsoleWrite(BinaryToString(StringToBinary("$sResponse: " & $sResponse, $SB_UTF8), $SB_ANSI) & @crlf) Local $vResponse = _JSON_Parse($sResponse) ; process return Local $sOutput = "" If VarGetType($vResponse) = 'Array' Then ; _ArrayDisplay($vResponse, "$vResponse") Local $aData = $vResponse[0] If VarGetType($aData) = 'Array' Then For $i = 0 To UBound($aData) -1 $sOutput &= ($aData[$i])[0] Next EndIf $sLangUsed = $vResponse[2] ; ex. "en" , "de" , ... to display which language Google used for translation, in case user choosed "Detect language" EndIf Return $sOutput EndFunc ;==>_GoogleAPITranslate ;============================================== Func _URIEncode(Const ByRef $sData) ; code below from Prog@ndy (minor changes) : https://www.autoitscript.com/forum/topic/95850-url-encoding/?do=findComment&comment=689060 ; maybe Chr(32) should always be encoded as "%20" and not "+" to be compatible with all browsers (?) we'll see... Local $aData = StringSplit(BinaryToString(StringToBinary($sData, $SB_UTF8), $SB_ANSI), "") ; "" => each character returns as an element Local $nChar, $sEncoded = "" For $i = 1 To $aData[0] $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sEncoded &= $aData[$i] Case 32 $sEncoded &= "+" Case Else $sEncoded &= "%" & Hex($nChar, 2) EndSwitch Next Return $sEncoded EndFunc ;==>_URIEncode ;============================================== Func _URIEncode_Truncate(Const ByRef $sData) Local $dBinary, $nChar, $sEncoded = "", $iGoodLen = 0 For $j = 1 To StringLen($sData) $iGoodLen = StringLen($sEncoded) ; from the previous loop $dBinary = StringToBinary(StringMid($sData, $j, 1), $SB_UTF8) ; for example л (russian) becomes 0xD0BB For $i = 1 To BinaryLen($dBinary) $nChar = Number(BinaryMid($dBinary, $i, 1)) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sEncoded &= Chr($nChar) Case 32 $sEncoded &= "+" Case Else $sEncoded &= "%" & Hex($nChar, 2) EndSwitch Next If StringLen($sEncoded) > 65535 Then ; stop encoding... GUICtrlSetData($idTextFrom, StringLeft($sData, $j - 1)) ; ...truncate original text... $sEncoded = StringLeft($sEncoded, $iGoodLen) ;...delete the very last byte(s) in $sEncoded... ExitLoop ; ...return the corresponding encoded string (which will never exceed 65535 bytes) EndIf Next Return $sEncoded EndFunc ;==>_URIEncode_Truncate ;============================================== Func _LanguageFilter(ByRef $aLang, ByRef $aLink, ByRef $sLang) ; Backup 3 arrays (quick), $iLangGui, $bRTL : in case user makes changes in GUI2 then presses Cancel button in GUI2 => revert Local $aLang_backup = $aLang, $aLink_backup = $aLink, $sLang_backup = $sLang, $iLangGui_backup = $iLangGui, $bRTL_backup = $bRTL ; Keep status of combo "Language From" (to select it again, even with another GUI language... if user keeps the language checked) Local $iOld_ItemFrom = GUICtrlSendMsg($idLangFrom, $CB_GETCURSEL, 0, 0) ; always 0+ (0 <=> "Detect language" or "Sprache erkennen" or etc...) Local $sOld_CodeFrom = ($iOld_ItemFrom = 0) ? "auto" : $aLang[$aLink[$iOld_ItemFrom - 1]][0] ; ex. "en" , "de" , ... Local $bCheck_ItemFrom = ($iOld_ItemFrom = 0) ? False : True ; Keep status of combo "Language To" (to select it again, even with another GUI language... if user keeps the language checked) Local $iOld_ItemTo = GUICtrlSendMsg($idLangTo, $CB_GETCURSEL, 0, 0) ; may be -1 if no selected "Language To" . 0+ if selected Local $sOld_CodeTo = ($iOld_ItemTo = -1) ? "" : $aLang[$aLink[$iOld_ItemTo]][0] ; ex. "en" , "de" , ... Local $bCheck_ItemTo = ($iOld_ItemTo = -1) ? False : True Local $iNumLi = -1, $iLeft = 15, $iTop = 49, $iMaxLanguages = Ubound($aLang), $idCheckbox[$iMaxLanguages] Local $iCountGui_Lang = Ubound($aLangGui) / 4, $idMenuItem[$iCountGui_Lang] Local $hGUI2 = GUICreate(_GuiTitle(2), 900, 700, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX)) Local $hMenu = _GUICtrlMenu_GetSystemMenu($hGUI2) _GUICtrlMenu_EnableMenuItem($hMenu, $SC_CLOSE, $MF_GRAYED, False) ; "disable red [X] and System Menu 'Close' item" (Melba23, Dec 14 2009) Local $idMenu_Lang = GUICtrlCreateMenu("GUI language") For $i = 0 To Ubound($aLangGui) - 1 Step 4 ; 0, 4, 8, 12, ... , 152 when 39 Gui languages $idMenuItem[$i / 4] = GUICtrlCreateMenuItem($aLangGui[$i + 1], $idMenu_Lang, -1, 1) ; 1 = menuradioitem If $i = $iLangGui Then GUICtrlSetState(-1, $GUI_CHECKED) Next GUICtrlCreateGroup("", 5, 39, 890, 639) ; just to display a thin rectangle around all Checkbox controls For $i = 0 To $iMaxLanguages - 1 $iNumLi += 1 ; 0+ If $iNumLi > 24 Then ; 0 to 24 = 25 checkbox controls per column (x 7 columns => 175 languages max. with these coords. Actually 133) $iLeft += 125 $iNumLi = 0 EndIf $idCheckbox[$i] = GUICtrlCreateCheckbox($aLang[$i][1], $iLeft, $iTop + $iNumLi * 25, 115, 25, _ $bRTL _ ? BitOr($BS_RIGHTBUTTON, $BS_RIGHT) _ : -1) If $aLang[$i][2] = 1 Then ; display this language in combobox GUICtrlSetState($idCheckbox[$i], $GUI_CHECKED) GUICtrlSetBkColor($idCheckbox[$i], 0xC0FFFF) ; light blue when checked EndIf Next GUICtrlCreateGroup("", -99, -99, 1, 1) Local $idCheckAll = GUICtrlCreateButton("Check All", 150, 7, 100, 30) Local $idUncheckAll = GUICtrlCreateButton("Uncheck All", 270, 7, 100, 30) Local $idOk = GUICtrlCreateButton("Ok", 520, 7, 100, 30) Local $idCancel = GUICtrlCreateButton("Cancel", 640, 7, 100, 30) GUISetState(@SW_SHOW) Local $idMsg, $iLangGuiNew While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $idCancel ; no $GUI_EVENT_CLOSE here, as GUI close button disabled just after GUI creation. Also Opt("GUICloseOnESC", 0) $aLang = $aLang_backup $aLink = $aLink_backup $sLang = $sLang_backup $iLangGui = $iLangGui_backup $bRTL = $bRTL_backup ExitLoop Case $idMenuItem[0] To $idMenuItem[$iCountGui_Lang - 1] ; ex. 30 To 68 when 39 GUI languages $iLangGuiNew = 4 * ($idMsg - $idMenuItem[0]) ; 0, 4, 8, 12, ... , 152 (when 39 GUI languages) If $iLangGuiNew <> $iLangGui Then _ChangeGuiLang($hGUI2, $iLangGuiNew, $idCheckbox) Case $idCheckbox[0] To $idCheckbox[$iMaxLanguages - 1] ; ex. 70 To 202 when 133 translatable languages... ; ...surrounded by 2 GUICtrlCreateGroup("") i.e. controls #69 & #203 If GUICtrlRead($idMsg) = $GUI_CHECKED Then GUICtrlSetBkColor($idMsg, 0xC0FFFF) ; light blue when checked $aLang[$idMsg - $idCheckbox[0]][2] = 1 ; display this language in combobox Else GUICtrlSetBkColor($idMsg, $GUI_BKCOLOR_DEFAULT) $aLang[$idMsg - $idCheckbox[0]][2] = "" ; do not display this language in combobox EndIf Case $idCheckAll GUISetState(@SW_LOCK, $hGui2) ; "Lock the window to avoid repainting" For $i = 0 To $iMaxLanguages - 1 GUICtrlSetState($idCheckbox[$i], $GUI_CHECKED) GUICtrlSetBkColor($idCheckbox[$i], 0xC0FFFF) ; light blue when checked $aLang[$i][2] = 1 ; display this language in combobox Next GUISetState(@SW_UNLOCK, $hGui2) ; "Unlock the window to allow repainting" Case $idUncheckAll GUISetState(@SW_LOCK, $hGui2) For $i = 0 To $iMaxLanguages - 1 GUICtrlSetState($idCheckbox[$i], $GUI_UNCHECKED) GUICtrlSetBkColor($idCheckbox[$i], $GUI_BKCOLOR_DEFAULT) $aLang[$i][2] = "" ; do not display this language in combobox Next GUISetState(@SW_UNLOCK, $hGui2) Case $idOk For $i = 0 To $iMaxLanguages - 1 ; test if one language (at least) is checked If GUICtrlRead($idCheckbox[$i]) = $GUI_CHECKED Then ExitLoop Next If $i = $iMaxLanguages Then ; no language checked MsgBox(BitOr($MB_TOPMOST, $MB_ICONWARNING), "Warning", "Please check at least 1 language", 0, $hGUI2) ContinueLoop EndIf ; at this stage $aLang[][2] Col 2 is fully up to date (1 = display this language in combobox, or "" = do not display) Local $iCountChecked = 0, $iNew_ItemFrom = -1, $iNew_ItemTo = -1 Dim $aLink[$iMaxLanguages] $sLang = "" For $i = 0 To $iMaxLanguages - 1 If GUICtrlRead($idCheckbox[$i]) = $GUI_CHECKED Then $iCountChecked += 1 ; 1+ $aLink[$iCountChecked - 1] = $i ; ex. $aLink[0] = 10 (1st combobox item links to row 10 in $aLang) , $aLink[1] = 27 etc... $sLang &= $aLang[$i][1] & "|" If $bCheck_ItemFrom And $aLang[$i][0] = $sOld_CodeFrom Then $iNew_ItemFrom = $iCountChecked ; 1+ (remember item 0 <=> "Detect language" or "Sprache erkennen" or etc...) $bCheck_ItemFrom = False EndIf If $bCheck_ItemTo And $aLang[$i][0] = $sOld_CodeTo Then $iNew_ItemTo = $iCountChecked - 1 ; 0+ $bCheck_ItemTo = False EndIf EndIf Next Redim $aLink[$iCountChecked] ; delete all superfluous empty rows (quick) GUICtrlSetData($idLangFrom, "|" & $aLangGui[$iLangGui + 2] & "|" & $sLang) ; "|" at beginning destroys the previous list (help file) GUICtrlSetData($idLangTo, "|" & $sLang) If $bRTL <> $bRTL_backup Then ; redraw both combo (RTL or LTR) If $bRTL Then _WinAPI_SetWindowLong(GUICtrlGetHandle($idLangFrom), $GWL_EXSTYLE, _ BitOr($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT)) _WinAPI_SetWindowLong(GUICtrlGetHandle($idLangTo), $GWL_EXSTYLE, _ BitOr($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT)) Else _WinAPI_SetWindowLong(GUICtrlGetHandle($idLangFrom), $GWL_EXSTYLE, 0) ; combobox don't have default exstyles (help file error) _WinAPI_SetWindowLong(GUICtrlGetHandle($idLangTo) , $GWL_EXSTYLE, 0) EndIf EndIf If $iNew_ItemFrom = - 1 Then ; old language From has been unchecked OR $iOld_ItemFrom = 0 GUICtrlSendMsg($idLangFrom, $CB_SETCURSEL, 0, 0) ; ex. "Detect language" or "Sprache erkennen" or etc... _WinAPI_SetWindowLong(GUICtrlGetHandle($idTextFrom), $GWL_EXSTYLE, $WS_EX_CLIENTEDGE) ; default extended style value in Edit field Else ; 1+ GUICtrlSendMsg($idLangFrom, $CB_SETCURSEL, $iNew_ItemFrom, 0) EndIf If $iNew_ItemTo = - 1 Then ; old language To has been unchecked OR $iOld_ItemTo = -1 GUICtrlSendMsg($idLangTo, $CB_SETCURSEL, -1, 0) ; blank the "Language To" selection GUICtrlSetData($idTextTo, "") ; clear the eventual translated text _WinAPI_SetWindowLong(GUICtrlGetHandle($idTextTo), $GWL_EXSTYLE, $WS_EX_CLIENTEDGE) ; default extended style value in Edit field Else ; 0+ GUICtrlSendMsg($idLangTo, $CB_SETCURSEL, $iNew_ItemTo, 0) EndIf If $iNew_ItemFrom > 0 And $iNew_ItemTo > -1 Then WinSetTitle($hGUI, "", "Translated From " & _ $aLang[$aLink[$iNew_ItemFrom - 1]][1] & " To " & $aLang[$aLink[$iNew_ItemTo]][1]) Else WinSetTitle($hGUI, "", _GuiTitle()) ; display the generic GUI title (which doesn't mention any translation language) EndIf ExitLoop EndSwitch WEnd GUIDelete($hGUI2) EndFunc ;==>_LanguageFilter ;============================================== Func _ChangeGuiLang(Const $hGUI2, Const $iLangGuiNew, Const ByRef $idCheckbox) ; ConsoleWrite($iLangGui & " " & $iLangGuiNew & @crlf) ; both can be 0, 4, 8, 12, ..., 152 (when 39 Gui languages) Local $bRTL_old = $bRTL ; define this variable before _FillArrayLang() ; Remap the links between the 2 language arrays (before redrawing all checkbox) Local $iIndex, $aLangNew = _FillArrayLang($aLangGui[$iLangGuiNew]) ; 3rd column of $aLangNew is empty at this stage ; $iLangGui & $bRTL redefined during _FillArrayLang() ... ; ... which means, from now on, $iLangGui = $iLangGuiNew For $i = 0 To Ubound($aLang) - 1 If Not $aLang[$i][2] Then ContinueLoop $iIndex = _ArraySearch($aLangNew, $aLang[$i][0], 0, 0, 1, 2, 1, 0) ; 2 = exact match, last 0 = search in col 0 of a 2D array If $iIndex > -1 Then $aLangNew[$iIndex][2] = 1 ; same language code (displayed in combobox) will very often have a different index in the new array. Else MsgBox(BitOr($MB_TOPMOST, $MB_ICONWARNING), "Serious warning", _ "Code language '" & $aLang[$i][0] & "' not found in " & $aLangGui[$iLangGui + 1] & @crlf & _ "Language text file is corrupted", 0, $hGUI2) EndIf Next ; redraw all checkbox with their captions reflecting the new language, tick the ones that need to be ticked, take care of LTR / RTL GUISetState(@SW_LOCK, $hGui2) ; Lock the window to avoid repainting Local $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($idCheckbox[0]), $GWL_STYLE) ; all 133 checkbox got the same style, pick any one. For $i = 0 To Ubound($aLang) - 1 If $bRTL <> $bRTL_old Then _WinAPI_SetWindowLong(GUICtrlGetHandle($idCheckbox[$i]), $GWL_STYLE, _ $bRTL _ ? BitOr ($iStyle, $BS_RIGHTBUTTON, $BS_RIGHT) _ : BitXOr($iStyle, $BS_RIGHTBUTTON, $BS_RIGHT)) EndIf GUICtrlSetData($idCheckbox[$i], $aLangNew[$i][1]) If $aLangNew[$i][2] = 1 Then ; display this language in combobox GUICtrlSetState($idCheckbox[$i], $GUI_CHECKED) GUICtrlSetBkColor($idCheckbox[$i], 0xC0FFFF) ; light blue when checked Else GUICtrlSetState($idCheckbox[$i], $GUI_UNCHECKED) GUICtrlSetBkColor($idCheckbox[$i], $GUI_BKCOLOR_DEFAULT) EndIf Next WinSetTitle($hGUI2, "", _GuiTitle(2)) GUISetState(@SW_UNLOCK, $hGui2) ; Unlock the window to allow repainting $aLang = $aLangNew ; note that $iLangGui and $bRTL have been updated during _FillArrayLang() EndFunc ;==>_ChangeGuiLang ;============================================== Func _ReadIniFile($sIniFile, ByRef $aLang, ByRef $aLink, ByRef $sLang) If FileExists($sIniFile) Then Local $aIni = FileReadToArray($sIniFile) If @extended <> 9 Then MsgBox($MB_TOPMOST, "_FileReadToArray: extended = " & @extended, _ "Ini file should have exactly 9 lines, not " & @extended & @crlf & _ "(this message is normal if you just upgraded the script to a new version.)" & @crlf & _ "" & @crlf & _ "Incompatible .ini file will be deleted now, please run the script again.") FileDelete($sIniFile) Exit EndIf For $i = 0 To 5 $aIni[$i] = Number($aIni[$i]) ; Number, or serious issues later with GUICtrlSendMsg() Next $aLink = StringSplit($aIni[6], ",", $STR_NOCOUNT) $aLang = _FillArrayLang(StringStripWS($aIni[7], $STR_STRIPLEADING + $STR_STRIPTRAILING)) ; ex. $aIni[7] = "en" or "de" or etc... ; (GUI interface for the language names) For $i = 0 To Ubound($aLink) - 1 $aLang[$aLink[$i]][2] = 1 ; display this language in ComboBox $sLang &= $aLang[$aLink[$i]][1] & "|" ; "a trailing GUIDataSeparatorChar is ignored" (help file, topic GUICtrlSetData for combo & list control) Next $aIni[8] = Number($aIni[8]) ; _ArrayDisplay($aIni, "Existing ini file") $aIni[6] = "" ; string not needed anymore (no big deal, just to match same behavior when ini file doesn't exist) Else ; ini file doesn't exist Local $aIni[9] $aIni[0] = 0 ; Language From (combobox) (force 'Detect Language' when .ini file doesn't exist) $aIni[1] = 11 ; Font Size for edit control original text $aIni[2] = 1 ; Word wrap for edit control original text (1 = checked, 4 = unchecked) $aIni[3] = -1 ; Language To (combobox) (forced to -1 [unselected] when .ini file doesn't exist) $aIni[4] = 11 ; Font Size for edit control translated text $aIni[5] = 1 ; Word wrap for edit control translated text (1 = checked, 4 = unchecked) ; $aIni[6] : nothing special about $aIni[6] when ini file doesn't exist. $aIni[7] = "en" ; Suggest english GUI interface when no ini file (i.e. language names in english) though it's changeable here $aIni[8] = 9.3 ; Font Size for both combobox (decrease by clicking LABEL $idLabelFrom, increase by clicking LABEL $idLabelTo) $aLang = _FillArrayLang($aIni[7]) Dim $aLink[Ubound($aLang)] For $i = 0 To Ubound($aLang) - 1 ; add all languages in $sLang when ini file doesn't exist (user will keep those he needs, later) $aLang[$i][2] = 1 ; 1 = display this language in ComboBox ("" = don't display it) $aLink[$i] = $i ; link between combobox item # and row in $aLang . This will be useful if user unchecks some languages he doesn't need $sLang &= $aLang[$i][1] & "|" ; "a trailing GUIDataSeparatorChar is ignored" (help file, topic GUICtrlSetData for combo & list control) Next ; _ArrayDisplay($aIni, "New ini file") EndIf Return $aIni EndFunc ;==>_ReadIniFile ;============================================== Func _WriteIniFile($sIniFile, Const ByRef $aLink) Local $hIni = FileOpen($sIniFile, $FO_OVERWRITE) If $hIni = -1 Then MsgBox($MB_TOPMOST, "FileOpen error", $sIniFile, 0, $hGUI) ; 5th param prevents clicking inside the GUI Else FileWrite($hIni, _ GUICtrlSendMsg($idLangFrom, $CB_GETCURSEL, 0, 0) & @crlf & _ Int(GUICtrlRead($idFontSizeFrom)) & @crlf & _ GUICtrlRead($idWordWrapFrom) & @crlf & _ GUICtrlSendMsg($idLangTo, $CB_GETCURSEL, 0, 0) & @crlf & _ Int(GUICtrlRead($idFontSizeTo)) & @crlf & _ GUICtrlRead($idWordWrapTo) & @crlf & _ _ArrayToString($aLink, ",") & @crlf & _ $aLangGui[$iLangGui] & @crlf & _ ; ex. "en" or "de" etc... (it will be the GUI interface for the language names, on next launch) $aIni[8]) ; So there are 9 lines in ini file (no need of a last @crlf , though it is allowed but not mandatory) FileClose($hIni) EndIf EndFunc ;==>_WriteIniFile ;============================================== Func _EditRecreate_From($iFontSize, $iWordWrap) Local $idEdit_Old = $idTextFrom ; 0 at first passage Local $iExStyle If $idEdit_Old Then Local $aPos = ControlGetPos($hGUI, "", $idEdit_Old) Local $sText = GUICtrlRead($idEdit_Old) Local $aSel = _GUICtrlEdit_GetSel($idEdit_Old) $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($idEdit_Old), $GWL_EXSTYLE) GUICtrlDelete($idEdit_Old) Else ; 1st passage Local $aPos[4] = [10, 100, 880, 275] Local $iItemFrom = GUICtrlSendMsg($idLangFrom, $CB_GETCURSEL, 0, 0) Local $sLangFrom = ($iItemFrom = 0) ? "auto" : $aLang[$aLink[$iItemFrom - 1]][0] ; ex. "auto", "en", de", ... $iExStyle = _IsRTL($sLangFrom) _ ? BitOR($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT, $WS_EX_CLIENTEDGE) _ : -1 ; -1 is the default value ($WS_EX_CLIENTEDGE) used by GUICtrlCreateEdit below EndIf Local $idTextFrom = GUICtrlCreateEdit("", $aPos[0], $aPos[1], $aPos[2], $aPos[3], _ (($iWordWrap = 1) _ ; Word wrap (1 = unchecked, 4 = checked) ? BitOr($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL) _ : -1), _ $iExStyle) ; new control ID (1st passage) or same control ID as the deleted edit control (2nd+ passage) => no gap in id's controls list GUICtrlSetFont(-1, $iFontSize) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSendMsg(-1, $EM_LIMITTEXT, $iMaxInputLength, 0) If $idEdit_Old Then _GUICtrlEdit_SetText($idTextFrom, $sText) If $aSel[0] <> $aSel[1] Then _GUICtrlEdit_SetSel($idTextFrom, $aSel[0], $aSel[1]) EndIf Return $idTextFrom EndFunc ;==>_EditRecreate_From ;============================================== Func _EditRecreate_To($iFontSize, $iWordWrap) Local $idEdit_Old = $idTextTo ; 0 at first passage Local $iExStyle If $idEdit_Old Then Local $aPos = ControlGetPos($hGUI, "", $idEdit_Old) Local $sText = GUICtrlRead($idEdit_Old) Local $aSel = _GUICtrlEdit_GetSel($idEdit_Old) $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($idEdit_Old), $GWL_EXSTYLE) GUICtrlDelete($idEdit_Old) Else ; 1st passage Local $aPos[4] = [10, 410, 880, 275] Local $iItemTo = GUICtrlSendMsg($idLangTo, $CB_GETCURSEL, 0, 0) If $iItemTo = -1 Then ; no "Language To" selected $iExStyle = -1 ; -1 is the default value ($WS_EX_CLIENTEDGE) used by GUICtrlCreateEdit below Else Local $sLangTo = $aLang[$aLink[$iItemTo]][0] ; ex. "en", "de", ... $iExStyle = _IsRTL($sLangTo) _ ? BitOR($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT, $WS_EX_CLIENTEDGE) _ : -1 ; -1 is the default value ($WS_EX_CLIENTEDGE) EndIf EndIf Local $idTextTo = GUICtrlCreateEdit("", $aPos[0], $aPos[1], $aPos[2], $aPos[3], _ (($iWordWrap = 1) _ ; Word wrap (1 = unchecked, 4 = checked) ? BitOr($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL) _ : -1), _ $iExStyle) ; new control ID (1st passage) or same control ID as the deleted edit control (2nd+ passage) => no gap in id's controls list GUICtrlSetFont(-1, $iFontSize) GUICtrlSendMsg(-1, $EM_LIMITTEXT, -1, 0) ; allow unlimited text size in edit control (translated text) If $idEdit_Old Then _GUICtrlEdit_SetText($idTextTo, $sText) If $aSel[0] <> $aSel[1] Then _GUICtrlEdit_SetSel($idTextTo, $aSel[0], $aSel[1]) EndIf Return $idTextTo EndFunc ;==>_EditRecreate_To ;============================================== Func _OpenFile() Local $sFileName = FileOpenDialog( _ "Open Text or PDF file", _ @ScriptDir, _ "Text or PDF (*.txt;*.pdf)", _ BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST), _ "", _ $hGUI) If @error Then ;~ MsgBox($MB_TOPMOST, "Open File", _ ;~ "No file selected ", 0, $hGUI) ; FileOpenDialog() was exited by Cancel/Red X button, or by Esc key Return ; 0 EndIf ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder (on successful return) ; FileChangeDir(@ScriptDir) Return $sFileName EndFunc ;==>_OpenFile ;============================================== Func _PdfToText(Const $sInputFileName) Local Static $sPdfToText = @ScriptDir & ((@OSVersion <> "WIN_XP") ? "\pdftotext.exe" : "\pdftotext40.exe") Local Static $sOutputFileName = @ScriptDir & "\TextExtractedFromPDF.txt" If Not FileExists($sPdfToText) Then MsgBox($MB_TOPMOST, "PDF : missing extractor file", _ "To translate a pdf, you need the file 'pdftotext.exe'" & @crlf & _ "" & @crlf & _ "It can be downloaded at https://www.xpdfreader.com" & @crlf & _ "then place it in same folder as the script", 0, $hGUI) _UpdateGUI($sEmpty) Return ; 0 EndIf Local $sCommand = " /c" & " " & _ chr(34) & chr(34) & $sPdfToText & chr(34) & " " & _ "-enc UTF-8" & " " & _ chr(34) & $sInputFileName & chr(34) & " " & _ chr(34) & $sOutputFileName & chr(34) & chr(34) Local $iRet = RunWait(@ComSpec & $sCommand, @ScriptDir, @SW_HIDE) Select Case @error MsgBox($MB_TOPMOST, "RunWait: error " & @error, _ "AutoIt error, please check AutoIt code", 0, $hGUI) Return ; 0 Case $iRet Local $sErr = "" ; following exit codes (from 0 To 99) are found in PdfToText documentation, except the personal "Case Else" Switch $iRet ;~ Case 0 ;~ $sErr = "No error." Case 1 $sErr = "Error opening a PDF file." Case 2 $sErr = "Error opening an output file." Case 3 $sErr = "Error related to PDF permissions." Case 98 $sErr = "Out of memory." ; this exit code 98 was added in last version 4.05 of pdftotxt.exe (released on Feb 8, 2024) Case 99 $sErr = "Other error." Case Else ; should never happen $sErr = "This error isn't found in PdfToText documentation !" EndSwitch MsgBox($MB_TOPMOST, "PdfToText exit code: error " & $iRet, _ $sErr, 0, $hGUI) _UpdateGUI($sEmpty) Return ; 0 EndSelect ; all is good from now on ($iRet = 0, which means no error returned from pdftotext.exe) Return $sOutputFileName EndFunc ;==>_PdfToText ;============================================== Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) ; Local $hWndFrom = $lParam ; Local $iIDFrom = _WinAPI_LoWord($wParam) Local $iIDFrom = BitAND($wParam, 0xFFFF) ; same (cf WinAPIConv.au3) ; Local $iCode = _WinAPI_HiWord($wParam) Local $iCode = BitShift($wParam, 16) ; same (cf WinAPIConv.au3) Switch $iIDFrom Case $idTextFrom If $iCode = $EN_UPDATE Then ; Sent when an edit control is about to redraw itself _UpdateCharStatus() EndIf Case $idLangFrom If $iCode = $CBN_CLOSEUP Or $iCode = $CBN_KILLFOCUS Then Local $iExStyle_Old = _WinAPI_GetWindowLong(GUICtrlGetHandle($idTextFrom), $GWL_EXSTYLE) ; Edit field From Local $iItemFrom = GUICtrlSendMsg($idLangFrom, $CB_GETCURSEL, 0, 0) Local $sLangFrom = ($iItemFrom = 0) ? "auto" : $aLang[$aLink[$iItemFrom - 1]][0] ; ex. "auto", "en", de", ... Local $iExStyle_New = _IsRTL($sLangFrom) _ ? BitOR($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT, $WS_EX_CLIENTEDGE) _ : $WS_EX_CLIENTEDGE ; $WS_EX_CLIENTEDGE is the default extended style value in Edit field If $iExStyle_New <> $iExStyle_Old Then _WinAPI_SetWindowLong(GUICtrlGetHandle($idTextFrom), $GWL_EXSTYLE, $iExStyle_New) EndIf EndIf Case $idLangTo If $iCode = $CBN_CLOSEUP Or $iCode = $CBN_KILLFOCUS Then Local $iExStyle_Old = _WinAPI_GetWindowLong(GUICtrlGetHandle($idTextTo), $GWL_EXSTYLE) ; Edit field To Local $iItemTo = GUICtrlSendMsg($idLangTo, $CB_GETCURSEL, 0, 0) If $iItemTo = -1 Then ; no "Language To" selected Local $iExStyle_New = $WS_EX_CLIENTEDGE ; $WS_EX_CLIENTEDGE is the default extended style value in Edit field Else Local $sLangTo = $aLang[$aLink[$iItemTo]][0] ; ex. "en", "de", ... Local $iExStyle_New = _IsRTL($sLangTo) _ ? BitOR($WS_EX_LEFTSCROLLBAR, $WS_EX_RTLREADING, $WS_EX_RIGHT, $WS_EX_CLIENTEDGE) _ : $WS_EX_CLIENTEDGE ; $WS_EX_CLIENTEDGE is the default extended style value in Edit field EndIf If $iExStyle_New <> $iExStyle_Old Then _WinAPI_SetWindowLong(GUICtrlGetHandle($idTextTo), $GWL_EXSTYLE, $iExStyle_New) EndIf EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND ;============================================== Func _UpdateCharStatus() Local $iChars = GUICtrlSendMsg($idTextFrom, $WM_GETTEXTLENGTH, 0, 0) ; same as _GUICtrlEdit_GetTextLen($idTextFrom) ? Select Case $iChars > $iMaxInputLength GUICtrlSetData($idTextFrom, StringLeft(GUICtrlRead($idTextFrom), $iMaxInputLength)) ContinueCase Case $iChars = $iMaxInputLength GUICtrlSetData($idCharStatus, $iMaxInputLength & " / " & $iMaxInputLength) GUICtrlSetBkColor($idCharStatus, 0xFF4040) ; reddish Case Else ; i.e. $iChars < $iMaxInputLength GUICtrlSetData($idCharStatus, $iChars & " / " & $iMaxInputLength) GUICtrlSetBkColor($idCharStatus, ($iChars <= 5460) ? 0x80FF80 : 0xFFFF00) ; greenish => ok, yellow => encoded string may become too long. EndSelect EndFunc ;==>_UpdateCharStatus ;============================================== Func _ErrFuncLocal($oError) ; https://www.autoitscript.com/forum/topic/191401-com-error-handling-in-a-udf-best-practice/?do=findComment&comment=1373102 MsgBox($MB_TOPMOST, @ScriptName & " (" & $oError.scriptline & ") : ==> Local COM error handler - COM Error intercepted !", _ @Tab & "err.number is: " & @Tab & @Tab & "0x" & Hex($oError.number) & @crlf & _ @Tab & "err.windescription:" & @Tab & @Tab & StringStripWS($oError.windescription, 2) & @crlf & _ @Tab & "err.description is: " & @Tab & @Tab & StringStripWS($oError.description, 2) & @crlf & _ @Tab & "err.source is: " & @Tab & @Tab & $oError.source & @crlf & _ @Tab & "err.helpfile is: " & @Tab & @Tab & $oError.helpfile & @crlf & _ @Tab & "err.helpcontext is: " & @Tab & @Tab & $oError.helpcontext & @crlf & _ @Tab & "err.lastdllerror is: " & @Tab & @Tab & $oError.lastdllerror & @crlf & _ @Tab & "err.scriptline is: " & @Tab & @Tab & $oError.scriptline & @crlf & _ @Tab & "err.retcode is: " & @Tab & @Tab & "0x" & Hex($oError.retcode), 0, $hGUI) EndFunc ;==>_ErrFuncLocal ;============================================== Func _Wanna_Quit() ; in case user keys Esc during the translation process HotKeySet("{ESC}") If WinActive($hGUI) Then MouseMove(@DesktopWidth / 2, @DesktopHeight / 2, 0) ; 0 = fastest move If MsgBox(BitOr($MB_TOPMOST, $MB_OKCANCEL, $MB_DEFBUTTON2), _ "Esc was keyed", "Quit translation script ?", 0, $hGUI) = $IDOK Then GUIDelete($hGUI) Exit EndIf Else ; Esc was keyed when another application was on top Send("{ESC}") EndIf HotKeySet("{ESC}", "_Wanna_Quit") EndFunc ;_Wanna_Quit ;============================================== Func _FillArrayLangGUI($sFileName) ; Text file containing a list of 39 languages & codes (for GUI) found patiently on Google translate web site, one by one... Local $sFilePath = @ScriptDir & "\" & $sFileName If Not FileExists($sFilePath) Then Exit MsgBox($MB_TOPMOST, "File not found", $sFilePath) Local $s_String = FileRead($sFilePath) If @error Then Exit MsgBox($MB_TOPMOST, "FileRead : error " & @error, $sFilePath) ; this shouldn't happen, but who knows ? Local $sPattern = '(?i)Language code\h*:?\h*(.+?)\h*\R+\h*Language name\h*:?\h*(.+?)\h*\R+\h*\["auto","(.+?)"],(\[".+"])\h*(?:\R+|$)' Local $aArray = StringRegExp($s_String, $sPattern, 3) If @error Then Exit MsgBox($MB_TOPMOST, "StringRegExp", _ "error = " & @error & (@error = 1 ? " (no matches)" : " (bad pattern)") & @crlf & _ "" & @crlf & _ $sFilePath) If Mod(Ubound($aArray), 4) Then _ArrayDisplay($aArray, "Malformed txt file : number of rows should be a multiple of 4") Exit MsgBox($MB_TOPMOST, "error", _ "Please install a correct language text file" & @crlf & _ "" & @crlf & _ $sFilePath) EndIf ; _ArrayDisplay($aArray, (Ubound($aArray) / 4) & " GUI languages codes & names") Return $aArray EndFunc ;==>_FillArrayLangGUI ;============================================== Func _FillArrayLang($sCode) For $i = 0 To Ubound($aLangGui) - 1 Step 4 ; 4 consecutive rows (in $aLangGui) contain the characteristics of each GUI language If $aLangGui[$i] = $sCode Then ExitLoop ; ex. "en" or "de" etc... Next If $i > Ubound($aLangGui) - 1 Then Exit MsgBox($MB_TOPMOST, 'error', _ 'Language code "' & $sCode & '" not retrieved in language text file' & @crlf & _ 'Please install a correct language text file (and delete your eventual ini file)') $iLangGui = $i ; important global variable indicating the row where starts the characteristics of the actual Gui language. ; its value is 0, 4, 8, 12...152 (when 39 Gui languages) Local $s_String = $aLangGui[$iLangGui + 3] ; string of 133 languages, for ex. ["af","Afrikaans"],["sq","Albanian"],[...],["zu","Zulu"] ; suppress eventual leading & trailing whitespaces ; Regexp Pattern in _FillArrayLangGUI() has already checked this => comment out the test below ; $s_String = StringStripWS($s_String, $STR_STRIPLEADING + $STR_STRIPTRAILING) ; check the string starts with an opening bracket followed by a double quote, then ends with a double quote followed by a closing bracket ; Regexp Pattern in _FillArrayLangGUI() has already checked this => comment out the test below ; If StringLeft($s_String, 2) <> '["' Or StringRight($s_String, 2) <> '"]' Then Exit MsgBox($MB_TOPMOST, _ ; 'Language code "' & $sCode & '" : bracket and double quote error inside language text file', _ ; 'The first 2 characters of the string must be ["' & @crlf & _ ; 'The last 2 characters of the string must be "]') ; beginning of string : suppress leading opening bracket and first double quote ; end of string : suppress last double quote and trailing closing bracket $s_String = StringMid($s_String, 3, StringLen($s_String) - 4) ; Split the string in a 2D array (2 columns) with a 3rd empty column added for further usage (5th param. of _StringSplit2D_EX) Local $aArray = _StringSplit2D_EX($s_String, '","', '"],["', False, 1) If @error Then Exit MsgBox($MB_TOPMOST, "_StringSplit2D_EX : error " & @error, _ "All rows don't have the same number of fields" & @crlf & _ "Please install a correct language text file") If Ubound($aArray, $UBOUND_COLUMNS) <> 3 Then Exit MsgBox($MB_TOPMOST, _ "error : number of columns = " & Ubound($aArray, $UBOUND_COLUMNS), _ "It should be 3 (last column being empty for further usage)" & @crlf & _ "Please install a correct language text file") $bRTL = _IsRTL($sCode) ; True if language is RTL, False if not Return $aArray EndFunc ;==>_FillArrayLang ;============================================== Func _IsRTL($sCode) ; June 2024 : 10 languages are RTL amongst the 133 traductable languages (tested) ; Place them all in the string below, though only 3 of them are accessible from the 39 GUI languages (Arabic, Hebrew, Persian) ; Arabic (ar) , Dhivehi (dv), Hebrew (iw), Kurdish (Sorani) (ckb), Pashto (ps) ; Persian (fa), Sindhi (sd), Urdu (ur), Uyghur (ug), Yiddish (yi) ; Note : in version 10+ the whole list (10 RTL languages) is checked in case of 1 or 2 edit fields are RTL (in edit creation & WM_COMMAND) Local Static $sRTL = "ar,dv,iw,ckb,ps,fa,sd,ur,ug,yi," ; end the string with a comma (to make the search easy on next line) Return (StringInStr($sRTL, $sCode & ",") > 0) ? True : False EndFunc ;==>_IsRTL ;============================================== Func _GuiTitle($iGui = 0) Local $sTitle Switch $iGui Case 0 ; add GUI language code (which may change during the script) to the string, so user knows what GUI language is actually set. ; ex. "Google Translation (v10 - en)" $sTitle = StringTrimRight($sGUI_Title, 1) & " - " & $aLangGui[$iLangGui] & ")" Case 2 ; add GUI language name to the string ; ex. "GUI language (English) & Languages filter" $sTitle = "GUI language (" & $aLangGui[$iLangGui + 1] & ") & Languages filter" Case Else $sTitle = "Scripter, where are you ?" EndSwitch Return $sTitle EndFunc ;==>_GuiTitle ;============================================== Func _StringSplit2D_EX(ByRef $sString, $sDelim_Col = "|", $sDelim_Row = @CRLF, $bExpand = False, $iAdd_EmptyCol = 0) ; based on AspirinJunkie's function _StringSplit2D found at https://autoit.de/thread/85380-1d-array-in-2d-array-splitten/ ; Thanks Nine for suggesting the 4th parameter $bExpand, to allow or not the same number of fields per row (as in _FileReadToArray) Local $a_FirstDim = StringSplit($sString, $sDelim_Row, $STR_ENTIRESPLIT + $STR_NOCOUNT) Local $iKeep_NbCol = Ubound(StringSplit($a_FirstDim[0], $sDelim_Col, $STR_ENTIRESPLIT + $STR_NOCOUNT)) ; keep nb cols row 0 Local $a_Out[UBound($a_FirstDim)][1 + $iAdd_EmptyCol], $a_Line, $i_2DMax = 1 For $i = 0 To UBound($a_FirstDim) - 1 $a_Line = StringSplit($a_FirstDim[$i], $sDelim_Col, $STR_ENTIRESPLIT + $STR_NOCOUNT) If (Not $bExpand) And (Ubound($a_Line) <> $iKeep_NbCol) Then Return SetError(3, 0, 0) ; same error # as _FileReadToArray If UBound($a_Line) > $i_2DMax Then ; when $bExpand = False, this test will be True maximum 1 time, never more. $i_2DMax = UBound($a_Line) ReDim $a_Out[UBound($a_Out)][$i_2DMax + $iAdd_EmptyCol] EndIf For $j = 0 To UBound($a_Line) - 1 $a_Out[$i][$j] = $a_Line[$j] Next Next Return $a_Out EndFunc ;==>_StringSplit2D_EX Please indicate if something doesn't work correctly as I just finished the script a few minutes ago. Have a great day * Update June 7, 2024 (version 7) If you don't need all 133 language names (in both combobox) and prefer to display less names for a better visibility, then it's easily doable as explained in my post just below * Update June 23, 2024 (version 9) list of changes below in this thread, here * 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 changes * Update June 30, 2024 (version 11) Pdf files can now be opened for translation. Instructions to download the free utility "pdftotext" are found in the post below Google Translate (languages list #3).zip10 points -
I was wondering how to create an Application Bar that would be recognized by the system. Searching on the forum here revealed that there was a few attempts of doing so but none was successful. So here a working example of how to perform it. Notice how maximized windows are shrunk by the application bar. 😎 #NoTrayIcon ;#AutoIt3Wrapper_UseX64=y #include <GUIConstants.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> #include <TrayConstants.au3> ; #SHAppBarMessage# ============================================================================================================= ; Name ..........: SHAppBarMessage.AU3 ; Description ...: Create an Application Bar recognized by the system ; Author ........: Nine ; Created .......: 2025-04-04 ; Modified ......: ; Remarks .......: ; Example .......: Yes ; =============================================================================================================================== Opt("MustDeclareVars", True) Opt("GUICloseOnESC", False) Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) Global Enum $ABM_NEW, $ABM_REMOVE, $ABM_QUERYPOS, $ABM_SETPOS, $ABM_GETSTATE, $ABM_GETTASKBARPOS, $ABM_ACTIVATE, $ABM_GETAUTOHIDEBAR, _ $ABM_SETAUTOHIDEBAR, $ABM_WINDOWPOSCHANGED, $ABM_SETSTATE Global Enum $ABS_ONTOP, $ABS_AUTOHIDE, $ABS_ALWAYSONTOP Global Enum $ABE_LEFT, $ABE_TOP, $ABE_RIGHT, $ABE_BOTTOM Global Enum $ABN_STATECHANGE, $ABN_POSCHANGED, $ABN_FULLSCREENAPP, $ABN_WINDOWARRANGE Global Const $CALLBACK = $WM_USER + 0x10 Global Const $tagAPPBARDATA = "dword cbSize;hwnd hWnd;uint uCallbackMessage;uint uEdge;" & $tagRECT & ";lparam lParam" Global $idDummy Example() Func Example() Local $tAppBarData = DllStructCreate($tagAPPBARDATA) $tAppBarData.cbSize = DllStructGetSize($tAppBarData) Local $hGUI = GUICreate("", 80, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x202020) GUISetFont(11, 0, 0, "Comic Sans MS") Local $idHide = GUICtrlCreateButton(" Hide", 5, 5, 70, 30) GUICtrlSetImage(-1, "shell32.dll", 200, 0) Local $idTask = GUICtrlCreateButton(" Task", 5, 40, 70, 30) GUICtrlSetImage(-1, "shell32.dll", 16739, 0) Local $idDo = GUICtrlCreateButton(" Do", 5, 75, 70, 30) GUICtrlSetImage(-1, "shell32.dll", 16802, 0) Local $idDont = GUICtrlCreateButton(" Don't", 5, 110, 70, 30) GUICtrlSetImage(-1, "shell32.dll", 240, 0) Local $idExit = GUICtrlCreateButton(" Exit", 5, 300, 70, 30) GUICtrlSetImage(-1, "shell32.dll", 290, 0) $tAppBarData.hWnd = $hGUI $tAppBarData.uCallbackMessage = $CALLBACK DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_NEW, "struct*", $tAppBarData) AppBarSetPos($tAppBarData) GUIRegisterMsg($CALLBACK, AppBarProc) GUISetState() $idDummy = GUICtrlCreateDummy() While True Switch GUIGetMsg() Case $idExit ExitLoop Case $idDummy AppBarSetPos($tAppBarData) Case $idHide GUISetState(@SW_HIDE) DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_REMOVE, "struct*", $tAppBarData) TraySetIcon("shell32.dll", 255) TraySetState($TRAY_ICONSTATE_SHOW) TraySetToolTip("Left click to restore" & @CRLF & "Right click to Exit") Case $idTask ToggleTaskBar() EndSwitch Switch TrayGetMsg() Case $TRAY_EVENT_PRIMARYDOWN GUISetState(@SW_SHOW) DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_NEW, "struct*", $tAppBarData) AppBarSetPos($tAppBarData) TraySetState($TRAY_ICONSTATE_HIDE) Case $TRAY_EVENT_SECONDARYUP Exit EndSwitch WEnd DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_REMOVE, "struct*", $tAppBarData) EndFunc ;==>Example Func AppBarSetPos(ByRef $tAppBar) $tAppBar.uEdge = $ABE_LEFT $tAppBar.left = 0 $tAppBar.top = 0 $tAppBar.Right = 80 $tAppBar.Bottom = @DesktopHeight DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_QUERYPOS, "struct*", $tAppBar) DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_SETPOS, "struct*", $tAppBar) WinMove($tAppBar.hWnd, "", $tAppBar.Left, $tAppBar.Top, $tAppBar.Right, $tAppBar.Bottom) EndFunc ;==>AppBarSetPos Func ToggleTaskBar() Local $tAppBar = DllStructCreate($tagAPPBARDATA) $tAppBar.cbSize = DllStructGetSize($tAppBar) Local $iState = DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_GETSTATE, "struct*", $tAppBar)[0] $tAppBar.lParam = $iState = $ABS_AUTOHIDE ? $ABS_ALWAYSONTOP : $ABS_AUTOHIDE DllCall("shell32.dll", "int", "SHAppBarMessage", "dword", $ABM_SETSTATE, "struct*", $tAppBar) EndFunc ;==>ToggleTaskBar Func AppBarProc($hWnd, $iMsg, $wParam, $lParam) If $wParam = $ABN_POSCHANGED Then GUICtrlSendToDummy($idDummy, $wParam) Return $GUI_RUNDEFMSG EndFunc ;==>AppBarProc8 points
-
MiniMark (a minimalistic rtf editor)
Skeletor and 6 others reacted to TheAutomator for a topic
To test as intended: see read me! file in zip This program is still under development, but feel free to make this code better with suggestions and better code There are some (closed) tickets for bugs in _GUICtrlRichEdit_StreamToFile and _GUICtrlRichEdit_GetZoom so the script uses workarounds until the next AutoIt update: https://www.autoitscript.com/trac/AutoIt/ticket/4038#ticket https://www.autoitscript.com/trac/AutoIt/ticket/4040#ticket Wanna take a look at the code? Here you go: #cs name: MiniMark function: a minimalistic editor for custom rtf files version: 4 made by: TheAutomator project: https://www.autoitscript.com/forum/topic/212763-minimark-a-minimalistic-rtf-editor todo: • make user level install possible (requested by argumentum) • allow dropping files to gui • consider sort lines, remove duplicate lines, remove whitespace button • add file changed indicator • add right click menu on edit • check if programfiles exist when opened • look into embedding images and sounds into compiled exe • make variable names better (AutoIt rules) • make tab behave correctly • handle double click behaviour on controls • figure out how to deal with saving zoom amount bug • $ws_clipsiblings needed for overlapping? bugs in AutoIt rich edit functions: https://www.autoitscript.com/trac/AutoIt/ticket/4038#ticket https://www.autoitscript.com/trac/AutoIt/ticket/4040#ticket should be fixed in the next AutoIt version! remarks: to install and test MiniMark as intended: • compile minimark to exe (with options) • compile setup to exe (with options) • use the setup to install MiniMark • restart computer (if things don't update directly) • rightclick to create a new mnm file • double click it and tadaaaah! hystory: version 1 + added some changes inspired by Werty + code revised + added functionality like opening files with a window, noticed by Argumentum + added sounds version 2 + scrolling is now possible thanks to Pixelsearch + scroll code was revised by Nine - changed some code to prevent a sound to be played twice + added "return $gui_rundefmsg" to "func wm_command" version 3 + made an installer/uninstaller (needs install path choice) - removed unnecessary guictrlcreatedummy code + undo buffer is set to empty when file loaded + added search function with custom gui (work in progress) + added scroll bar (that is buggy AF) version 4 (still in beta) + code revised again + made find and replace work better + better custom scrollbar (based on cursor position in edit) + added "save as" shortcut + added option to silence sounds + added option to save zoom amount (bug -> see ticket) + new search gui + added settings gui + added ini file to save settings + added custom popups in same style as MiniMark + added about button with link to forum + added per-monitor v2 dpi awareness (requires windows 10 creators update or later) + added better way to create controls on the fly (not as many images needed) + added checkmarks + added upper and lower case hotkeys + added incert date and time hotkey + scroll bar major update (special thanks to Pixelsearch for all the help with the code!) #ce #Region au3 #autoit3wrapper_icon=setup\icon.ico #autoit3wrapper_outfile_x64=MiniMark\MiniMark.exe #autoit3wrapper_usex64=y #NoTrayIcon #include <guirichedit.au3> #include <guiconstants.au3> #include <winapisyswin.au3> #include <array.au3> #include <date.au3> #EndRegion au3 #Region MiniMark constants ; colors Const $color_text_white = 0x00ffffff Const $color_text_gray = 0x00c0c0c0 Const $color_element_gray = 0x606060 Const $color_control_gray = 0x404040 Const $color_border_gray = 0x202020 Const $color_text_red = 0x006600ff Const $color_text_green = 0x0000ff66 Const $color_text_blue = 0x00ff6600 Const $color_transparent_background = 0xff00ff ; font names Const $font_handel_gothic_bt = 'handelgothic bt' Const $font_lucida_console = 'lucida console' ; sound effects Const $sound_start = @ScriptDir & '\sounds\start.wav' Const $sound_click = @ScriptDir & '\sounds\click.wav' Const $sound_alert = @ScriptDir & '\sounds\alert.wav' Const $sound_stop = @ScriptDir & '\sounds\stop.wav' ; user interface images Const $image_alert = @ScriptDir & '\images\alert.bmp' Const $image_button = @ScriptDir & '\images\button.bmp' Const $image_MiniMark = @ScriptDir & '\images\MiniMark.bmp' Const $image_scroll = @ScriptDir & '\images\scroll.bmp' Const $image_scroll_down = @ScriptDir & '\images\scroll_down.bmp' Const $image_scroll_up = @ScriptDir & '\images\scroll_up.bmp' Const $image_search = @ScriptDir & '\images\search.bmp' Const $image_settings = @ScriptDir & '\images\settings.bmp' Const $image_size_down = @ScriptDir & '\images\size_down.bmp' Const $image_size_up = @ScriptDir & '\images\size_up.bmp' Const $image_tick_on = @ScriptDir & '\images\tick_on.bmp' Const $image_tick_off = @ScriptDir & '\images\tick_off.bmp' ; files Const $file_intro = @ScriptDir & '\data\MiniMark.mnm' Const $file_settings = @ScriptDir & '\data\settings.ini' #EndRegion MiniMark constants #Region custom gui create functions ; create titles. Func title_create($title, $w) Local $title_handle = GUICtrlCreateLabel($title, 5, 5, $w, 20, BitOR($ss_centerimage, $ss_center), $gui_ws_ex_parentdrag) ; use label to drag form GUICtrlSetFont(Default, 12, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $gui_bkcolor_transparent) Return $title_handle EndFunc ;==>title_create ; create buttons. Func button_create($text, $tip, $sub, $x, $y) Local $button_handle = GUICtrlCreatePic($image_button, $x, $y, 70, 20) GUICtrlSetTip(Default, $tip, $sub) Local $button_label = GUICtrlCreateLabel($text, $x, $y, 70, 20, BitOR($ss_centerimage, $ss_center)) GUICtrlSetFont(Default, 9, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $gui_bkcolor_transparent) Return $button_handle EndFunc ;==>button_create ; create checkboxes. Func checkbox_create($text, $tip, $sub, $x, $y, $state = 0) Local $checkbox_handle = GUICtrlCreatePic($state ? $image_tick_on : $image_tick_off, $x, $y, 70, 20) GUICtrlSetTip(Default, $tip, $sub) Local $checkbox_label = GUICtrlCreateLabel($text, $x, $y, 50, 20, BitOR($ss_centerimage, $ss_center)) GUICtrlSetFont(Default, 9, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $gui_bkcolor_transparent) Return $checkbox_handle EndFunc ;==>checkbox_create ; create inputs (+5 on the left, -5 on the right; so we don't overlap the corners). Func input_create($x, $y, $tip) Local $input_handle = GUICtrlCreateInput('', $x, $y, 210, 20, $es_autohscroll, 0) GUICtrlSetTip(Default, $tip) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $color_control_gray) GUICtrlSetFont(Default, 12, 400, 0, $font_handel_gothic_bt) Return $input_handle EndFunc ;==>input_create #EndRegion custom gui create functions #Region checkbox messages Func checkbox_toggle($checkbox_handle, ByRef $checkbox_state) play_sound($sound_click) $checkbox_state = $checkbox_state ? 0 : 1 GUICtrlSetImage($checkbox_handle, $checkbox_state ? $image_tick_on : $image_tick_off) EndFunc ;==>checkbox_toggle #EndRegion checkbox messages #Region sound effects $checkbox_sound_state = Int(IniRead($file_settings, 'settings', 'sound', 1)) ; read from ini Func play_sound($name, $wait = 0) If $checkbox_sound_state Then SoundPlay($name, $wait) EndFunc ;==>play_sound #EndRegion sound effects #Region custom msgbox ; alert constants Const $alert_ok = 0 Const $alert_link_close = 1 Const $alert_yes_no_cancel = 2 ; a custom messagebox, used for warnings and notifications Func alert($title = 'Alert', $text = '', $type = $alert_ok) Local $alert_form = GUICreate('Alert', 230, 120, Default, Default, $ws_popup, BitOR($ws_ex_layered, $ws_ex_topmost)) GUISetBkColor($color_transparent_background) Local $alert_background = GUICtrlCreatePic($image_alert, 0, 0, 230, 120) GUICtrlSetState(Default, $gui_disable) Local $alert_title = title_create($title, 220) Local $alert_text = GUICtrlCreateLabel($text, 10, 35, 210, 50, $ss_center) ;, bitor($ss_centerimage, $ss_center, $bs_multiline)) GUICtrlSetFont(Default, 8, 400, 0, $font_handel_gothic_bt) GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $color_control_gray) Local $alert_button_1 = -14, $alert_button_2 = -14, $alert_button_3 = -14 Switch $type Case $alert_ok $alert_button_2 = button_create('Ok', '', Default, 80, 95) Case $alert_link_close $alert_button_1 = button_create('Link', 'Go to the AutoIt forum to check for MiniMark updates.', Default, 5, 95) $alert_button_3 = button_create('Close', '', Default, 155, 95) Case $alert_yes_no_cancel $alert_button_1 = button_create('Yes', '', Default, 5, 95) $alert_button_2 = button_create('No', '', Default, 80, 95) $alert_button_3 = button_create('Cancel', '', Default, 155, 95) EndSwitch _WinAPI_SetLayeredWindowAttributes($alert_form, $color_transparent_background) ; set the transparant gui color GUISetState(@SW_SHOW) play_sound($sound_alert) Local $choice ; to return what button was clicked While 1 Switch GUIGetMsg() Case $gui_event_close $choice = 0 ExitLoop Case $alert_button_1 $choice = 1 ExitLoop Case $alert_button_2 $choice = 2 ExitLoop Case $alert_button_3 $choice = 3 ExitLoop EndSwitch WEnd play_sound($sound_click) GUIDelete($alert_form) Return $choice EndFunc ;==>alert #EndRegion custom msgbox #Region dll calls ; set per-monitor v2 dpi awareness (requires windows 10 creators update or later) dllcall("user32.dll", "bool", "setprocessdpiawarenesscontext", "ptr", -4) #EndRegion dll calls #Region parameters Func get_filename() Local $path_split = StringSplit($cmdline[1], '\', 3) Return StringTrimRight($path_split[UBound($path_split) - 1], 4) EndFunc ;==>get_filename Func wrong_file_extension($path = $cmdline[1]) Return StringRight($path, 4) <> '.mnm' EndFunc ;==>wrong_file_extension Func set_default_file() Global $cmdline = [1, $file_intro] ; overwrite if empty to load default intro file EndFunc ;==>set_default_file If $cmdline[0] = 1 Then If wrong_file_extension() Then alert('Wrong file type!', 'You can only open *.mnm files with this program.', $alert_ok) set_default_file() EndIf Else set_default_file() EndIf #EndRegion parameters #Region MiniMark gui $MiniMark_form = GUICreate('MiniMark', 380, 480, Default, Default, $ws_popup, $ws_ex_layered) GUISetBkColor($color_border_gray) $MiniMark_background = GUICtrlCreatePic($image_MiniMark, 0, 0, 380, 480) GUICtrlSetState(Default, $gui_disable) $MiniMark_title = title_create(get_filename(), 370) $MiniMark_edit = _GUICtrlRichEdit_Create($MiniMark_form, 'Loading...', 10, 35, 270, 435, BitOR($es_multiline, $es_autovscroll, $es_nohidesel), 0) ; $es_nohidesel for visible selection when using search function _GUICtrlRichEdit_SetBkColor($MiniMark_edit, $color_control_gray) $button_settings = button_create('Options', 'Open settings.', Default, 305, 30) $button_open = button_create('Open', 'Open a new *.mnm file.', 'ctrl + o', 305, 55) $button_save = button_create('Save', 'Save file / save file as.', 'ctrl + s / shift + ctrl + s', 305, 80) $save_as = GUICtrlCreateDummy() $button_search = button_create('Search', 'Find and replace text.', 'ctrl + f', 305, 105) $button_upper = button_create('Upper', 'Make selection upper case.', 'escape', 305, 130) $button_lower = button_create('Lower', 'Make selection lower case.', 'escape', 305, 155) $button_bold = button_create('Bold', 'Make selection bold.', 'ctrl + b', 305, 180) $button_italic = button_create('Italic', 'Make selection italic.', 'ctrl + i', 305, 205) $button_struck = button_create('Struck', 'Make selection struck.', 'ctrl + t', 305, 230) $button_underline = button_create('Underline', 'Make selection underlined.', 'ctrl + u', 305, 255) $button_red = button_create('Red', 'Make selection red.', 'shift + ctrl + r', 305, 280) $button_green = button_create('Green', 'Make selection green.', 'shift + ctrl + g', 305, 305) $button_blue = button_create('Blue', 'Make selection blue.', 'shift + ctrl + b', 305, 330) $button_white = button_create('White', 'Make selection white.', 'shift + ctrl + w', 305, 355) $button_default = button_create('Default', 'Make selection default style and gray.', 'shift + ctrl + d', 305, 380) $button_tick = button_create('Tick', 'Add a checkmark or toggle it.', 'shift + ctrl + d', 305, 405) $button_now = button_create('Time', 'Insert the current date and time.', 'shift + ctrl + d', 305, 430) $button_quit = button_create('Quit', 'Quit the program.', 'escape', 305, 455) $MiniMark_scroll_up = GUICtrlCreatePic($image_scroll_up, 290, 30, 10, 10) $MiniMark_scroll_thumb = GUICtrlCreatePic($image_scroll, 290, 45, 10, 40) ; scroll background: 290, 45, 10, 315 $MiniMark_scroll_down = GUICtrlCreatePic($image_scroll_down, 290, 465, 10, 10) _WinAPI_SetLayeredWindowAttributes($MiniMark_form, $color_transparent_background) ;set the transparant gui color GUISetState(@SW_SHOW, $MiniMark_form) play_sound($sound_start) ; play MiniMark startup sound. #EndRegion MiniMark gui #Region markup functions ; function that handles text color actions. Func colorize($color) ; if already in selected color -> make default color again play_sound($sound_click) If _GUICtrlRichEdit_GetCharColor($MiniMark_edit) <> $color Then _GUICtrlRichEdit_SetCharColor($MiniMark_edit, $color) Else _GUICtrlRichEdit_SetCharColor($MiniMark_edit, $color_text_gray) EndIf If $color = $color_text_gray Then _GUICtrlRichEdit_SetCharAttributes($MiniMark_edit, '-bo-it-un-st') EndFunc ;==>colorize ; function that handles text style actions. Func stylize($style) ; if already in selected style -> undo style play_sound($sound_click) If StringInStr(_GUICtrlRichEdit_GetCharAttributes($MiniMark_edit), $style & '+') Then _GUICtrlRichEdit_SetCharAttributes($MiniMark_edit, '-' & $style) Else _GUICtrlRichEdit_SetCharAttributes($MiniMark_edit, '+' & $style) EndIf EndFunc ;==>stylize #EndRegion markup functions #Region tools Func change_case($upper) Local $selection = _GUICtrlRichEdit_GetSel($MiniMark_edit) If $selection[0] = $selection[1] Then Return Local $selection_text = _GUICtrlRichEdit_GetSelText($MiniMark_edit) If $upper Then $selection_text = StringUpper($selection_text) Else $selection_text = StringLower($selection_text) EndIf _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $selection_text) _GUICtrlRichEdit_SetSel($MiniMark_edit, $selection[0], $selection[1]) EndFunc Func tickmark() Local $first_char = _GUICtrlRichEdit_GetFirstCharPosOnLine($MiniMark_edit) Local $line_from_char = _GUICtrlRichEdit_GetLineNumberFromCharPos($MiniMark_edit, $first_char) Local $tick_type = StringLeft(_GUICtrlRichEdit_GetTextInLine($MiniMark_edit, $line_from_char), 1) Local $tick_replace Switch $tick_type ; ■□○●• Case '☐' $tick_replace = '☑' Case '☑' $tick_replace = '☐' Case Else _GUICtrlRichEdit_SetSel($MiniMark_edit, $first_char, $first_char) _GUICtrlRichEdit_InsertText($MiniMark_edit, '☐ ') Return endSwitch _GUICtrlRichEdit_SetSel($MiniMark_edit, $first_char, $first_char + 1) _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $tick_replace) EndFunc #EndRegion tools #Region edit and scrollbar messages ; the scrollbar of hell! ; https://www.autoitscript.com/forum/topic/212778-goto-specific-line-in-rich-edit-control AutoItSetOption('MouseCoordMode', 2) ; 2 = relative coords to the client area of the active window _GUICtrlRichEdit_SetEventMask($MiniMark_edit, $enm_scrollevents) $Scrolling = False func MouseOnTumb() local $MouseXY = MouseGetPos() static local $BarX = 290 static local $BarY = 45 static local $BarWidth = 10 static local $BarHeight = 415 if $MouseXY[0] >= $BarX and $MouseXY[0] <= $BarX + $BarWidth and $MouseXY[1] >= $BarY and $MouseXY[1] <= $BarY + $BarHeight then $Scrolling = True ConsoleWrite(@CRLF & "SCROLLING -> " & $Scrolling) EndFunc guiregistermsg($wm_command, wm_command) func wm_command($hwnd, $imsg, $wparam, $lparam) if $scrolling then return $gui_rundefmsg if $lparam <> $minimark_edit then return $gui_rundefmsg if bitshift($wparam, 16) = $en_update then updatetumbposition() if _guictrlrichedit_istextselected($minimark_edit) then return $gui_rundefmsg if _guictrlrichedit_getfont($minimark_edit)[1] <> $font_lucida_console then _guictrlrichedit_setfont($minimark_edit, 9, $font_lucida_console) _guictrlrichedit_setcharcolor($minimark_edit, $color_text_gray) endif return $gui_rundefmsg endfunc guiregistermsg($wm_notify, wm_notify) func wm_notify($hwnd, $imsg, $wparam, $lparam) local $tfilter = dllstructcreate($tagmsgfilter, $lparam) if $tfilter.hwndfrom = $minimark_edit then _guictrlrichedit_scrolllines($tfilter.hwndfrom, $tfilter.wparam ? 1 : -1) return $gui_rundefmsg endfunc Func UpdateTumbPosition() local $LineFirst = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($minimark_edit) static local $EditHeight = 435 local $LineLast = _GUICtrlRichEdit_GetLineNumberFromCharPos($minimark_edit, _GUICtrlRichEdit_GetCharPosFromXY($minimark_edit, 1, $EditHeight)) local $LineCount = _GUICtrlRichEdit_GetLineCount($minimark_edit) local $LinesVisible = $LineLast - $LineFirst + 1 ; "+ 1" = count last visible line too local $MaxScrollableLines = $LineCount - $LinesVisible local $EditPercent = 0 If $MaxScrollableLines > 0 Then $EditPercent = ($LineFirst - 1) / $MaxScrollableLines ; "> 0" to prevent division by 0 static local $BarY = 45 static local $BarHeight = 415 static local $TumbX = 290 static local $TumbHeight = 40 local $TumbY = $BarY + $EditPercent * ($BarHeight - $TumbHeight) GUICtrlSetPos($MiniMark_scroll_thumb, $TumbX, $TumbY) EndFunc Func UpdateEditPosition() local $MouseY = MouseGetPos(1) static local $TumbHeight = 40 local $TumbY = $MouseY - $TumbHeight / 2 static local $BarY = 45 If $TumbY < $BarY Then $TumbY = $BarY static local $BarHeight = 415 static local $TumbMax = $BarY + $BarHeight - $TumbHeight If $TumbY > $TumbMax Then $TumbY = $TumbMax static local $TumbX = 290 GUICtrlSetPos($MiniMark_scroll_thumb, $TumbX, $TumbY) local $TumbPercent = ($TumbY - $BarY) / ($TumbMax - $BarY) local $LineFirst = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($minimark_edit) static local $EditHeight = 435 local $LineLast = _GUICtrlRichEdit_GetLineNumberFromCharPos($minimark_edit, _GUICtrlRichEdit_GetCharPosFromXY($minimark_edit, 1, $EditHeight)) local $LineCount = _GUICtrlRichEdit_GetLineCount($minimark_edit) local $LinesVisible = $LineLast - $LineFirst local $LineTop = $TumbPercent * ($LineCount - $LinesVisible) + 1 ; "+ 1" = becouse it's a 1-based system for line positions _GUICtrlRichEdit_ScrollLines($minimark_edit, $LineTop - $LineFirst) EndFunc #EndRegion edit and scrollbar messages #Region shortcuts ; here we set all the shortcuts for the buttons. Dim $hotkeysaccel[18][2] = [ _ ['+^d', $button_default], _ ['^b', $button_bold], _ ['^i', $button_italic], _ ['^u', $button_underline], _ ['^t', $button_struck], _ ['+^r', $button_red], _ ['+^g', $button_green], _ ['+^b', $button_blue], _ ['+^w', $button_white], _ ['^o', $button_open], _ ['^s', $button_save], _ ['+^s', $save_as], _ ['{f5}', $button_now], _ ['!t', $button_tick], _ ['!u', $button_upper], _ ['!l', $button_lower], _ ['^f', $button_search], _ ['{esc}', $button_quit] _ ] GUISetAccelerators($hotkeysaccel, $MiniMark_form) #EndRegion shortcuts #Region search gui $search_form = GUICreate('Search', 305, 105, Default, Default, $ws_popup, BitOR($ws_ex_layered, $ws_ex_topmost)) GUISetBkColor($color_transparent_background) GUICtrlCreatePic($image_search, 0, 0, 305, 105) GUICtrlSetState(Default, $gui_disable) $search_title = title_create('Find and replace', 295) $input_find = input_create(10, 30, 'What to look for.') $input_replace = input_create(10, 55, 'Replace by what.') $checkbox_case_state = 0 $checkbox_case = checkbox_create('Case', 'Toggle casesence.', Default, 230, 30) $checkbox_word_state = 0 $checkbox_word = checkbox_create('Word', 'Toggle whole word only.', Default, 230, 55) $button_search_find = button_create('Find', 'find string.', Default, 5, 80) $button_search_replace = button_create('Replace', 'Replace current match.', Default, 80, 80) $button_search_replace_all = button_create('Replace all', 'Replace all matches.', Default, 155, 80) $button_search_close = button_create('Close', '', Default, 230, 80) _WinAPI_SetLayeredWindowAttributes($search_form, $color_transparent_background) ;set the transparant gui color #EndRegion search gui #Region search functions Func find() Local $find_text = GUICtrlRead($input_find) If $find_text = '' Then Return play_sound($sound_click) Local $selection = _GUICtrlRichEdit_GetSel($MiniMark_edit) $selection = _GUICtrlRichEdit_FindTextInRange($MiniMark_edit, $find_text, $selection[1], -1, $checkbox_case_state = 1, $checkbox_word_state = 1) If $selection[0] = -1 And $selection[1] = -1 Then alert('Search ended', 'No more matches found.' & @CRLF & 'Next time when you press the [Find] button, the search function will start looking from the beginning of the text.', $alert_ok) _GUICtrlRichEdit_SetSel($MiniMark_edit, 0, 0) Else _GUICtrlRichEdit_SetSel($MiniMark_edit, $selection[0], $selection[1]) EndIf EndFunc ;==>find Func replace() Local $find_text = GUICtrlRead($input_find) If $find_text = '' Then Return play_sound($sound_click) Local $replace_text = GUICtrlRead($input_replace) _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $replace_text) find() EndFunc ;==>replace Func replace_all() Local $find_text = GUICtrlRead($input_find) If $find_text = '' Then Return play_sound($sound_click) Local $replace_text = GUICtrlRead($input_replace) Local $selection = _GUICtrlRichEdit_FindTextInRange($MiniMark_edit, $find_text, 0, -1, $checkbox_case_state = 1, $checkbox_word_state = 1) While $selection[0] > -1 And $selection[1] > -1 _GUICtrlRichEdit_SetSel($MiniMark_edit, $selection[0], $selection[1]) _GUICtrlRichEdit_ReplaceText($MiniMark_edit, $replace_text) $selection = _GUICtrlRichEdit_FindTextInRange($MiniMark_edit, $find_text, $selection[1], -1, $checkbox_case_state = 1, $checkbox_word_state = 1) WEnd alert('Search ended', 'No more matches found.' & @CRLF & 'All matches are replaced (if there were are any).', $alert_ok) EndFunc ;==>replace_all Func find_and_replace() play_sound($sound_click) local $selection_text = _GUICtrlRichEdit_GetSelText($MiniMark_edit) if @error <> -1 then GUICtrlSetData($input_find, $selection_text) GUISetState(@SW_SHOW, $search_form) While 1 Switch GUIGetMsg() Case $gui_event_close, $button_search_close play_sound($sound_click) GUISetState(@SW_HIDE, $search_form) ExitLoop Case $checkbox_case checkbox_toggle($checkbox_case, $checkbox_case_state) Case $checkbox_word checkbox_toggle($checkbox_word, $checkbox_word_state) Case $button_search_find find() Case $button_search_replace replace() Case $button_search_replace_all replace_all() EndSwitch WEnd EndFunc #EndRegion search functions #Region settings $font_size = Int(IniRead($file_settings, 'settings', 'fontsize', 100)) $settings_form = GUICreate('Settings', 230, 80, Default, Default, $ws_popup, BitOR($ws_ex_layered, $ws_ex_topmost)) GUISetBkColor($color_transparent_background) GUICtrlCreatePic($image_settings, 0, 0, 230, 80) GUICtrlSetState(Default, $gui_disable) $settings_title = title_create('Settings', 220) $checkbox_sound = checkbox_create('Sound', 'play sounds?', Default, 5, 30, $checkbox_sound_state) $button_settings_save = button_create('Save', 'Save settings.', Default, 5, 55) $button_settings_info = button_create('Info', 'About MiniMark.', Default, 155, 30) $button_settings_reset = button_create('Reset', 'Reset to default settings.', Default, 80, 55) $button_settings_close = button_create('Close', '', Default, 155, 55) $number_step = GUICtrlCreateInput($font_size, 85, 30, 45, 20, BitOR($es_center, $es_number, $es_autohscroll), 0) GUICtrlSetTip(Default, 'Custom font size (zoom).') GUICtrlSetColor(Default, $color_text_gray) GUICtrlSetBkColor(Default, $color_control_gray) GUICtrlSetFont(Default, 12, 400, 0, $font_handel_gothic_bt) GUICtrlSetLimit(Default, 8) $number_step_up = GUICtrlCreatePic($image_size_up, 130, 30, 20, 10) $number_step_down = GUICtrlCreatePic($image_size_down, 130, 40, 20, 10) _WinAPI_SetLayeredWindowAttributes($settings_form, $color_transparent_background) ;set the transparant gui color #EndRegion settings #Region settings function Func settings() play_sound($sound_click) GUICtrlSetData($number_step, Int(_GUICtrlRichEdit_GetZoom($MiniMark_edit))) GUISetState(@SW_SHOW, $settings_form) While 1 Switch GUIGetMsg() Case $gui_event_close, $button_settings_close play_sound($sound_click) GUISetState(@SW_HIDE, $settings_form) ExitLoop Case $checkbox_sound checkbox_toggle($checkbox_sound, $checkbox_sound_state) Case $number_step_up number_step(1) Case $number_step_down number_step(-1) Case $button_settings_info If alert('About', 'MiniMark version 4.' & @CRLF & 'Created by:' & @CRLF & 'Tom Schrauwen (TheAutomator).', $alert_link_close) = 1 Then ShellExecute('https://www.autoitscript.com/forum/topic/212763-MiniMark-a-minimalistic-rtf-editor') Case $button_settings_reset settings_reset() Case $button_settings_save settings_save() EndSwitch WEnd EndFunc #EndRegion settings function #Region settings messages ; write ini Func number_step($amount) Local $number = GUICtrlRead($number_step) $number += $amount GUICtrlSetData($number_step, $number) play_sound($sound_click) EndFunc ;==>number_step Func settings_reset() If Not $checkbox_sound_state Then checkbox_toggle($checkbox_sound, $checkbox_sound_state) GUICtrlSetData($number_step, 100) play_sound($sound_click) EndFunc ;==>settings_reset Func settings_save() IniWrite($file_settings, 'settings', 'sound', $checkbox_sound_state) IniWrite($file_settings, 'settings', 'fontsize', GUICtrlRead($number_step)) _GUICtrlRichEdit_SetZoom($MiniMark_edit, GUICtrlRead($number_step)) play_sound($sound_click) EndFunc ;==>settings_save #EndRegion settings messages #Region file functions ; if this is not the case, or when there are no arguments, we just open the intro file instead. ; also extract the filename from $cmdline to display as title. Func load_file() ; add fileexists check? GUICtrlSetData($MiniMark_title, get_filename()) GUICtrlSetTip($MiniMark_title, $cmdline[1]) ; display full path on mouse over title _GUICtrlRichEdit_Deselect($MiniMark_edit) _GUICtrlRichEdit_StreamFromFile($MiniMark_edit, $cmdline[1]) _GUICtrlRichEdit_SetZoom($MiniMark_edit, Int($font_size)) ; needed becouse it resets after loading (https://www.autoitscript.com/forum/topic/190695-_guictrlrichedit_setzoom-parameter-limitation) _GUICtrlRichEdit_SetModified($MiniMark_edit, False) _GUICtrlRichEdit_EmptyUndoBuffer($MiniMark_edit) updatetumbposition() EndFunc ;==>load_file load_file() ; load input file ; before opening another file or before quitting, we need to check if the current file is modified. Func save_changes_cancel() ; returns true if we wanna cancel follow up actions If Not _GUICtrlRichEdit_IsModified($MiniMark_edit) Then Return Switch alert('Save changes?', 'This file was modified.' & @CRLF & 'Do you wanna save your work first?', $alert_yes_no_cancel) Case 1 ; yes save_file() Case 2 ; no Return Case Else Return True ; abort next actions EndSwitch EndFunc ;==>save_changes_cancel ; the function that saves the current text to a *.mnm file. ; _guictrlrichedit_streamtofile($edit, $cmdline[1]) -> bug, adds new paragraph every time (see ticket). Func save_file($as = False) ; as triggers a save to dialog If $as Then play_sound($sound_click) Local $new_file = FileSaveDialog('Save MiniMark file...', @DesktopDir, 'MiniMark file (*.mnm)', 16, '', $MiniMark_form) If @error Or wrong_file_extension() Then Return $cmdline[1] = $new_file GUICtrlSetTip($MiniMark_title, $new_file) ; display full path on mouse over title GUICtrlSetData($MiniMark_title, get_filename()) Else If Not _GUICtrlRichEdit_IsModified($MiniMark_edit) Then Return play_sound($sound_click) EndIf _GUICtrlRichEdit_Deselect($MiniMark_edit) Local $var = _GUICtrlRichEdit_StreamToVar($MiniMark_edit) $var = StringTrimRight($var, 9) & "}" ; bug will be resolved in future versions Local $file = FileOpen($cmdline[1], $fo_overwrite) Local $written = FileWrite($file, $var) FileClose($file) If $written = 1 Then ; 0 = failed to write, 1 = succes _GUICtrlRichEdit_SetModified($MiniMark_edit, False) Else alert('File write error!', "Can't save the file..." & @CRLF & 'Check if the file is read only.', $alert_ok) EndIf EndFunc ;==>save_file ; open a file with the open dialog. Func open_file() If save_changes_cancel() Then Return play_sound($sound_click) Local $file = FileOpenDialog('Open new MiniMark file...', @DesktopDir, 'MiniMark file (*.mnm)', 3, '', $MiniMark_form) If @error Or wrong_file_extension() Then Return $cmdline[1] = $file load_file() EndFunc ;==>open_file #EndRegion file functions #Region quit function ; when the program unloads we need to destroy the rich edit control and play the stop sound Func quit() If save_changes_cancel() Then Return play_sound($sound_stop, 1) _GUICtrlRichEdit_Destroy($MiniMark_edit) GUIDelete() Exit EndFunc ;==>quit #EndRegion quit function #Region main loop While 1 Switch GUIGetMsg() Case $gui_event_close, $button_quit quit() Case $button_now _GUICtrlRichEdit_InsertText($MiniMark_edit, _now()) Case $button_tick tickmark() Case $button_upper change_case(True) Case $button_lower change_case(False) Case $MiniMark_scroll_up play_sound($sound_click) _GUICtrlRichEdit_ScrollLines($MiniMark_edit, -1) Case $MiniMark_scroll_down play_sound($sound_click) _GUICtrlRichEdit_ScrollLines($MiniMark_edit, 1) Case $button_open open_file() Case $button_save save_file() Case $save_as save_file(True) Case $button_bold stylize('bo') Case $button_italic stylize('it') Case $button_struck stylize('st') Case $button_underline stylize('un') Case $button_red colorize($color_text_red) Case $button_green colorize($color_text_green) Case $button_blue colorize($color_text_blue) Case $button_white colorize($color_text_white) Case $button_default colorize($color_text_gray) Case $gui_event_primarydown MouseOnTumb() Case $gui_event_mousemove if $Scrolling then UpdateEditPosition() Case $gui_event_primaryup $Scrolling = False Case $button_search find_and_replace() Case $button_settings settings() EndSwitch WEnd #EndRegion main loop And here is the code for the installer: SETUP FOR VERSION 4 STILL IN THE MAKING! #cs function: installer for MiniMark version: 3 made by: TheAutomator project: https://www.autoitscript.com/forum/topic/212763-minimark-a-minimalistic-rtf-editor todo: • check if programfiles exist when opened • add choice for install path and user level install • installer does'nt use the "fileinstall" function (yet) #ce #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #autoit3wrapper_icon=setup\setup.ico #autoit3wrapper_outfile=Setup.EXE #autoit3wrapper_compression=4 #autoit3wrapper_useupx=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #NoTrayIcon #RequireAdmin #include <guiconstants.au3> #include <winapisyswin.au3> const $source_path = @ScriptDir & '\minimark' const $setup_path = @ScriptDir & '\setup' const $install_path = @ProgramFilesDir & '\MiniMark' const $install_font = @ScriptDir & '\setup\handelgo.ttf' const $font_lucida = 'lucida console' const $image_background = @scriptdir & '\setup\setup.bmp' const $image_install = @scriptdir & '\setup\install.bmp' const $image_remove = @scriptdir & '\setup\remove.bmp' const $image_exit = @scriptdir & '\minimark\exit.bmp' const $color_gui_transparant = 0xff00ff const $color_edit_background = 0x323232 const $color_edit_gray = 0xb4b4b4 const $color_edit_red = 0xff0066 const $color_edit_green = 0x66ff00 const $sound_start = @scriptdir & '\minimark\start.wav' const $sound_click = @scriptdir & '\minimark\click.wav' const $sound_alert = @scriptdir & '\minimark\alert.wav' const $sound_stop = @scriptdir & '\minimark\stop.wav' local $check_installed = FileExists($install_path) soundplay($sound_start) ; startup sound $form = guicreate('MiniMark Setup', 310, 240, default, default, $ws_popup, $ws_ex_layered) guisetbkcolor($color_gui_transparant) $title = guictrlcreatelabel('', 10, 10, 280, 20, $SS_GRAYRECT, $gui_ws_ex_parentdrag) ; use label to drag form (hidden behind gui image) guictrlcreatepic($image_background, 0, 0, 310, 240) guictrlsetstate(default, $gui_disable) $console = GUICtrlCreateEdit('MiniMark V3 setup' & @CRLF & 'made by: TheAutomator', 20, 50, 270, 140, bitor($es_multiline, $es_autovscroll, $es_readonly), 0) GUICtrlSetColor(Default, $color_edit_gray) GUICtrlSetBkColor(Default, $color_edit_background) GUICtrlSetFont(Default, 9, 0, 0, $font_lucida) $button_install = guictrlcreatepic($check_installed ? $image_remove : $image_install, 10, 210, 50, 20) $button_exit = guictrlcreatepic($image_exit, 250, 210, 50, 20) $escape = guictrlcreatedummy() dim $hotkeysaccel[1][2] = [["{esc}", $escape]] guisetaccelerators($hotkeysaccel) _winapi_setlayeredwindowattributes($form, $color_gui_transparant) ; 0xff00ff is set as the transparant gui color guisetstate() func console($text) GUICtrlSetData($console, @crlf & @crlf & $text, 1) EndFunc console($check_installed ? 'it looks like MiniMark is already installed, press [remove] to uninstall' : 'it looks like MiniMark is not installed yet, press [install] to install it') func install_remove() ; needs admin rights, compiling installer to exe is probably needed... GUICtrlSetColor($console, $color_edit_green) soundplay($sound_click) GUICtrlSetState($button_install, $gui_hide) if $check_installed then ; remove it console('removing MiniMark from:') console($install_path) DirRemove($install_path, 1) console('removing MiniMark menu') RegDelete('HKEY_CLASSES_ROOT\.mnm') RegDelete('HKEY_CLASSES_ROOT\MiniMark') console('removing "handelgothic bt" font') RegDelete('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', 'HandelGothic BT (TrueType)') ; uninstall font in registery DllCall('gdi32.dll', 'int', 'RemoveFontResource', 'str', @WindowsDir & '\Fonts\handelgo.ttf') ; uninstall font in fonts folder DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', 0xFFFF, 'int', 0x1D, 'int', 0, 'int', 0) ; tell windows about font changes FileDelete(@WindowsDir & '\Fonts\handelgo.ttf') ; delete font in fonts folder $check_installed = FileExists($install_path) if $check_installed Then GUICtrlSetColor($console, $color_edit_red) soundplay($sound_alert) console('MiniMark was not removed correctly...') Else console('MiniMark was uninstalled succesfully!') EndIf Else ; install it console('installing MiniMark to:') console($install_path) DirCopy($source_path, $install_path, 1) ; $fc_overwrite console('installing MiniMark menu') RegWrite('HKEY_CLASSES_ROOT\.mnm', '', 'REG_SZ', 'MiniMark') ; add filetype RegWrite('HKEY_CLASSES_ROOT\.mnm', 'PerceivedType', 'REG_SZ', 'Document') ; tell windows it's a document RegWrite('HKEY_CLASSES_ROOT\.mnm\ShellNew', 'NullFile', 'REG_SZ', '') ; add it to the 'new' file menu RegWrite('HKEY_CLASSES_ROOT\MiniMark', '', 'REG_SZ', 'MiniMark File') ; add edit menu for *.mnm file RegWrite('HKEY_CLASSES_ROOT\MiniMark', 'BrowserFlags', 'REG_DWORD', '00000008') RegWrite('HKEY_CLASSES_ROOT\MiniMark', 'EditFlags', 'REG_DWORD', '00000000') RegWrite('HKEY_CLASSES_ROOT\MiniMark\DefaultIcon', '', 'REG_SZ', $install_path & '\MiniMark.exe,0') ; set icon for *.mnm file RegWrite('HKEY_CLASSES_ROOT\MiniMark\Shell\Open', 'Icon', 'REG_SZ', $install_path & '\MiniMark.exe,0') ; set icon for open menu RegWrite('HKEY_CLASSES_ROOT\MiniMark\Shell\Open\Command', '', 'REG_SZ', $install_path & '\MiniMark.exe "%1"') ; always open with MiniMark console('installing "handelgothic bt" font') FileCopy($install_font, @WindowsDir & '\Fonts\', 1) ; $FC_OVERWRITE (1) = overwrite existing files RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', 'HandelGothic BT (TrueType)', 'REG_SZ', 'handelgo.ttf') ; install font in registery DllCall('gdi32.dll', 'int', 'AddFontResource', 'str', @WindowsDir & '\Fonts\handelgo.ttf') ; install font in fonts folder DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', 0xFFFF, 'int', 0x1D, 'int', 0, 'int', 0) ; tell windows about font changes DllCall('shell32.dll', 'none', 'SHChangeNotify', 'long', 0x08000000, 'uint', 0, 'ptr', 0, 'ptr', 0) ; refresh the icon cache (ie4uinit.exe -show) $check_installed = FileExists($install_path) if $check_installed Then console('MiniMark was installed succesfully!') Else GUICtrlSetColor($console, $color_edit_red) soundplay($sound_alert) console('MiniMark was not installed correctly...') EndIf EndIf guictrlsetimage($button_install, $check_installed ? $image_remove : $image_install) GUICtrlSetState($button_install, $gui_show) EndFunc func quit() soundplay($sound_stop, 1) exit endfunc while 1 switch guigetmsg() case $gui_event_close, $button_exit, $escape quit() case $button_install install_remove() endswitch wend Enjoy, TheAutomator. MiniMark 4 beta test.zip7 points -
I shamelessly used (copied and pasted) a very nice @eukalyptus's script to underline and send you some auspicious messages ... sorry for the laziness... ; source ; https://autoit.de/thread/17855-led-laufschrift/ ; ; reference for this script (by Eukalyptus): ; https://autoit.de/thread/17855-led-laufschrift/?postID=140164#post140164 #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIPlusConstants.au3> ; #include "LEDTXT.au3" ; (by Eukalyptus) already embedded here below Local $sText1 = "Hello friends! ☺ best wishes for a happy holiday and a happy new year (me)" Local $sText2 = "Let us greet together this new year that ages our friendship without aging our hearts. (Victor Hugo)" Local $sText3 = "The best time to plant a tree was 20 years ago. The second best time is now. (Chinese proverb)" Local $sText4 = "The future belongs to those who believe in the beauty of their dreams. (Eleanor Roosevelt)" Local $sText5 = "In the end, what matters is not the years of your life, but the life you put into those years. (Abraham Lincoln)" HotKeySet("{ESC}", "_Exit") _GDIPlus_Startup() $hGuiTrans = GUICreate("", @DesktopWidth, 300, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) GUISetBkColor(0xABCDEF) _WinAPI_SetLayeredWindowAttributes($hGuiTrans, 0xABCDEF) GUISetState() $hGui = GUICreate("", @DesktopWidth, 400, 0, 300, Default, $WS_EX_TOPMOST) ; WinSetTrans($hGui, "", 100) GUISetState() #cs parameters info: $hGui: Handle to the window $sText: The text $iX: X position of the scrolling text $iY: Y position $iW: Length $iH: Height $iType: Appearance of the LEDs 0=Round with 3D effect, 1=Square with 3D, 2=Round, 3=Square; (the last two are filled and/or outlined, depending on which colors are <>0) $iLedW = X-size of an LED $iLedH = Y-size of an LED $nLedOnCol1 = Color 1 of the ON LEDs (foreground for 3D, fill color for $iType 2 and 3) $nLedOnCol2 = Color 2 of the ON LEDs (background for 3D, color of the outline for $iType 2 and 3) $nLedOffCol1 = Color 1 of the OFF LEDs $nLedOffCol2 = Color 2 of the OFF LEDs $nBkColor = Background color $iDistW = X-distance of the LEDs $iDistH = Y-distance of the LEDs $sFont = Font $iTextSize = Font size $iTextOpt = Font options (see _GDIPlus_FontCreate ) $iTextOffY = Y offset of the font #ce $aLed1 = _LEDTXT_Create_Gdi($hGuiTrans, $sText1, 0, 0, @DesktopWidth, 50, 0, 2, 2, 0xFFFFAA00, 0xFF000000, 0xAA111122, 0xAA000000, 0, 0, 0, "Courier New", 40, 1) $aLed2 = _LEDTXT_Create_Gdi($hGuiTrans, $sText2, 0, 50, @DesktopWidth, 50, 3, 2, 2, 0, 0xFF0088FF, 0, 0xFF000000, 0, 0, 0, "Arial", 40, 1) $aLed3 = _LEDTXT_Create_Gdi($hGuiTrans, $sText3, 0, 100, @DesktopWidth, 100, 1, 4, 4, 0xFFFF0000, 0xFF000000, 0, 0, 0xFFABCDEF, 1, 1, "Times New Roman", 80, 1) $aLed4 = _LEDTXT_Create_Gdi($hGuiTrans, $sText4, 0, 200, @DesktopWidth, 100, 1, 4, 4, 0xFF00FF00, 0xFF000000, 0xFFABCDEF, 0xFFABCDEF, 0xFFABCDEF, 0, 0, "Arial", 80, 1) $aLed5 = _LEDTXT_Create_Gdi($hGui, $sText5, 0, 0, @DesktopWidth, 350, 0, 14, 14, 0xFF00FF00, 0xFF00AA00, 0x44111119, 0x4400EE00, 0x44000000, 0, 0, "Arial", 410, 1, -60) GUIRegisterMsg($WM_ERASEBKGND, "_WM_ERASEBKGND") While 1 _LEDTXT_Step($aLed1, 1) _LEDTXT_Step($aLed2, -1) _LEDTXT_Step($aLed3, 1) _LEDTXT_Step($aLed4, -1) _LEDTXT_Step($aLed5, 1) _WinAPI_RedrawWindow($hGuiTrans, 0, 0, 5) _WinAPI_RedrawWindow($hGui, 0, 0, 5) Sleep(10) WEnd Func _WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam) Switch $hWnd Case $hGuiTrans _LEDTXT_Draw($aLed1) _LEDTXT_Draw($aLed2) _LEDTXT_Draw($aLed3) _LEDTXT_Draw($aLed4) Case $hGui _LEDTXT_Draw($aLed5) EndSwitch Return True EndFunc ;==>_WM_ERASEBKGND Func _Exit() _LEDTXT_Destroy($aLed1) _LEDTXT_Destroy($aLed2) _LEDTXT_Destroy($aLed3) _LEDTXT_Destroy($aLed4) _LEDTXT_Destroy($aLed5) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit ; =============================== ; LEDTXT.au3 (by Eukalyptus) ; =============================== Func _LEDTXT_Step(ByRef $aLed, $iDir = 1) $aLed[6] -= $aLed[8] * $iDir Select Case $aLed[6] + $aLed[7] < 0 $aLed[6] = 0 Case $aLed[6] > 0 $aLed[6] = -$aLed[7] EndSelect EndFunc ;==>_LEDTXT_Step Func _LEDTXT_Draw($aLed) Local $iPos = Round($aLed[6]) - Mod(Round($aLed[6]), $aLed[8]) Switch $aLed[10] Case True Switch $iPos Case -$aLed[7] To -$aLed[7] + $aLed[4] _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], -$iPos, 0, $iPos + $aLed[7], $aLed[5], $aLed[2], $aLed[3], $iPos + $aLed[7], $aLed[5]) If $aLed[6] + $aLed[7] < $aLed[4] Then _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], 0, 0, $aLed[4] - ($iPos + $aLed[7]), $aLed[5], $aLed[2] + $iPos + $aLed[7], $aLed[3], $aLed[4] - ($iPos + $aLed[7]), $aLed[5]) Case Else _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], -$iPos, 0, $aLed[4], $aLed[5], $aLed[2], $aLed[3], $aLed[4], $aLed[5]) EndSwitch Case Else Switch $iPos Case -$aLed[7] To -$aLed[7] + $aLed[4] _WinAPI_BitBlt($aLed[0], $aLed[2], $aLed[3], $aLed[2] + $iPos + $aLed[7], $aLed[5], $aLed[1], -$iPos, 0, $MERGECOPY) If $aLed[6] + $aLed[7] < $aLed[4] Then _WinAPI_BitBlt($aLed[0], $aLed[2] + $iPos + $aLed[7], $aLed[3], $aLed[4] - ($iPos + $aLed[7]), $aLed[5], $aLed[1], 0, 0, $MERGECOPY) Case Else _WinAPI_BitBlt($aLed[0], $aLed[2], $aLed[3], $aLed[4], $aLed[5], $aLed[1], -$iPos, 0, $MERGECOPY) EndSwitch EndSwitch EndFunc ;==>_LEDTXT_Draw Func _LEDTXT_Create_GdiPlus($hGui, $sText, $iX, $iY, $iW, $iH, $iType, $iLedW = 8, $iLedH = 8, $nLedOnCol1 = 0xFFFFAA00, $nLedOnCol2 = 0xFF000000, $nLedOffCol1 = 0xAA111122, $nLedOffCol2 = 0xAA000000, $nBkColor = 0xFF000000, $iDistW = 0, $iDistH = 0, $sFont = "Arial", $iTextSize = 0, $iTextOpt = 1, $iTextOffY = 0) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) Local $hLedOn = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOnCol1, $nLedOnCol2) Local $hLedOff = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOffCol1, $nLedOffCol2) Local $hLed, $iWidth $hLed = _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, $iWidth) Local $aReturn[11] $aReturn[0] = $hGraphics $aReturn[1] = $hLed $aReturn[2] = $iX $aReturn[3] = $iY $aReturn[4] = $iW $aReturn[5] = $iH $aReturn[6] = 0 $aReturn[7] = $iWidth $aReturn[8] = $iLedW + $iDistW $aReturn[9] = 0 $aReturn[10] = True ; True = _GdiPlus, False=_WinApi Return $aReturn EndFunc ;==>_LEDTXT_Create_GdiPlus Func _LEDTXT_Create_Gdi($hGui, $sText, $iX, $iY, $iW, $iH, $iType, $iLedW = 8, $iLedH = 8, $nLedOnCol1 = 0xFFFFAA00, $nLedOnCol2 = 0xFF000000, $nLedOffCol1 = 0xAA111122, $nLedOffCol2 = 0xAA000000, $nBkColor = 0xFF000000, $iDistW = 0, $iDistH = 0, $sFont = "Arial", $iTextSize = 0, $iTextOpt = 1, $iTextOffY = 0) Local $bGdiStarted = True If Not $__g_hGDIPDll Then $bGdiStarted = False _GDIPlus_Startup() EndIf Local $hDC = _WinAPI_GetDC($hGui) Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC) Local $hLedOn = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOnCol1, $nLedOnCol2) Local $hLedOff = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOffCol1, $nLedOffCol2) Local $hLed, $iWidth $hLed = _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, $iWidth) Local $hBmpDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hLed) _WinAPI_SelectObject($hBmpDC, $hBmp) Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hLed) Local $aReturn[11] $aReturn[0] = $hDC $aReturn[1] = $hBmpDC $aReturn[2] = $iX $aReturn[3] = $iY $aReturn[4] = $iW $aReturn[5] = $iH $aReturn[6] = 0 $aReturn[7] = $iWidth $aReturn[8] = $iLedW + $iDistW $aReturn[9] = $hBmp ; zum späteren destroy?! $aReturn[10] = False ; True = _GdiPlus, False=_WinApi _GDIPlus_GraphicsDispose($hGraphics) If Not $bGdiStarted Then _GDIPlus_Shutdown() Return $aReturn EndFunc ;==>_LEDTXT_Create_Gdi Func _LEDTXT_Destroy($aLed) Switch $aLed[10] Case True _GDIPlus_BitmapDispose($aLed[1]) _GDIPlus_GraphicsDispose($aLed[0]) Case Else _WinAPI_DeleteObject($aLed[9]) _WinAPI_ReleaseDC(0, $aLed[1]) _WinAPI_DeleteDC($aLed[0]) EndSwitch EndFunc ;==>_LEDTXT_Destroy Func _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, ByRef $iReturnW) $sText = StringReplace($sText, @LF, "") $iW -= Mod($iW, $iLedW + $iDistW) If Not $iTextSize Then $iTextSize = $iH Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iTextSize, $iTextOpt, 2) Local $tLayout = _GDIPlus_RectFCreate($iW, 0, 0, 0) Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat) Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width")) + $iW $iWidth -= Mod($iWidth, $iLedW + $iDistW) Local $iHeight = $iH ;Ceiling(DllStructGetData($aInfo[0], "Height")) DllStructSetData($aInfo[0], "Y", $iTextOffY) Local $hBmpTxt = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics) Local $hBmpLed = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics) Local $hBmpTmp = _GDIPlus_BitmapCreateFromGraphics($iLedW, $iHeight, $hGraphics) Local $hGfxTxt = _GDIPlus_ImageGetGraphicsContext($hBmpTxt) Local $hGfxLed = _GDIPlus_ImageGetGraphicsContext($hBmpLed) Local $hGfxTmp = _GDIPlus_ImageGetGraphicsContext($hBmpTmp) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) _GDIPlus_GraphicsClear($hGfxTxt, 0xFF000000) If $nBkColor Then _GDIPlus_GraphicsClear($hGfxLed, $nBkColor) _GDIPlus_GraphicsDrawStringEx($hGfxTxt, $sText, $hFont, $aInfo[0], $hFormat, $hBrush) Local $BitmapData = _GDIPlus_BitmapLockBits($hBmpTxt, $iW, 0, $iWidth - $iW, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local $Stride = DllStructGetData($BitmapData, "Stride") Local $Width = DllStructGetData($BitmapData, "Width") Local $Height = DllStructGetData($BitmapData, "Height") Local $Scan0 = DllStructGetData($BitmapData, "Scan0") Local $PixelData = DllStructCreate("ubyte lData[" & (Abs($Stride) * $Height - 1) & "]", $Scan0) If $hLedOff Then For $i = 0 To $Height - 1 Step $iLedH + $iDistH _GDIPlus_GraphicsDrawImage($hGfxTmp, $hLedOff, 0, $i) Next For $i = 0 To $iW - 1 Step $iLedW + $iDistW _GDIPlus_GraphicsDrawImage($hGfxLed, $hBmpTmp, $i, 0) Next EndIf For $col = 0 To $Width - 1 Step $iLedW + $iDistW If $hLedOff Then _GDIPlus_GraphicsDrawImage($hGfxLed, $hBmpTmp, $col + $iW, 0) For $row = 0 To $Height - 1 Step $iLedH + $iDistH If DllStructGetData($PixelData, 1, $row * $Stride + ($col * 4) + 1) Then _GDIPlus_GraphicsDrawImage($hGfxLed, $hLedOn, $col + $iW, $row) Next Next _GDIPlus_BitmapUnlockBits($hBmpTxt, $BitmapData) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BitmapDispose($hBmpTxt) _GDIPlus_GraphicsDispose($hGfxTxt) _GDIPlus_BitmapDispose($hBmpTmp) _GDIPlus_GraphicsDispose($hGfxTmp) _GDIPlus_GraphicsDispose($hGfxLed) $iReturnW = $iWidth Return $hBmpLed EndFunc ;==>_LEDTXT_Create_Bmp Func _LEDTXT_Create_Led($hGraphics, $iType, $iWidth, $iHeight, $nColor1, $nColor2) If Not $nColor1 And Not $nColor2 Then Return 0 Local $hBmp = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $hGraphics) Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp) Switch $iType Case 0 Local $hPen = _GDIPlus_PenCreate() Local $hPath = _GDIPlus_CreatePath() _GDIPlus_AddPathEllipse($hPath, 0, 0, $iWidth, $iHeight) Local $hBrushGrad = _GDIPlus_CreatePathGradientFromPath($hPath) _GDIPlus_SetLineGammaCorrection($hBrushGrad, True) _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrushGrad, $nColor2) _GDIPlus_SetPathGradientCenterColor($hBrushGrad, $nColor1) _GDIPlus_FillPath($hGfx, $hBrushGrad, $hPath) _GDIPlus_ClosePathFigure($hPath) _GDIPlus_GraphicsDrawEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrushGrad) _GDIPlus_PathDispose($hPath) Case 1 Local $hPen = _GDIPlus_PenCreate() Local $hPath = _GDIPlus_CreatePath() _GDIPlus_AddPathRectangle($hPath, 0, 0, $iWidth, $iHeight) Local $hBrushGrad = _GDIPlus_CreatePathGradientFromPath($hPath) _GDIPlus_SetLineGammaCorrection($hBrushGrad, True) _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrushGrad, $nColor2) _GDIPlus_SetPathGradientCenterColor($hBrushGrad, $nColor1) _GDIPlus_FillPath($hGfx, $hBrushGrad, $hPath) _GDIPlus_ClosePathFigure($hPath) _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrushGrad) _GDIPlus_PathDispose($hPath) Case 2 If $nColor1 Then Local $hBrush = _GDIPlus_BrushCreateSolid($nColor1) _GDIPlus_GraphicsFillEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hBrush) _GDIPlus_BrushDispose($hBrush) EndIf If $nColor2 Then Local $hPen = _GDIPlus_PenCreate($nColor2) _GDIPlus_GraphicsDrawEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) EndIf Case 3 If $nColor1 Then Local $hBrush = _GDIPlus_BrushCreateSolid($nColor1) _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $iWidth, $iHeight, $hBrush) _GDIPlus_BrushDispose($hBrush) EndIf If $nColor2 Then Local $hPen = _GDIPlus_PenCreate($nColor2) _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) EndIf EndSwitch _GDIPlus_GraphicsDispose($hGfx) Return $hBmp EndFunc ;==>_LEDTXT_Create_Led Func _GDIPlus_CreatePath($brushMode = 0) Local $hPath $hPath = DllCall($__g_hGDIPDll, "int", "GdipCreatePath", "int", $brushMode, "handle*", 0) If @error Then Return SetError(1, @error, 0) Return SetError($hPath[0], 0, $hPath[2]) EndFunc ;==>_GDIPlus_CreatePath Func _GDIPlus_AddPathEllipse($hPath, $iX, $iY, $iWidth, $iHeight) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipAddPathEllipse", "handle", $hPath, "float", $iX, "float", $iY, "float", $iWidth, "float", $iHeight) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_AddPathEllipse Func _GDIPlus_AddPathRectangle($hPath, $iX, $iY, $iWidth, $iHeight) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipAddPathRectangle", "handle", $hPath, "float", $iX, "float", $iY, "float", $iWidth, "float", $iHeight) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_AddPathRectangle Func _GDIPlus_CreatePathGradientFromPath($hPath) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[2]) EndFunc ;==>_GDIPlus_CreatePathGradientFromPath Func _GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetLineGammaCorrection", "handle", $hBrush, "int", $useGammaCorrection) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_SetLineGammaCorrection Func _GDIPlus_SetPathGradientCenterColor($hBrush, $iARGB) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetPathGradientCenterColor", "handle", $hBrush, "int", $iARGB) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_SetPathGradientCenterColor Func _GDIPlus_FillPath($hGraphic, $hBrushGrad, $hPath) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGraphic, "handle", $hBrushGrad, "handle", $hPath) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_FillPath Func _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $aArgb) Local $iI, $iCount, $aResult, $res, $x, $pArgb If IsArray($aArgb) Then $iCount = UBound($aArgb) $tArgb = DllStructCreate("int[" & $iCount & "]") $pArgb = DllStructGetPtr($tArgb) For $iI = 0 To $iCount - 1 DllStructSetData($tArgb, 1, $aArgb[$iI], $iI + 1) Next Else $iCount = 1 $tArgb = DllStructCreate("int") $pArgb = DllStructGetPtr($tArgb) DllStructSetData($tArgb, 1, $aArgb, 1) EndIf $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush, "int", $pArgb, "int*", $iCount) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], $aResult[3], $aResult[0] = 0) EndFunc ;==>_GDIPlus_SetPathGradientSurroundColorsWithCount Func _GDIPlus_ClosePathFigure($hPath) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_ClosePathFigure Func __GDIPlus_PathDispose($hPath) Local $aResult = DllCall($__g_hGDIPDll, "uint", "GdipDeletePath", "handle", $hPath) If @error Then Return SetError(1, @error, 0) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>__GDIPlus_PathDispose7 points
-
Just a bit of fun because evidently I have too much time on my hands! I'm doing all sorts of bad things to in order to handle note on/off events from the stream - so I wouldn't recommend using that part for any real project. A few days early, but happy new year folks!🎉 HappyNewYear.zip7 points
-
Hi folks, Attached below is one way of attacking WinRT Objects. These are essentially COM objects, however they don't have an IDispatch interface so ObjCreate() cannot be used. It is possible to expose them using ObjCreateInterface though. Alternately, DllCallAddress() may be used to access an object's functions directly from memory. I'm using the latter mainly because that's the path I started down first! To make sense of whats in the attachment... WinRT.au3 - Core high level functions that sit on top of interface libraries Includes Async and Collection implementations etc. So basic high level functionality. WinRTCore.au3 - Internal helper functions for interface libraries Interface Folder - Interface libraries (there are over 850 of these!). Essentially these wrap the functions in an interface's vtable Includes tags which may be used with ObjCreateInterface Enums Folder - Contains map datatypes that can be used to convert enumeration strings to their numeric type, or vice versa Classes Folder - doesn't actually contain code - A class file includes interface and enum files that belong to a class. Namespaces Folder - doesn't actually contain code - A namespace file includes classes that are related. Bonus: I've also uploaded a rudimentary WinRT Class Explorer if it happens to be useful to anyone. Bonus2: I've added a tool that installs/removes calltips for interface libraries. Original post: WinRT Libraries - Latest ClassExplorer.zip7 points
-
Unsure if this is intended, but as some of you noticed chromedriver now tries to use a random port on opening. You can override that by supplying the desired port number as a parameter -- _WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & @ScriptDir & '\chrome.log"')7 points
-
JSON UDF using JSON-C
Musashi and 5 others reacted to seangriffin for a topic
I created this UDF for JSON using JSON-C because I needed high performance parsing of JSON data in my script. I needed to query large data arrays of several thousand entries and other UDFs were taking many seconds to do so. With this UDF a query of 5,000 array entries takes me about 600ms (see Example2.au3). This UDF executes JSON functions through a JSON-C DLL to achieve better performance. The JSON-C project is https://github.com/json-c/json-c. To download this UDF please visit https://github.com/seanhaydongriffin/JsonC-UDF. Two examples are provided (Example1.au3 and Example2.au3) that demonstrate all the functions.6 points -
Hi all, I've just been playing with window messages that are sent to win32 controls themselves (rather than to the parent GUI), and it looks like you can do some cool stuff. So I thought I'd share some things that I found interesting. And yeah I know the code probably needs a cleanup - but I figure its good enough to get the point across... Anyway what I have is: while the "lock" checkbox is selected, the buttons behave normally. Otherwise you can drag them around and/or resize them. Because you're essentially dragging the buttons by their "Caption" bar, double clicking will also maximise them. #include <guiConstants.au3> #include <winapi.au3> Global Const $DLGC_BUTTON = 0x2000 Global Const $DLGC_WANTTAB = 0x0002 Global $hGui = GUICreate("", 300, 200) Global $idBtn = GUICtrlCreateButton("Button 1", 4, 4, 80, 80) Global $idBtn2 = GUICtrlCreateButton("Button 2", 90, 4, 80, 80) Global $idLockButtons = GUICtrlCreateCheckbox("Lock Buttons", 200, 20, 80, 20) Global $hCursor = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, $OCR_CROSS)) Global $hBtnMoveProc = DllCallbackRegister("ButtonMoveProc", "long", "hwnd;uint;wparam;lparam") Global $pBtnMoveProc = DllCallbackGetPtr($hBtnMoveProc) Global $hBtn = GUICtrlGetHandle($idBtn) Global $hBtn2 = GUICtrlGetHandle($idBtn2) Global $pOrigBtnProc = _WinAPI_SetWindowLong($hBtn, $GWL_WNDPROC, $pBtnMoveProc) _WinAPI_SetWindowLong($hBtn2, $GWL_WNDPROC, $pBtnMoveProc) GUISetState() While 1 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $idLockButtons _WinAPI_SetWindowLong($hBtn, $GWL_WNDPROC, (GUICtrlRead($iMsg) = $GUI_CHECKED) ? $pOrigBtnProc : $pBtnMoveProc) _WinAPI_SetWindowLong($hBtn2, $GWL_WNDPROC, (GUICtrlRead($iMsg) = $GUI_CHECKED) ? $pOrigBtnProc : $pBtnMoveProc) Case $idBtn, $idBtn2 ConsoleWrite("Click " & GUICtrlRead($iMsg) & @CRLF) EndSwitch WEnd Func ButtonMoveProc($hWnd, $uMsg, $wParam, $lParam) Local $aPos, $iRet, $aPoint[2], $iSrc, $iEvent Local $aRes = DllCallAddress("long", $pOrigBtnProc, "hwnd", $hWnd, "uint", $uMsg, "wparam", $wParam, "lparam", $lParam) Switch $uMsg Case $WM_NCHITTEST $aPos = WinGetPos($hWnd) $aPoint[0] = BitAND($lParam, 0xFFFF) $aPoint[1] = BitShift($lParam, 16) $iRet = $HTCAPTION If $aPoint[0] - $aPos[0] < 10 Then $iRet = $HTLEFT If $aPoint[0] - $aPos[0] > ($aPos[2] - 10) Then $iRet = $HTRIGHT If $aPoint[1] - $aPos[1] < 10 Then Switch $iRet Case $HTLEFT $iRet = $HTTOPLEFT Case $HTRIGHT $iRet = $HTTOPRIGHT Case Else $iRet = $HTTOP EndSwitch ElseIf $aPoint[1] - $aPos[1] > ($aPos[3] - 10) Then Switch $iRet Case $HTLEFT $iRet = $HTBOTTOMLEFT Case $HTRIGHT $iRet = $HTBOTTOMRIGHT Case Else $iRet = $HTBOTTOM EndSwitch EndIf Return $iRet Case $WM_SETCURSOR $iSrc = BitAND($lParam, 0xFFFF) $iEvent = BitShift($lParam, 16) If $iSrc = $HTCAPTION And $iEvent = $WM_LBUTTONDOWN Then _WinAPI_SetCursor($hCursor) Return True EndIf Case Else EndSwitch Return $aRes[0] ;~ Return _WinAPI_DefWindowProcW($hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>ButtonProc6 points
-
I needed a very fast x64 unsigned shift right, and doing it through an AutoIt array was way too slow. So I decided to make a .dll to perform such a task. While I was there, why not include all the bitwise operators that I know of. And then why not make a UDF. This is a bit like my wife does, she buys some draperies and then I end up repainting the whole room because the colors do not match anymore. Anyway, hope it can be useful for you too. Let me know if you have enhancements or comments, I will be glad to incorporate them (if possible). Version 2024-12-07 ASM * Code optimization (elimination of redundancy) Version 2024-12-06 ASM Func BitAND64 Func BitOR64 Func BitXOR64 Func BitSHIFT64 Func BitROTATE64 Func BitNOT64 Version 2020-04-27 DLL Func _BitAND64 Func _BitOR64 Func _BitXOR64 Func _BitEQV64 Func _BitIMP64 Func _BitSHIFT64 Func _BitROTATE64 Func _BitNOT64 Func _x64CloseDLL Version 2020-04-27 Util Func _Hex2Dec x64_Ops.zip6 points
-
AutoIt Snippets
seadoggie01 and 5 others reacted to Nine for a topic
Wonder how to have a progress in your window task bar, here you go : #include <GUIConstantsEx.au3> Global Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" Global Const $sIID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}" Global Const $tagITaskbarList3 = _ "HrInit hresult();" & _ "AddTab hresult(hwnd);" & _ "DeleteTab hresult(hwnd);" & _ "ActivateTab hresult(hwnd);" & _ "SetActiveAlt hresult(hwnd);" & _ "MarkFullscreenWindow hresult(hwnd;boolean);" & _ "SetProgressValue hresult(hwnd;uint64;uint64);" & _ "SetProgressState hresult(hwnd;int);" & _ "RegisterTab hresult(hwnd;hwnd);" & _ "UnregisterTab hresult(hwnd);" & _ "SetTabOrder hresult(hwnd;hwnd);" & _ "SetTabActive hresult(hwnd;hwnd;dword);" & _ "ThumbBarAddButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarUpdateButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarSetImageList hresult(hwnd;ptr);" & _ "SetOverlayIcon hresult(hwnd;ptr;wstr);" & _ "SetThumbnailTooltip hresult(hwnd;wstr);" & _ "SetThumbnailClip hresult(hwnd;ptr);" Example() Func Example() Local $hGUI = GUICreate("AutoIt v3", 400, 100) GUISetState() Local $oTaskBar = TB_Init() For $i = 1 To 100 TB_SetProgress($oTaskBar, $hGUI, $i, 100) Sleep(25) Next TB_Flash($oTaskBar, $hGUI, 4, 300) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>Example Func TB_Init() Local $oTB = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList3, $tagITaskbarList3) $oTB.HrInit() Return $oTB EndFunc ;==>TB_Init Func TB_SetProgress(ByRef $oTB, $hWnd, $iCurrent, $iCompleted) $oTB.SetProgressValue($hWnd, $iCurrent, $iCompleted) EndFunc ;==>TB_SetProgress Func TB_Flash(ByRef $oTB, $hWnd, $iTimes, $iDelay) For $i = 1 To $iTimes $oTB.SetProgressState($hWnd, 0) Sleep($iDelay) $oTB.SetProgressValue($hWnd, 100, 100) Sleep($iDelay) Next $oTB.SetProgressState($hWnd, 0) EndFunc ;==>TB_Flash6 points -
Hi, already fix for next beta/release6 points
-
Although I think the best way to use WebView2 in AutoIt would be to complete and use the work started by @LarsJ in this other @mLipok's topic, now it is possible to use WebView2 in AutoIt in a much simpler way. This is possible thanks to this ocx control and thanks to @Danyfirex for his decisive contribution. Now we can easily start embedding one or more WebView2 controls in our GUI in AutoIt. What we need is: the OrdoWebView2.ocx control and the \OrdoRC6 folder. These two are installed together with other programs (in the C:\Program Files (x86)\OrdoWebView2Control folder) by running the OrdoWebView2ActiveXControl.2.0.9.exe program downloadable from this link: https://freeware.ordoconcept.net/OrdoWebview2.php by clicking on "Download OrdoWebView2 SDK" at the bottom of the screen. Or, more simply, you can find them directly attached to this post by @Danyfirex. As explained in this post on VBForums (https://www.vbforums.com/showthread.php?899415-OrdoWebview2-ActiveX-WebView2-Browser-Control-(Replacement-of-the-MS-browser-control)&p=5651133&viewfull=1#post5651133): "On the latest versions of Windows 10 and Windows 11, only the following components are needed: OrdoWebView2.ocx OrdoRC6 folder and its contents, in the same directory as OrdoWebView2.ocx Finally, you need to register OrdoWebView2.ocx with regsvr32.exe OrdoWebView2.ocx". Also: Our AutoIt script and the OrdoWebView2.au3 must also be in the same directory along with the above. I have extracted the essential parts needed to create the WebView2 object from the DanyFirex's original example and grouped them into the OrdoWebView2.au3 UDF so that it can be easily included into a program. This is just a quick draft to get you started, but it can definitely be improved. Suggestions are welcome. Here are the basic UDF and a very basic example script: Embed 4 WebView2 controls in an AutoIt GUI More scripts to follow to test the functionality and interaction between OrdoWebView2 and AutoIt. See you later. P.S. Here is a reference link to the OrdoWebView2.ocx help (https://freeware.ordoconcept.net/Help/OrdoWebView2/) OrdoWebView2.au3 ; From the following POST By DanyFirex: ; https://www.autoitscript.com/forum/topic/204362-microsoft-edge-webview2-embed-web-code-in-your-native-application/page/9/#findComment-1542694 ; ... first draft to be continue ... #include <WinAPI.au3> Global Const $gATL = DllOpen("ATL.DLL") Global Const $gOleaut32 = DllOpen("oleaut32.dll") _WinAPI_CoInitialize($COINIT_APARTMENTTHREADED) AtlAxWinInit() Global $pProgID = SysAllocString('OrdoWebView2.OrdoWebView') Func webview2_GUI_Create($w, $h, $x, $y, $hMain, _ $sEventsPrefix = '', _ ; ......................... The prefix of the functions you define to handle receiving events. The prefix is appended by the Objects event name. $sLang = "", _ ; ................................. Language defined by the 2-letter code from ISO 639. If omitted, the chosen language will be that of the user's system. $bIsPrivateNavigation = False, _ ; ............... if TRUE the browser goes into private browsing mode. Default value is False $sBrowserInstallPath = "", _ ; ................... sets the installation directory of the WebView2 fixed version. Only considered if UseEdgeFixedVersion is TRUE. $sUserDataFolder = "", _ ; ....................... defines the user's browsing data directory. If empty, use default user assignment directory. Ignored if IsPrivateNavigation is true $sAdditionalBrowserArguments = "", _ ; ........... Allows passing parameters to the Chromium WebView2 browser through command line switches. You can find a list of Chromium Command Line Switches here $iAllowSingleSignOnUsingOSPrimaryAccount = 0) ; .. Determines whether to enable single sign on with Azure Active Directory Local $hGUI_1 = GUICreate('', $w, $h, $x, $y, $WS_POPUPWINDOW) ; BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN)) Local $hResult = AtlAxCreateControl($pProgID, $hGUI_1) ; _SysFreeString($pProgID) Local $pIUnkown = AtlAxGetControl($hGUI_1) ; ConsoleWrite("AtlAxGetControl: " & $pIUnkown & @CRLF) _WinAPI_SetParent($hGUI_1, $hMain) ; trap this child gui within the main gu GUISetState(@SW_SHOW, $hGUI_1) Local $oOrdoWebView2 = ObjCreateInterface($pIUnkown, "{E54909AA-1705-44A9-8235-B24F74366B3F}") Local $oOrdoWebViewEvents = ObjEvent($oOrdoWebView2, $sEventsPrefix, "__OrdoWebView") ; ConsoleWrite("$oOrdoWebView2: " & IsObj($oOrdoWebView2) & @CRLF) ; ConsoleWrite($oOrdoWebView2.GetWebView2Version() & @CRLF) ; ConsoleWrite($oOrdoWebView2.GetMostRecentInstallPath() & @CRLF) #cs $oOrdoWebView2.Anchor = True $oOrdoWebView2.Search_URL = "https://search.yahoo.com/search?p=%1" $oOrdoWebView2.HomeURL = "http://www.google.com" $oOrdoWebView2.SearchEngine = 2 $oOrdoWebView2.SearchAuto = True #ce $oOrdoWebView2.UseEdgeFixedVersion = False $oOrdoWebView2.InitEx($sLang, $bIsPrivateNavigation, $sBrowserInstallPath, $sUserDataFolder, $sAdditionalBrowserArguments, $iAllowSingleSignOnUsingOSPrimaryAccount) While Not $oOrdoWebView2.IsWebViewInit() ;wait initialization otherwise Navigate will fail Sleep(100) WEnd Local $aReturn = [$oOrdoWebView2, $hGUI_1] Return $aReturn ; $oOrdoWebView2 EndFunc ;==>webview2_GUI_Create Func AtlAxCreateControl($pProgID, $HWND) Local $aCall = DllCall($gATL, "long", "AtlAxCreateControl", "ptr", $pProgID, "handle", $HWND, "ptr", 0, "ptr", 0) If @error Then Return SetError(1, 0, -1) Return $aCall[0] EndFunc ;==>AtlAxCreateControl Func AtlAxGetControl($HWND) Local $aCall = DllCall($gATL, "long", "AtlAxGetControl", "handle", $HWND, "ptr*", 0) If @error Then Return SetError(1, 0, -1) Return $aCall[2] EndFunc ;==>AtlAxGetControl Func AtlAxWinInit() Local $aCall = DllCall($gATL, "bool", "AtlAxWinInit") If @error Then Return SetError(1, 0, -1) Return $aCall[0] EndFunc ;==>AtlAxWinInit Func _SysFreeString($pBSTR) ; Author: Prog@ndy If Not $pBSTR Then Return SetError(2, 0, 0) DllCall($gOleaut32, "none", "SysFreeString", "ptr", $pBSTR) If @error Then Return SetError(1, 0, 0) EndFunc ;==>_SysFreeString Func SysAllocString($str) ; Author: monoceres Local $aCall = DllCall($gOleaut32, "ptr", "SysAllocString", "wstr", $str) If @error Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc ;==>SysAllocString OrdoWebView2_Demo.au3 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "OrdoWebView2.au3" Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _TestOrdoWebView() Func _TestOrdoWebView() Local $hMain_GUI = GUICreate("Main GUI", 990, 810, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN)) GUISetState(@SW_SHOW, $hMain_GUI) Local $hAutoIt_Button_1 = GUICtrlCreateButton("test", 10, 785) ; Create 4 controls Local $aWebView1 = webview2_GUI_Create(480, 380, 10, 10, $hMain_GUI) Local $aWebView2 = webview2_GUI_Create(480, 380, 500, 10, $hMain_GUI) Local $aWebView3 = webview2_GUI_Create(480, 380, 10, 400, $hMain_GUI) Local $aWebView4 = webview2_GUI_Create(480, 380, 500, 400, $hMain_GUI) ; Navigate to web pages $aWebView1[0].Navigate("https://www.kevs3d.co.uk/dev/js1kdragons/") ; "http://www.3quarks.com/en/SegmentDisplay/" $aWebView2[0].Navigate("https://gridstackjs.com/demo/anijs.html") ; "https://retejs.org/") $aWebView3[0].Navigate("https://www.youtube.com/watch?v=ojBYW3ycVTE") $aWebView4[0].Navigate("https://freeware.ordoconcept.net/OrdoWebview2.php") ; "https://freeware.ordoconcept.net/Help/OrdoWebView2/" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hAutoIt_Button_1 MsgBox(0, 'AutoIt', 'Hi') EndSwitch WEnd _SysFreeString($pProgID) GUIDelete($aWebView1[1]) GUIDelete($aWebView2[1]) GUIDelete($aWebView3[1]) GUIDelete($aWebView4[1]) GUIDelete($hMain_GUI) EndFunc ;==>_TestOrdoWebView ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc5 points
-
I need from from time to time to run small processes to perform task that would otherwise clog the main process. Yes, there is a number of other UDF that could have done it very well, but I felt they were an over-kill for what I wanted. Don't throw me stones, I know it's not really multi-threading, but it is as close as I could get with simple AutoIt. If someone wonders why I called it PMT, the P stands for Pretending. And I'm also not pretending it is an elaborate UDF. Just small and simple to use... Version 2025-01-03 * changed how temporary files are deleted * changed location of temporary files to use standard folder * added support to unusual location of AutoIt Version 2025-01-02 * corrected bug when temporary files has space within their name. Version 2024-03-24 * corrected bug when 8 parameters (max) is passed to the function Example : #AutoIt3Wrapper_Res_SaveSource=y #include "PMT-UDF.AU3" #include <Constants.au3> _PMT_Init() Local $hProc1 = _PMT_Start("Test1", Default, "Test 1") _PMT_Start("Test2") _PMT_Start("Test3", 5) Local $sResponse While Sleep(50) $sResponse = _PMT_GetResponse($hProc1) If @error Then Exit MsgBox($MB_OK, "Error", "Process has dropped") If $sResponse <> "" Then MsgBox($MB_OK, "Success", $sResponse & @CRLF) ExitLoop EndIf WEnd Func Test1($sTitle, $sMessage) Local $iResp = MsgBox($MB_OK, $sTitle, $sMessage) Return "Done with value " & $iResp EndFunc Func Test2() MsgBox($MB_OK, "2", "Test 2") EndFunc Func Test3($iTimeout) MsgBox($MB_OK, "3", "Test 3", $iTimeout) EndFunc You can pass up to 8 parameters to _PMT_Start. It is up to you to manage the right number. You cannot pass structures, maps or arrays as parameter (only bool, ptr, hWnd, int, float, string, and the keyword Default). You could use my WCD-IPC if need be to exchange large amount of data. If you want to run it compiled, you need to have add #AutoIt3Wrapper_Res_SaveSource=y at the start of your script. In the case you decide to compile your script, _PMT_Init allows you to identity where AutoIt3 is located (in the situation where AutoIt is not installed in the usual directory) to get the right includes in your "threads". Let me know if you have any question, or suggestion, I will be glad to hear them. Enjoy. PMT-UDF.au35 points
-
Another AutoIt extension for Visual Studio Code
jaberwacky and 4 others reacted to genius257 for a topic
So another vscode extension for the AutoIt language emerges! I've tried the existing ones, and found small problems that i felt i could improve on, but it would require an entire new approach to the inner working of the existing extensions. Also working on a complete AutoIt3 parser a vscode extension just made sense Any feedback is appreciated, and i hope this project will benefit more than just me 🤡 Visual Studio Code Marketplace GitHub repo Some of the current features: Basic AutoIt2 syntax highlighting, for fun 🤡 AutoIt3 syntax highlighting Variable/Function hover gives declaration information if available. Goto declaration #include links Syntax checking, as you type Function signature help Function and variable list in a file via the outline tab. Works on desktop (any OS) and web version ⚠️ The parser used is not yet 100% complete (see issues for know problems), and the last thing to be implemented is the With code block. Hope you like 😃5 points -
This is a spin off the thread from here. I've moved this out of the collab space so I don't feel guilty about making sweeping changes when the mood hits me. But I'm still more than happy for this to be a community project at heart. Just a quick comment about the code: for this API, it looks like we need to construct some objects internally, which is a bit of a learning curve - but hopefully this example will provide a bit of background as to whats happening there... Original Attempt: Updated example 20/4 - Load media file, progress/seek bar. PlayerDemo 1.1.zip5 points
-
Hello friends, I haven't used AutoIt for a long time, but I always like these challenges, and I never forget you. Apparently there is some bug in how GUICtrlCreateObj works and I don't have time to look internally at the bug. This way I was able to create the instance of the object. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $gATL = DllOpen("ATL.DLL") Global Const $gOleaut32 = DllOpen("oleaut32.dll") Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _TestOrdoWebView() Func _TestOrdoWebView() ConsoleWrite("AtlAxWinInit: " & AtlAxWinInit() & @CRLF) Local $pProgID = SysAllocString('OrdoWebView2.OrdoWebView') ConsoleWrite("SysAllocString('OrdoWebView2.OrdoWebView'): " & $pProgID & @CRLF) Local $hGUI = GUICreate("OrdoWebView2.OrdoWebView Test", (@DesktopWidth) / 1.2, (@DesktopHeight) / 1.2, Default, Default, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN)) Local $hResult = AtlAxCreateControl($pProgID, $hGUI) _SysFreeString($pProgID) Local $pIUnkown = AtlAxGetControl($hGUI) ConsoleWrite("AtlAxGetControl: " & $pIUnkown & @CRLF) GUISetState() Local $oOrdoWebView2 = ObjCreateInterface($pIUnkown, "{E54909AA-1705-44A9-8235-B24F74366B3F}") Local $oOrdoWebViewEvents = ObjEvent($oOrdoWebView2, "_OrdoWebView_", "__OrdoWebView") ConsoleWrite("$oOrdoWebView2: " & IsObj($oOrdoWebView2) & @CRLF) ConsoleWrite($oOrdoWebView2.GetWebView2Version() & @CRLF) ConsoleWrite($oOrdoWebView2.GetMostRecentInstallPath() & @CRLF) $oOrdoWebView2.Anchor = True $oOrdoWebView2.Search_URL = "https://search.yahoo.com/search?p=%1" $oOrdoWebView2.HomeURL = "http://www.google.com" $oOrdoWebView2.SearchEngine = 2 $oOrdoWebView2.SearchAuto = True $oOrdoWebView2.Init() While Not $oOrdoWebView2.IsWebViewInit() ;wait initialization otherwise Navigate will fail Sleep(100) WEnd $oOrdoWebView2.Navigate("https://www.autoitscript.com/forum/topic/204362-microsoft-edge-webview2-embed-web-code-in-your-native-application/page/9/#findComment-1542505") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_TestOrdoWebView Func _OrdoWebView_InitComplete($oIEpDisp) ConsoleWrite("_OrdoWebView_InitComplete" & @CRLF) EndFunc ;==>_OrdoWebView_InitComplete Func AtlAxCreateControl($pProgID, $HWND) Local $aCall = DllCall($gATL, "long", "AtlAxCreateControl", "ptr", $pProgID, "handle", $HWND, "ptr", 0, "ptr", 0) If @error Then Return SetError(1, 0, -1) Return $aCall[0] EndFunc ;==>AtlAxCreateControl Func AtlAxGetControl($HWND) Local $aCall = DllCall($gATL, "long", "AtlAxGetControl", "handle", $HWND, "ptr*", 0) If @error Then Return SetError(1, 0, -1) Return $aCall[2] EndFunc ;==>AtlAxGetControl Func AtlAxWinInit() Local $aCall = DllCall($gATL, "bool", "AtlAxWinInit") If @error Then Return SetError(1, 0, -1) Return $aCall[0] EndFunc ;==>AtlAxWinInit Func _SysFreeString($pBSTR) ; Author: Prog@ndy If Not $pBSTR Then Return SetError(2, 0, 0) DllCall($gOleaut32, "none", "SysFreeString", "ptr", $pBSTR) If @error Then Return SetError(1, 0, 0) EndFunc ;==>_SysFreeString Func SysAllocString($str) ; Author: monoceres Local $aCall = DllCall($gOleaut32, "ptr", "SysAllocString", "wstr", $str) If @error Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc ;==>SysAllocString ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc Saludos5 points
-
Another AutoIt extension for Visual Studio Code
seadoggie01 and 4 others reacted to genius257 for a topic
Version 1.8.2 has just been released! I should have been 1.8.0, but issues with deployment pipeline after bigger changes to how the parser code and types are generated (internally) meant that i had to increment patch version 2 times, to successfully be able to release to the extension marketplaces. Notable changes: Added au3 DocBlock `@link` tag support Added syntax highlighting for au3 DocBlock and legacy UDF headers 2 things i would like feedback on, if possible: About the new syntax highlighting: Let me know if and/or how you like or dislike it. Performance: small changes to how the parser worked with some parser rules, to better generate types. Smaller tests indicated it was same or faster, but it can very much depend how it traverses through the code. Let me know if you notice any slow down, so I can look into fixing it ASAP! Feedback can be here, via an issue or via the discussion for the release.5 points -
BETA: SciTE v5x & lua Dynamic_include and "Smart" AutoComplete for Vars/UDFs/Abbrevs
argumentum and 4 others reacted to Jos for a topic
I am getting ready to publish a production update for SciTE4AutoI3, so have a SciTE4AutoIt3 v25.205.1420.0 release candidate ready and uploaded to Beta for those willing to test this installer before releasing it. Would appreciate hearing whether there are still issues with it as it has been a major overhaul since the last production version back in 2021. My main drives at this moment are to get the setup ready for better supporting Visual Studio Code as the default editor for AutoIt3, as I am convinced that there is an added benefit using VSC over SciTE. I have no intent to drop the SciTE upgrades, but do prefer to stop development & support of all the written LUA script functionalities. This is a list of the current changes at a high level: SciTE updated from v4.4.6 to v5.5.4 and includes both the x86 and x64 version selectable at install time Include the major LUA changes for Dynamic add Variables & Functions & #Include functionality. See here for details. This can be Simply disabled when old behavior is preferred by settings dynamic.include=n Utilities (Tidy.exe/au3Stripper/Au3check) can now process mixed encoded files and special characters in the filenames, so they do not require AutoIt3Wrappper anymore. The Included au3check v3.3.17.1 is an update of the standard latest au3check v3.3.16.1 included in the AutoIt3 installer. The new au3check now also supports mixed encoded files and special characters in the filenames and can be used without AutoIt3Wrapper for those cases. The installer will check the current version and replace it with this version when it is < v3.3.17.1. A copy of the old version will be made to AutoIt3\SciTE\Au3Check The installer will prompt for SciTE.exe x86 or x64 version Whether you want to change to VSCode as your default Editor for the "Edit" & "Open" options for AU3 files. What to do with Double Click, either Open or Run with AutoIt3. (also an option to change in SciTE Config) For those few that are currently using the Dynamic Beta version: There are a few minor changes since the last version published: AutoComplete #include lines wasn't working when dynamic.include=n was set. I have added the option to limited the number of entries shown in the AutoComplete dropdown to make it much more responsive when e.g. typing $a : # Define the max entries is a Variable/Func dropdown autocomplete list for speed reasons. autocomplete_dropdown_max=2005 points -
Visual Studio Code Extension currently available and future plans for SciTE?
seadoggie01 and 4 others reacted to Jos for a topic
Let's not make this topic more difficult than it is and stick for now to VSCode/SciTE. One can always decide to go down an alternative path later when VSCode is working.5 points -
BETA: SciTE v5x & lua Dynamic_include and "Smart" AutoComplete for Vars/UDFs/Abbrevs
BinaryBrother and 4 others reacted to Jos for a topic
Updated SciTE: Fixed UTF8 BOM detection.5 points -
RustDesk UDF
SOLVE-SMART and 4 others reacted to BinaryBrother for a topic
Here it is. ; #CURRENT# ===================================================================================================================== ; _RustDesk_Config ; _RustDesk_DebugEnable ; _RustDesk_Deploy ; _RustDesk_GenerateRandomPassword ; _RustDesk_GetID ; _RustDesk_GetLatestVersion ; _RustDesk_GetLocalVersion ; _TustDesk_isInstalled ; _RustDesk_SetPassword ; _RustDesk_Start ; =============================================================================================================================== Update: 1/10/25 - Added _RustDesk_Config() for those who need to configure a custom relay. Update: 1/23/25 - Overhauled some portions of the code with redundancy and timers. Update: 1/26/25 - Inched closer to UDF-Spec and added Constants. Update: 1/27/25 - Finished UDF-Spec Update: 2/4/2025 - Disregard nightly builds for the download. Current.zip5 points -
I modified one of my old script from 2014: ;Coded by UEZ #include <GUIConstantsEx.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global Const $hGUI = GUICreate("GDI+ Test", 200, 100) GUISetBkColor(0x505050) Global Const $iPicBtn = GUICtrlCreatePic("", 50, 28, 100, 44) Global $aButtons = _GDIPlus_BitmapCreateRoundedButtonAndText("install", 100, 44) _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) GUISetState() Global $aMouseInfo, $bShow = False, $bHide = False Do If WinActive($hGUI) Then $aMouseInfo = GUIGetCursorInfo($hGUI) ;hover simulation Switch $aMouseInfo[4] Case $iPicBtn _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[1])) $bShow = True $bHide = False Case Else _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) $bHide = True $bShow = False EndSwitch EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($aButtons[0]) _WinAPI_DeleteObject($aButtons[1]) _GDIPlus_Shutdown() Exit Case $iPicBtn MsgBox(0, "Information", "Button pressed") EndSwitch Until False ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_BitmapCreateRoundedButtonAndText ; Description ...: Draw rounded button ; Syntax ........: _GDIPlus_BitmapCreateRoundedButtonAndText($sString, $iWidth, $iHeight[, $iBgColor = 0xFF1BA0E1[, $iFontSize = 16[, $sFont = "Times New Roman"[, ; $iHoverColor = 0xFFC9388C[, $iFrameSize = 2[, $iFontFrameColor = 0x408AD5EA[, $iFontColor = 0xFFFFFFFF]]]]]]) ; Parameters ....: $sString - A string value. ; $iWidth - An integer value. ; $iHeight - An integer value. ; $iBgColor - [optional] An integer value. Default is 0xFF1BA0E1. ; $iFontSize - [optional] An integer value. Default is 16. ; $sFont - [optional] A string value. Default is "Times New Roman". ; $iHoverColor - [optional] An integer value. Default is 0xFFC9388C. ; $iFrameSize - [optional] An integer value. Default is 2. ; $iFontFrameColor - [optional] An integer value. Default is 0x408AD5EA. ; $iFontColor - [optional] An integer value. Default is 0xFFFFFFFF. ; Return values .: an array with 2 GDI bitmap handles -> [0]: default button, [1]: hover button ; Author ........: UEZ ; Version .......: 0.85 build 2025-01-12 ; Modified ......: ; Remarks .......: Dispose returned GDI bitmap handles when done ; Example .......: Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateRoundedButtonAndText($sString, $iWidth, $iHeight, $iBgColor = 0xFF1BA0E1, $iFontSize = 16, $sFont = "Times New Roman", $iHoverColor = 0xF0FFFFFF, $iFrameSize = 2, $iFontFrameColor = 0x408AD5EA, $iFontColor = 0xFFFFFFFF) ;some checks If $sString = "" Then Return SetError(1, 0, 0) If Int($iWidth) < $iFrameSize * 2 Then Return SetError(2, 0, 0) If Int($iHeight) < $iFrameSize * 2 Then Return SetError(3, 0, 0) ;create font objects Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight) _GDIPlus_StringFormatSetAlign($hFormat, 1) ;center string on X axis _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ;center string on Y axis ;create bitmap and graphics context handles Local Const $aBitmaps[2] = [_GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)] Local Const $aGfxCtxt[2] = [_GDIPlus_ImageGetGraphicsContext($aBitmaps[0]), _GDIPlus_ImageGetGraphicsContext($aBitmaps[1])] ;set drawing quality _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt[0], $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt[1], $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($aGfxCtxt[0], $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT) ;define brush and pen objects Local Const $hBrushFontColor = _GDIPlus_BrushCreateSolid($iFontColor) ;, $hBrushBGColor = _GDIPlus_BrushCreateSolid($iBgColor) Local Const $hPenFontFrameColor = _GDIPlus_PenCreate($iFontFrameColor, $iFrameSize), $hPenHoverColor = _GDIPlus_PenCreate($iHoverColor, $iFrameSize) ;create path object Local Const $hPath = _GDIPlus_PathCreate() ;create cloned path object for string measurement Local Const $hPath_Dummy = _GDIPlus_PathClone($hPath) _GDIPlus_PathAddString($hPath_Dummy, $sString, $tLayout, $hFamily, 0, $iFontSize, $hFormat) _GDIPlus_PathStartFigure($hPath) Local $fArcSize = $iWidth * 0.33333 _GDIPlus_PathAddArc($hPath, $iFrameSize, $iHeight - $fArcSize - $iFrameSize, $fArcSize, $fArcSize, 180, -90) ;BR _GDIPlus_PathAddArc($hPath, $iWidth - $fArcSize - $iFrameSize, $iHeight - $fArcSize - $iFrameSize, $fArcSize, $fArcSize, -270, -90) ;BL _GDIPlus_PathAddArc($hPath, $iWidth - $fArcSize - $iFrameSize, $iFrameSize, $fArcSize, $fArcSize, 0, -90) ;TR _GDIPlus_PathAddArc($hPath, $iFrameSize, $iFrameSize, $fArcSize, $fArcSize, -90, -90) ;TL _GDIPlus_PathCloseFigure($hPath) Local Const $hPath_Clone = _GDIPlus_PathClone($hPath) Local Const $hBrushBGColor = _GDIPlus_PathBrushCreateFromPath($hPath) _GDIPlus_PathBrushSetSurroundColor($hBrushBGColor, $iBgColor) _GDIPlus_PathBrushSetCenterColor($hBrushBGColor, 0xFFFFFFFF) _GDIPlus_PathBrushSetCenterPoint($hBrushBGColor, $iWidth / 2, $iHeight / 2) _GDIPlus_PathBrushSetSigmaBlend($hBrushBGColor, 1, 0.33333) _GDIPlus_GraphicsFillPath($aGfxCtxt[0], $hPath, $hBrushBGColor) _GDIPlus_GraphicsDrawPath($aGfxCtxt[0], $hPath, $hPenFontFrameColor) _GDIPlus_PathReset($hPath) ;add string to path _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 1, $iFontSize, $hFormat) ;clear bitmap and draw string _GDIPlus_GraphicsFillPath($aGfxCtxt[0], $hPath, $hBrushFontColor) _GDIPlus_GraphicsDrawPath($aGfxCtxt[0], $hPath, $hPenFontFrameColor) ;draw rectangle on cloned bitmap for hover effect _GDIPlus_GraphicsDrawImageRect($aGfxCtxt[1], $aBitmaps[0], 0, 0, $iWidth, $iHeight) _GDIPlus_GraphicsDrawPath($aGfxCtxt[1], $hPath_Clone, $hPenHoverColor) ;dispose object resources _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PathDispose($hPath) _GDIPlus_PathDispose($hPath_Dummy) _GDIPlus_PathDispose($hPath_Clone) _GDIPlus_GraphicsDispose($aGfxCtxt[0]) _GDIPlus_GraphicsDispose($aGfxCtxt[1]) _GDIPlus_BrushDispose($hBrushFontColor) _GDIPlus_BrushDispose($hBrushBGColor) _GDIPlus_PenDispose($hPenFontFrameColor) _GDIPlus_PenDispose($hPenHoverColor) ;create GDI bitmap for later usage Local $aHBitmaps[2] = [_GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[0]), _GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[1])] ;dispose GDI+ bitmaps _GDIPlus_BitmapDispose($aBitmaps[0]) _GDIPlus_BitmapDispose($aBitmaps[1]) Return $aHBitmaps EndFunc ;==>_GDIPlus_BitmapCreateRoundedButtonAndText5 points
-
WMCDIPC ( x32/x64, user/admin, self triggering, slow WM_COPYDATA IPC )
Musashi and 4 others reacted to argumentum for a topic
The example: The UDFish: The back story: I put together "Win 11 - My own border color" and looking at the logs I've found that I had a handle leak. The leak got fixed but I wanted ( out of OCD ? ) to have the script report on it's status. Ok, easy enough, I'll IPC the request. But I don't wanna have it in the main loop, constantly asking "are we there yet ?, are we there yet ?, ..." . I could not find a copy'n'paste UDF, that did that I wanted to have, so I had to code it 🥲 Now you can copy'n'paste it How does it work: When WM_COPYDATA gets a message, it puts the data in a global array that gets accessed by any user function triggered by AdlibRegister() after X mSec. You can set the AdlibRegister() time with WMCDIPC_AdlibTime(). Without a parameter it will return the current value. Can set the user function with WMCDIPC_AdlibFunc()**. Without a parameter it will return the current value. The UDF has notes that will hint it's use. Hope you find it useful. Edit: This is v2.0 ( yey ! ) ** there now is a WMCDIPC_AdlibRegister(func,time) that can do that too. This version allows running all Au3Stripper arguments, so that's good. Added WMCDIPC_PrintCallback() to handle the one line of debug in the UDF. Also added a return in case the script is already busy running in Adlib, therefore unable to process the IPC request right there and then. The int return is "0xFADE" and the string has how many mSec it's been busy. Giving the user a chance to know it "FADEd away" and formulate a resend or what not. Since is a new version, added WMCDIPC_Version(), just in case of a future one. But all in all, I think that this UDF is complete and needs no other functionality for the scenario it would be used at. Edit: This is v2.1 ( wow ! ) Added in the loop. Why ?. Well, the project that I wrote this for is GUIOnEventMode=1. Having the "are we there yet ?" is much slower given that a long Sleep() is common in that option. But the example I posted is GUIOnEventMode=0. It does use GUIGetMsg() to handle messages and CPU usage so, why not have the trigger right there. So that's what I added in this version. And obviously responds much faster than scheduling an Adlib. Edit: ..and this is v2.1.1 ( child proofing ? ) I was thinking that it would be nice to tell, the new to this UDF, that a set of choices would not work ( not as extreme as in MsgBox_Extn() but, something ). Also to run ControlViewer just in case of an "oops". where you can select a script, press DEL, and process close it, if something went wrong. ( and I use it a lot ) So there: for all those that should be sleeping at 3 AM but want to code and screw up, because the brain is sleeping regardless of will.5 points -
Found a copy of 1.4 thanks to SMF 😋 in my archive drive at the location "E:\__code\TB_TurboBooster\Workbench\_testcode\FontViewer_source.zip" 🙄. Updated that too to 3.3.16.1, here's a copy of that plus the original code FontViewer_1.4.zip Additionally fixed a bug in the enumeration of the system fonts. ; $hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, StringTrimLeft($REG_KEY_TRUETYPE, 5)) ; needs to be $hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, StringTrimLeft($REG_KEY_TRUETYPE, 5),BitOR($KEY_QUERY_VALUE , $KEY_WOW64_32KEY))5 points
-
Here is a very simple example using the method described earlier by argumentum. Note the use of static variables. Doing it that way prevents the need to define those variables as Global. The example script sets up Ctrl+w and Ctrl+j as hotkeys to show how the method can be used for multiple hotkeys. The payload in each hotkey function will only execute if the hotkey is fired twice within the specified time, which in this case is 500 milliseconds (.5 seconds). Press ESC to exit the example. #include <Constants.au3> #include <Misc.au3> ;Declare constants Const $DOUBLE_CLICK_TIME = 500 ;Declare global vars Global $ghUserDll = DllOpen("user32.dll"), _ $ghCtrlWTimer = TimerInit(), _ $ghCtrlJTimer = TimerInit() ;Set hotkey(s) HotKeySet("^w", do_ctrl_w) HotKeySet("^j", do_ctrl_j) ;Loop until ESC pressed While 1 If _IsPressed("1B", $ghUserDll) then ExitLoop WEnd ;========================================================================== ; These hotkey functions only do something if called twice within a ; specified time ($DOUBLE_CLICK_TIME) ;========================================================================== Func do_ctrl_w() ;Declare vars Static $iPrevTime = 0 Local $iCurrTime = TimerDiff($ghCtrlWTimer) ;If function called twice within specified time If $iCurrTime < ($iPrevTime + $DOUBLE_CLICK_TIME) Then ;Do something MsgBox($MB_ICONINFORMATION, "INFO", "CTRL+W double click occurred.") ;Reset timer $ghCtrlWTimer = TimerInit() EndIf ;Reset previous Time to current time $iPrevTime = TimerDiff($ghCtrlWTimer) EndFunc Func do_ctrl_j() ;Declare vars Static $iPrevTime = 0 Local $iCurrTime = TimerDiff($ghCtrlJTimer) ;If function called twice within specified time If $iCurrTime < ($iPrevTime + $DOUBLE_CLICK_TIME) Then ;Do something MsgBox($MB_ICONINFORMATION, "INFO", "CTRL+J double click occurred.") ;Reset timer $ghCtrlJTimer = TimerInit() EndIf ;Reset previous Time to current time $iPrevTime = TimerDiff($ghCtrlJTimer) EndFunc5 points
-
i found solution here (Thanks to LarsJ ) https://www.autoitscript.com/forum/topic/205154-using-objcreateinterface-and-objectfromtag-functions/ Methods/properties of the description tag string must be in correct Vtable order. (I learned what Vtable is) ; https://www.autoitscript.com/forum/topic/212211-solved-setthumbnailtooltip #include <GUIConstantsEx.au3> $hGUI = GUICreate("AutoIt v3", 400, 100) GUISetState() _SetThumbnailTooltip($hGUI, "AutoIt v3" & @CRLF & "including a line breaker" & @CRLF & "in gui ThumbnailTooltip") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) Func _SetThumbnailTooltip($hWnd, $sText) ; Declare the CLSID, IID, and interface description for ITaskbarList3. Local Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" Local Const $sIID_ITaskbarList3 = "{ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf}" Local Const $sTagITaskbarList3 = "HrInit hresult();" & _ "AddTab hresult(hwnd);" & _ "DeleteTab hresult(hwnd);" & _ "ActivateTab hresult(hwnd);" & _ "SetActiveAlt hresult(hwnd);" & _ "MarkFullscreenWindow hresult(hwnd;boolean);" & _ "SetProgressValue hresult(hwnd;uint64;uint64);" & _ "SetProgressState hresult(hwnd;int);" & _ "RegisterTab hresult(hwnd;hwnd);" & _ "UnregisterTab hresult(hwnd);" & _ "SetTabOrder hresult(hwnd;hwnd);" & _ "SetTabActive hresult(hwnd;hwnd;dword);" & _ "ThumbBarAddButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarUpdateButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarSetImageList hresult(hwnd;ptr);" & _ "SetOverlayIcon hresult(hwnd;ptr;wstr);" & _ "SetThumbnailTooltip hresult(hwnd;wstr);" & _ "SetThumbnailClip hresult(hwnd;ptr);" ; Create the object. Local $oTB = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList3, $sTagITaskbarList3) ; Initialize the iTaskbarList3 object. $oTB.HrInit() ; Attempt to set the tooltip for the taskbar thumbnail $oTB.SetThumbnailTooltip($hWnd, $sText) EndFunc ;==>_SetThumbnailTooltip5 points
-
Menu possible without submenus?
ioa747 and 4 others reacted to pixelsearch for a topic
@Melba23 & @Nine Deleting the menu control seems to do the job. It will position to the very left of the GUI all existing menuitem(s) control(s) . Does this work for you ? #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $Form1 = GUICreate("Form1", 615, 437, 192, 124) $mDummymenu = GUICtrlCreateMenu("this menu control will be deleted") $menu1 = GUICtrlCreateMenuItem("click me", -1) $menu2 = GUICtrlCreateMenuItem("click me again", -1) GUICtrlDelete($mDummymenu) ; <====================== GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $menu1 MsgBox($MB_TOPMOST ,'yes!', 'it works') Case $menu2 MsgBox($MB_TOPMOST,'yes!', 'it works again') EndSwitch WEnd5 points -
Ok we're back with a new stuff in post #1. You'll first need to compile "playerDemo_engine.au3", then run "playerDemo.au3". We're still using a modal to block execution in the engine script - wish we could do something nicer, but I guess it'll have to do for now. For comms between processes we're using windows messages (thanks nine for the inspiration!). Look for the $WM_ME* values in the constants file. The WM codes are the same values as those generated by the mediaengine, combined with WM_APP. There's one totally "made up" code - its for MediaEngine to send through its window handle to the UI process ($WM_ME_PLAYBACKWINDOW). Also with the WMs, there's a bit of jiggery pokey in order to pass floating point values over wparam and lparam. I found if you send values as a float or double, they pop out as an integer on the other end - so you lose everything after the decimal point. But sending the values as binary solves this. We just need to ensure we convert our "doubles" to "floats" for x86 so the values fit within wparam/lparam. One last thing... you can still crash the engine by flooding it with messages from the UI, but that's where we're at for now. We could probably fix this by only check incoming messages from within the event handler... Then the problem is the engine won't be contactable when its paused, so you'd need to flick between two modes of checking for messages. And it would also require a total rethink of how to pass comms from the UI back to the engine!4 points
-
JSON UDF using JSON-C
argumentum and 3 others reacted to TheXman for a topic
4 points -
Just uploaded SciTEx86.zip & SciTEx64.zip which contain the Latest SciTE 5.5.6 versions released April 2, 2025, for those that like to use the latest version of SciTE Full. This will also be part of the final update of SciTE4AutoIt3.4 points
-
Smooth and infinite marquee style scroll of a long string in a short control
pixelsearch and 3 others reacted to Gianni for a topic
If you want the text scrolling to continue even when you drag the GUI or even when an MsgBox() is in action, you can use _WinAPI_SetTimer instead of AdlibRegister, as in this slightly modified version of your script. ... But if you don't care, then forget it ... #include <GUIConstants.au3> #include <WinAPISysWin.au3> $guiWidth = 300 $hGUI = GUICreate("Main GUI", $guiWidth, 70) $sString = "This is a long string that scrolls smoothly and infinitely in a short label control." ; Create a child GUI for scrolling label $iMargin = 10 $sGap = " " $iLabelWidth = $guiWidth - $iMargin * 2 $hChildGUI = GUICreate("", $iLabelWidth, 20, 10, 10, $WS_CHILD, -1, $hGUI) GUISetFont(12, 400, 0, "Arial") ; Create a label wide enough to hold a long string without truncation $idLabel = GUICtrlCreateLabel($sString, 0, 0, 2000, 20, BitOR($SS_NOPREFIX, $SS_LEFTNOWORDWRAP)) ; Get the string width $tmpLabel = GUICtrlCreateLabel($sString, 0, 0, -1, 20, BitOR($SS_NOPREFIX, $SS_LEFTNOWORDWRAP)) $iStringWidth = ControlGetPos($hChildGUI, "", $tmpLabel)[2] - 9 ; Label is wider than the string width by 9 pixels GUICtrlDelete($tmpLabel) GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOW, $hChildGUI) ; Update the label data if the string width is larger than the label width If $iStringWidth > $iLabelWidth Then GUICtrlSetData($idLabel, $sString & $sGap & $sString) $iScrollPos = 0 $iMarquee = 0 $iScrollDelay = 40 ; AdlibRegister("_Marquee", $iScrollDelay) ; -- setup timer-- Local $hTimerProc = DllCallbackRegister('_Marquee', 'none', 'hwnd;uint;uint_ptr;dword') Local $iTimerID = _WinAPI_SetTimer(0, 0, $iScrollDelay, DllCallbackGetPtr($hTimerProc)) ; ---------------- EndIf MsgBox(64, "Info", "text scrolls") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; -- clean timer-- _WinAPI_KillTimer(0, $iTimerID) DllCallbackFree($hTimerProc) ; ---------------- Func _Marquee($hWnd, $iMsg, $iTimerID, $iTime) #forceref $hWnd, $iMsg, $iTimerID, $iTime $iMarquee += 1 If $iMarquee < 3000 / $iScrollDelay Then Return ; 3 seconds of halt when $sString comes to the initial position $iScrollPos -= 1 If - $iScrollPos = $iStringWidth + StringLen($sGap) * 4 Then ; Initialize the $idLabel's position $iMarquee = 0 $iScrollPos = 0 EndIf GUICtrlSetPos($idLabel, $iScrollPos, 0) EndFunc ;==>_Marquee4 points -
MessageBox higher than Desktop
Musashi and 3 others reacted to pixelsearch for a topic
Hi everybody This script displays a big MessageBox having a height higher than @DesktopHeight While the MessageBox is displayed, you can "navigate" inside it like this : * Mouse Left-click drag : to move the window up and down (displaying a new panel of lines) * Mouse Right-click : to display the window at its initial position * Up key * Down key * PageUp Key (Fn + up key on some laptops) * PageDown Key (Fn + down key on some laptops) * Home Key (Fn + left key on some laptops) * End Key (Fn + right key on some laptops) The 6 keyboard keys allow to navigate inside the window. Click on a button (placed at top of the window) to make your choice. All this could have been scripted more easily using a GUI, an Edit control containing the text to display, plus the buttons to choose from, but I just wanted to try it using a native MessageBox #include <APISysConstants.au3> ; $GCL_HCURSOR #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WinAPIRes.au3> ; _WinAPI_LoadCursor() #include <WinAPISysWin.au3> ; _WinAPI_SetClassLongEx() #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Opt("GUICloseOnESC", 0) ;1=ESC closes (default), 0=ESC won't close Global $g_hGUI, $g_hDLL = DllOpen("user32.dll") Global $g_aCaption, $g_sTitle Example() ;=========================================== Func Example() $g_hGUI = GUICreate("Big MsgBox example (7b)", 400, 200) GUICtrlCreateLabel("Number of lines in MsgBox (2 - 1588)", 10, 20, 180, 20, $SS_SUNKEN) Local $idNbLines = GUICtrlCreateInput("200", 200, 20, 35, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)), $iNbLines GUICtrlSetLimit($idNbLines, 4) Local $idMsgBox = GUICtrlCreateButton("Big MsgBox", 10, 60, 100, 25, $BS_DEFPUSHBUTTON) Local $idExit = GUICtrlCreateButton("Exit", 10, 110, 100, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idExit ExitLoop Case $idMsgBox Local $iRet = Prepare_MsgBox(GUICtrlRead($idNbLines)) If $iRet Then MsgBox($MB_TOPMOST, "Big MsgBox return value : " & $iRet, Retrieve_Caption($iRet), 0, $g_hGUI) GUICtrlSetState($idNbLines, $GUI_FOCUS) EndSwitch WEnd DllClose($g_hDLL) EndFunc ;==>Example ;=========================================== Func Prepare_MsgBox(Const $iNbLines) If $iNbLines < 2 Or $iNbLines > 1588 Then MsgBox($MB_TOPMOST, "Error", "Enter a number of lines between 2 and 1588", 0, $g_hGUI) Return ; 0 EndIf Local $sTxt = "Line 1 : first line" & @crlf For $i = 2 To $iNbLines - 1 $sTxt &= "Line " & $i & @crlf Next $sTxt &= "Line " & $iNbLines & " : last line" Dim $g_aCaption[3][3] = [ ["Cancel"], ["Try Again"], ["Continue"] ] ; 1st column = button caption, 2nd = button handle, 3rd = button ID $g_sTitle = "MsgBox with 3 buttons" Local $iChoice = _MsgBox(BitOr($MB_CANCELTRYCONTINUE, $MB_TOPMOST), $g_sTitle, $sTxt, 0, $g_hGUI) ;~ Dim $g_aCaption[2][3] = [ ["Yes"], ["No"] ] ;~ $g_sTitle = "MsgBox with 2 buttons" ;~ Local $iChoice = _MsgBox(BitOr($MB_YESNO, $MB_TOPMOST), $g_sTitle, $sTxt, 0, $g_hGUI) ;~ Dim $g_aCaption[1][3] = [ ["Hello"] ] ;~ $g_sTitle = "MsgBox with 1 button" ;~ Local $iChoice = _MsgBox(BitOr($MB_OK, $MB_TOPMOST), $g_sTitle, $sTxt, 0, $g_hGUI) Return $iChoice EndFunc ;==>Prepare_MsgBox ;=========================================== Func _MsgBox($iFlag, $g_sTitle, $sText, $iTimeOut = 0, $hWnd = 0) GUIRegisterMsg($WM_HELP , "WM_HELP") Local $hTimerProc = DllCallbackRegister('_MsgBoxTimerProc', 'none', 'hwnd;uint;uint_ptr;dword') Local $iTimerID = _WinAPI_SetTimer(0, 0, 10, DllCallbackGetPtr($hTimerProc)) Local $iChoice = MsgBox($iFlag, $g_sTitle, $sText, $iTimeOut, $hWnd) _WinAPI_KillTimer(0, $iTimerID) DllCallbackFree($hTimerProc) GUIRegisterMsg($WM_HELP, "") Return $iChoice EndFunc ;==>_MsgBox ;=========================================== Func _MsgBoxTimerProc($hWnd, $iMsg, $iTimerID, $iTime) If WinExists($g_sTitle) Then _WinAPI_KillTimer(0, $iTimerID) Local $hMsgBox = WinGetHandle($g_sTitle) For $i = 0 To Ubound($g_aCaption) - 1 ControlSetText($hMsgBox, "", "Button" & ($i + 1), $g_aCaption[$i][0]) $g_aCaption[$i][1] = ControlGetHandle($hMsgBox, "", "Button" & ($i + 1)) $g_aCaption[$i][2] = _WinAPI_GetDlgCtrlID($g_aCaption[$i][1]) ; remember OK button ID is 1 ($MB_OKCANCEL) or 2 ($MB_OK) ... ; ... msdn "If a message box has a Cancel button, the function returns the IDCANCEL value (2) if either the ESC key is pressed ; or the Cancel button is selected." ; "If the message box has no Cancel button, pressing ESC will no effect - unless an MB_OK button is present. ; If an MB_OK button is displayed and the user presses ESC, the return value will be IDOK (1)" [personal: only one case for this] Next Local $aPosMsgBox = WinGetPos($hMsgBox) Local $bTooHigh = ($aPosMsgBox[3] > @DesktopHeight + 15) ? True : False If $bTooHigh Then Local $aPosButton, $aPosStatic = ControlGetPos($hMsgBox, "", "Static1") ; the text area For $i = 0 To Ubound($g_aCaption) - 1 $aPosButton = ControlGetPos($hMsgBox, "", "Button" & ($i + 1)) WinMove($g_aCaption[$i][1], "", $aPosButton[0], $aPosStatic[1]) Next WinMove(ControlGetHandle($hMsgBox, "", "Static1"), "", $aPosStatic[0], $aPosStatic[1] + $aPosButton[3] + 10) _WinAPI_RedrawWindow($hMsgBox) ; +++ Send("{F1}") ; => Func WM_HELP EndIf EndIf EndFunc ;==>_MsgBoxTimerProc ;============================================== Func WM_HELP($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam If WinExists($g_sTitle) Then ; MessageBox window always exists at this stage Local $hMsgBox = WinGetHandle($g_sTitle) Local $aPosMsgBox = WinGetPos($hMsgBox), $aPosMsgBox_Init = $aPosMsgBox Local $aWinPos, $aMPos, $aMPosOld Local $hCursor = _WinAPI_LoadCursor(0, $OCR_SIZEALL) ; $OCR_SIZENS ok too Local $iPrev = _WinAPI_SetClassLongEx($hMsgBox, $GCL_HCURSOR, $hCursor) ; see "147c.au3" _ClearBuffer("0D") ; Enter key (in case pressed too long on button 'Big MsgBox' in main GUI, so it won't select a button in MsgBox) While 1 If WinActive($hMsgBox) Then Select Case _IsPressed("01", $g_hDLL) ; "01" = Left mouse button $aMPosOld = MouseGetPos() While _IsPressed("01", $g_hDLL) $aMPos = MouseGetPos() If $aMPos[1] <> $aMPosOld[1] Then $aWinpos = WinGetPos($hMsgBox) If ($aMPos[0] - 1 > $aWinpos[0]) And ($aMPos[0] + 1 < $aWinpos[0] + $aWinpos[2]) Then WinMove($hMsgBox, "", Default, $aWinpos[1] + ($aMPos[1] - $aMPosOld[1])) $aMPosOld = $aMPos EndIf EndIf Sleep(10) Wend Case _IsPressed("02", $g_hDLL) ; Right mouse button WinMove($hMsgBox, "", $aPosMsgBox_Init[0], $aPosMsgBox_Init[1]) Case _IsPressed("09", $g_hDLL) ; Tab key _ClearBuffer("09") _ChangeFocus($hMsgBox, "09") Case _IsPressed("0D", $g_hDLL) ; Enter key _ClearBuffer("0D") ControlClick($hMsgBox, "", ControlGetFocus($hMsgBox)) Case _IsPressed("1B", $g_hDLL) ; Esc key _ClearBuffer("1B") For $i = 0 To Ubound($g_aCaption) - 1 If $g_aCaption[$i][2] = 2 Then ; Cancel button (or OK button when alone : see msdn notes above) ControlClick($hMsgBox, "", $g_aCaption[$i][2]) EndIf Next Case _IsPressed("21", $g_hDLL) ; PageUp Key (Fn + up key on most laptops) _ClearBuffer("21") $aPosMsgBox = WinGetPos($hMsgBox) WinMove( $hMsgBox, "", Default, ($aPosMsgBox[1] + @DesktopHeight > 0) ? 0 : $aPosMsgBox[1] + @DesktopHeight ) Case _IsPressed("22", $g_hDLL) ; PageDown Key (Fn + down key on most laptops) _ClearBuffer("22") $aPosMsgBox = WinGetPos($hMsgBox) WinMove( $hMsgBox, "", Default, _ ($aPosMsgBox[3] + $aPosMsgBox[1] - @DesktopHeight < @DesktopHeight + 15) ? @DesktopHeight - $aPosMsgBox[3] : $aPosMsgBox[1] - @DesktopHeight ) Case _IsPressed("23", $g_hDLL) ; End Key (Fn + right key on most laptops) $aPosMsgBox = WinGetPos($hMsgBox) WinMove($hMsgBox, "", Default, @DesktopHeight - $aPosMsgBox[3]) Case _IsPressed("24", $g_hDLL) ; Home Key (Fn + left key on most laptops) WinMove($hMsgBox, "", Default, 0) Case _IsPressed("25", $g_hDLL) ; Left key _ClearBuffer("25") _ChangeFocus($hMsgBox, "25") Case _IsPressed("26", $g_hDLL) ; Up Key $aPosMsgBox = WinGetPos($hMsgBox) WinMove($hMsgBox, "", Default, ($aPosMsgBox[1] + 12 > 0) ? 0 : $aPosMsgBox[1] + 12) Case _IsPressed("27", $g_hDLL) ; Right key _ClearBuffer("27") _ChangeFocus($hMsgBox, "27") Case _IsPressed("28", $g_hDLL) ; Down Key $aPosMsgBox = WinGetPos($hMsgBox) WinMove( $hMsgBox, "", Default, _ ($aPosMsgBox[3] + $aPosMsgBox[1] - 12 < @DesktopHeight) ? @DesktopHeight - $aPosMsgBox[3] : $aPosMsgBox[1] - 12 ) EndSelect EndIf If Not BitAND(WinGetState($hMsgBox), $WIN_STATE_VISIBLE) Then ; one of MsgBox buttons was chosen by user ExitLoop EndIf Sleep(10) WEnd _WinAPI_SetClassLongEx($hMsgBox, $GCL_HCURSOR, $iPrev) ; needed, or cursor $OCR_SIZEALL will show... in final MsgBox from main loop EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_HELP ;============================================== Func _ClearBuffer($sKey) While _IsPressed($sKey, $g_hDLL) Sleep(10) Wend EndFunc ;==>_ClearBuffer ;============================================== Func _ChangeFocus($hMsgBox, $sKey) Local $iCtrlGetFocus, $iCtrlSetFocus, $iStyle $iCtrlGetFocus = StringRight(ControlGetFocus($hMsgBox), 1) ; 1/2/3 (last char of "Button1"/"Button2"/"Button3") If $sKey = "27" Or $sKey = "09" Then ; Right key (27) or Tab (09) $iCtrlSetFocus = $iCtrlGetFocus < Ubound($g_aCaption) ? $iCtrlGetFocus + 1 : 1 Else ; Left key (25) $iCtrlSetFocus = $iCtrlGetFocus > 1 ? $iCtrlGetFocus - 1 : Ubound($g_aCaption) EndIf ControlFocus($hMsgBox, "", "Button" & $iCtrlSetFocus) $iStyle = _WinAPI_GetWindowLong($g_aCaption[$iCtrlGetFocus - 1][1], $GWL_STYLE) _WinAPI_SetWindowLong($g_aCaption[$iCtrlGetFocus - 1][1], $GWL_STYLE, BitXOR($iStyle, $BS_DEFPUSHBUTTON)) $iStyle = _WinAPI_GetWindowLong($g_aCaption[$iCtrlSetFocus - 1][1], $GWL_STYLE) _WinAPI_SetWindowLong($g_aCaption[$iCtrlSetFocus - 1][1], $GWL_STYLE, BitOR($iStyle, $BS_DEFPUSHBUTTON)) EndFunc ;==>_ChangeFocus ;=========================================== Func Retrieve_Caption($iRet) If Ubound($g_aCaption) = 1 Then ; $MB_OK Return $g_aCaption[0][0] Else For $i = 0 To Ubound($g_aCaption) - 1 If $g_aCaption[$i][2] = $iRet Then Return $g_aCaption[$i][0] ; button ID always = $iRet (except for $MB_OK, see note msdn above) Next EndIf MsgBox($MB_TOPMOST, "Warning", "This message should never be displayed", 0, $g_hGUI) EndFunc ;==>Retrieve_Caption Update Feb 24, 2025 : Left key, Right key, Tab, Enter, Spacebar, Esc These 6 keys react now like they do in any MsgBox Feb 27, 2025 : minor correction4 points -
I guess I'm mixing too many different program languages these days, so goofed up pretty much with that last version. Anyway, it should be fixed with the latest Beta installer containing an update for AutoIt3Wrapper v25.205.1420.2 ... and did test properly this time.4 points
-
I did originally use the Damien.autoit extension in vscode myself, and found issues I wanted to fix via pull requests. But after looking at the usage of regular expression and the reliance on AutoIt executables (nothing wrong with that as such, I mean it works), I wanted to try a entirely different approach. I started implementing my own extension after I experienced inconsistent behavior from the Damien.autoit version. For example: sometimes the suggestions did not work as expected, with no error messages. I was also working on a AutoIt parser in Pegjs grammer syntax (now Peggyjs) and saw it as the perfect opportunity for testing it's capabilities. My extension does not depend on any files from AutoIt installations, and therefore works in web (test here: https://vscode.dev/) and on on non windows environments, like Linux (I use Ubuntu from time to time). The Damien.autoit extension uses regular expressions to parse the file (for completions and such), where I use my parser as mentioned before. My extension also runs via LSP, Damien.autoit does not. There are also small differences like incorrect syntax highlighting for nested comments on the Damien.autoit extension (this issue can be fixed by looking at my tmLanguage implementation). Try this between the two extensions as an example: #cs #cs #cs #ce #ce #ce $a To be clear I am not saying my extension is superior. My extension is currently slower at parsing scripts, the parser i am using/developing is in active development and incomplete (with code blocks are currently not implemented) and since I don't use AutoIt executables for error checking there is currenly little to no error checking, besides the syntax check (and recently error messages for include statements that fail to resolve). This also means that to run AutoIt scripts with my extension, a secondary extension is needed (https://marketplace.visualstudio.com/items?itemName=genius257.autoit3-debug) My extension is also made to move towards what I want for the AutoIt development experience. This means support for a new, more standardized doc-block way of documenting function and variable declarations. The standard UDF documentation format is supported for backwards compatibility, but is currently not great, and will only ever be implemented by me to "good enough" standard. I am unsure what you mean by "azure" dependencies? The only azure i am using that i know of, is for auto deploying to vscode extension marketplace and Open VSX Registry automatically, when a new release is created on GitHub, via GitHub actions?4 points
-
[SOLVED] - help, add right click option on header of active file/window/program
pixelsearch and 3 others reacted to ioa747 for a topic
Here's a script that does it with the Ctrl + Win + T hotkey. #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_Res_ProductName=WinTogleOnTop.au3 #AutoIt3Wrapper_Res_Description=Togle Window OnTop with 'Ctrl + Win + T' #AutoIt3Wrapper_Res_Fileversion=0.0.0.1 #AutoIt3Wrapper_Icon=WinTogleOnTop.ICO #include <WindowsConstants.au3> #include <WinAPISys.au3> TraySetIcon("WinTogleOnTop.ico") Opt("TrayAutoPause", 0) Global $g_ActWnd HotKeySet("#^t", "Cmd_WinTogleOnTop") ; Ctrl + Win + T" & @CRLF ;********************************** While Sleep(50) _GetActiveWindow() WEnd ;********************************** ;---------------------------------------------------------------------------------------- Func _GetActiveWindow() Local $AnyWindow = WinGetHandle("[ACTIVE]") If $g_ActWnd <> $AnyWindow Then $g_ActWnd = $AnyWindow ;ConsoleWrite("$g_ActWnd=" & $g_ActWnd & "; " & WinGetTitle($g_ActWnd) & @CRLF) EndIf EndFunc ;==>_GetActiveWindow ;---------------------------------------------------------------------------------------- Func Cmd_WinTogleOnTop() Local $iStyle = _WinAPI_GetWindowLong($g_ActWnd, $GWL_EXSTYLE) Local $iStyleTopMost = BitOR($iStyle, $WS_EX_TOPMOST) Local $aWPos = WinGetPos($g_ActWnd) If $iStyle = $iStyleTopMost Then WinSetOnTop($g_ActWnd, "", 0) ToolTip(" ", $aWPos[0], $aWPos[1], "Normal", 1) Else WinSetOnTop($g_ActWnd, "", 1) ToolTip(" ", $aWPos[0], $aWPos[1], "On top", 3) EndIf Sleep(1000) ToolTip("") EndFunc ;==>Cmd_WinTogleOnTop ;----------------------------------------------------------------------------------------4 points -
WinActiveBorder()
Danyfirex and 3 others reacted to argumentum for a topic
4 points -
Cheers Gianni AutoIt x64 was having trouble - So if anyone uses that by default, here's the same code with the DllCalls swapped out for inbult _GDIPlus_* funcs. ; source ; https://autoit.de/thread/17855-led-laufschrift/ ; ; reference for this script (by Eukalyptus): ; https://autoit.de/thread/17855-led-laufschrift/?postID=140164#post140164 #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIPlusConstants.au3> ; #include "LEDTXT.au3" ; (by Eukalyptus) already embedded here below Local $sText1 = "Hello friends! ☺ best wishes for a happy holiday and a happy new year (me)" Local $sText2 = "Let us greet together this new year that ages our friendship without aging our hearts. (Victor Hugo)" Local $sText3 = "The best time to plant a tree was 20 years ago. The second best time is now. (Chinese proverb)" Local $sText4 = "The future belongs to those who believe in the beauty of their dreams. (Eleanor Roosevelt)" Local $sText5 = "In the end, what matters is not the years of your life, but the life you put into those years. (Abraham Lincoln)" HotKeySet("{ESC}", "_Exit") _GDIPlus_Startup() $hGuiTrans = GUICreate("", @DesktopWidth, 300, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) GUISetBkColor(0xABCDEF) _WinAPI_SetLayeredWindowAttributes($hGuiTrans, 0xABCDEF) GUISetState() $hGui = GUICreate("", @DesktopWidth, 400, 0, 300, Default, $WS_EX_TOPMOST) ; WinSetTrans($hGui, "", 100) GUISetState() #cs parameters info: $hGui: Handle to the window $sText: The text $iX: X position of the scrolling text $iY: Y position $iW: Length $iH: Height $iType: Appearance of the LEDs 0=Round with 3D effect, 1=Square with 3D, 2=Round, 3=Square; (the last two are filled and/or outlined, depending on which colors are <>0) $iLedW = X-size of an LED $iLedH = Y-size of an LED $nLedOnCol1 = Color 1 of the ON LEDs (foreground for 3D, fill color for $iType 2 and 3) $nLedOnCol2 = Color 2 of the ON LEDs (background for 3D, color of the outline for $iType 2 and 3) $nLedOffCol1 = Color 1 of the OFF LEDs $nLedOffCol2 = Color 2 of the OFF LEDs $nBkColor = Background color $iDistW = X-distance of the LEDs $iDistH = Y-distance of the LEDs $sFont = Font $iTextSize = Font size $iTextOpt = Font options (see _GDIPlus_FontCreate ) $iTextOffY = Y offset of the font #ce $aLed1 = _LEDTXT_Create_Gdi($hGuiTrans, $sText1, 0, 0, @DesktopWidth, 50, 0, 2, 2, 0xFFFFAA00, 0xFF000000, 0xAA111122, 0xAA000000, 0, 0, 0, "Courier New", 40, 1) $aLed2 = _LEDTXT_Create_Gdi($hGuiTrans, $sText2, 0, 50, @DesktopWidth, 50, 3, 2, 2, 0, 0xFF0088FF, 0, 0xFF000000, 0, 0, 0, "Arial", 40, 1) $aLed3 = _LEDTXT_Create_Gdi($hGuiTrans, $sText3, 0, 100, @DesktopWidth, 100, 1, 4, 4, 0xFFFF0000, 0xFF000000, 0, 0, 0xFFABCDEF, 1, 1, "Times New Roman", 80, 1) $aLed4 = _LEDTXT_Create_Gdi($hGuiTrans, $sText4, 0, 200, @DesktopWidth, 100, 1, 4, 4, 0xFF00FF00, 0xFF000000, 0xFFABCDEF, 0xFFABCDEF, 0xFFABCDEF, 0, 0, "Arial", 80, 1) $aLed5 = _LEDTXT_Create_Gdi($hGui, $sText5, 0, 0, @DesktopWidth, 350, 0, 14, 14, 0xFF00FF00, 0xFF00AA00, 0x44111119, 0x4400EE00, 0x44000000, 0, 0, "Arial", 410, 1, -60) GUIRegisterMsg($WM_ERASEBKGND, "_WM_ERASEBKGND") While 1 _LEDTXT_Step($aLed1, 1) _LEDTXT_Step($aLed2, -1) _LEDTXT_Step($aLed3, 1) _LEDTXT_Step($aLed4, -1) _LEDTXT_Step($aLed5, 1) _WinAPI_RedrawWindow($hGuiTrans, 0, 0, 5) _WinAPI_RedrawWindow($hGui, 0, 0, 5) Sleep(10) WEnd Func _WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam) Switch $hWnd Case $hGuiTrans _LEDTXT_Draw($aLed1) _LEDTXT_Draw($aLed2) _LEDTXT_Draw($aLed3) _LEDTXT_Draw($aLed4) Case $hGui _LEDTXT_Draw($aLed5) EndSwitch Return True EndFunc ;==>_WM_ERASEBKGND Func _Exit() _LEDTXT_Destroy($aLed1) _LEDTXT_Destroy($aLed2) _LEDTXT_Destroy($aLed3) _LEDTXT_Destroy($aLed4) _LEDTXT_Destroy($aLed5) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit ; =============================== ; LEDTXT.au3 (by Eukalyptus) ; =============================== Func _LEDTXT_Step(ByRef $aLed, $iDir = 1) $aLed[6] -= $aLed[8] * $iDir Select Case $aLed[6] + $aLed[7] < 0 $aLed[6] = 0 Case $aLed[6] > 0 $aLed[6] = -$aLed[7] EndSelect EndFunc ;==>_LEDTXT_Step Func _LEDTXT_Draw($aLed) Local $iPos = Round($aLed[6]) - Mod(Round($aLed[6]), $aLed[8]) Switch $aLed[10] Case True Switch $iPos Case -$aLed[7] To -$aLed[7] + $aLed[4] _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], -$iPos, 0, $iPos + $aLed[7], $aLed[5], $aLed[2], $aLed[3], $iPos + $aLed[7], $aLed[5]) If $aLed[6] + $aLed[7] < $aLed[4] Then _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], 0, 0, $aLed[4] - ($iPos + $aLed[7]), $aLed[5], $aLed[2] + $iPos + $aLed[7], $aLed[3], $aLed[4] - ($iPos + $aLed[7]), $aLed[5]) Case Else _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], -$iPos, 0, $aLed[4], $aLed[5], $aLed[2], $aLed[3], $aLed[4], $aLed[5]) EndSwitch Case Else Switch $iPos Case -$aLed[7] To -$aLed[7] + $aLed[4] _WinAPI_BitBlt($aLed[0], $aLed[2], $aLed[3], $aLed[2] + $iPos + $aLed[7], $aLed[5], $aLed[1], -$iPos, 0, $MERGECOPY) If $aLed[6] + $aLed[7] < $aLed[4] Then _WinAPI_BitBlt($aLed[0], $aLed[2] + $iPos + $aLed[7], $aLed[3], $aLed[4] - ($iPos + $aLed[7]), $aLed[5], $aLed[1], 0, 0, $MERGECOPY) Case Else _WinAPI_BitBlt($aLed[0], $aLed[2], $aLed[3], $aLed[4], $aLed[5], $aLed[1], -$iPos, 0, $MERGECOPY) EndSwitch EndSwitch EndFunc ;==>_LEDTXT_Draw Func _LEDTXT_Create_GdiPlus($hGui, $sText, $iX, $iY, $iW, $iH, $iType, $iLedW = 8, $iLedH = 8, $nLedOnCol1 = 0xFFFFAA00, $nLedOnCol2 = 0xFF000000, $nLedOffCol1 = 0xAA111122, $nLedOffCol2 = 0xAA000000, $nBkColor = 0xFF000000, $iDistW = 0, $iDistH = 0, $sFont = "Arial", $iTextSize = 0, $iTextOpt = 1, $iTextOffY = 0) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) Local $hLedOn = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOnCol1, $nLedOnCol2) Local $hLedOff = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOffCol1, $nLedOffCol2) Local $hLed, $iWidth $hLed = _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, $iWidth) Local $aReturn[11] $aReturn[0] = $hGraphics $aReturn[1] = $hLed $aReturn[2] = $iX $aReturn[3] = $iY $aReturn[4] = $iW $aReturn[5] = $iH $aReturn[6] = 0 $aReturn[7] = $iWidth $aReturn[8] = $iLedW + $iDistW $aReturn[9] = 0 $aReturn[10] = True ; True = _GdiPlus, False=_WinApi Return $aReturn EndFunc ;==>_LEDTXT_Create_GdiPlus Func _LEDTXT_Create_Gdi($hGui, $sText, $iX, $iY, $iW, $iH, $iType, $iLedW = 8, $iLedH = 8, $nLedOnCol1 = 0xFFFFAA00, $nLedOnCol2 = 0xFF000000, $nLedOffCol1 = 0xAA111122, $nLedOffCol2 = 0xAA000000, $nBkColor = 0xFF000000, $iDistW = 0, $iDistH = 0, $sFont = "Arial", $iTextSize = 0, $iTextOpt = 1, $iTextOffY = 0) Local $bGdiStarted = True If Not $__g_hGDIPDll Then $bGdiStarted = False _GDIPlus_Startup() EndIf Local $hDC = _WinAPI_GetDC($hGui) Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC) Local $hLedOn = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOnCol1, $nLedOnCol2) Local $hLedOff = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOffCol1, $nLedOffCol2) Local $hLed, $iWidth $hLed = _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, $iWidth) Local $hBmpDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hLed) _WinAPI_SelectObject($hBmpDC, $hBmp) Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hLed) Local $aReturn[11] $aReturn[0] = $hDC $aReturn[1] = $hBmpDC $aReturn[2] = $iX $aReturn[3] = $iY $aReturn[4] = $iW $aReturn[5] = $iH $aReturn[6] = 0 $aReturn[7] = $iWidth $aReturn[8] = $iLedW + $iDistW $aReturn[9] = $hBmp ; zum späteren destroy?! $aReturn[10] = False ; True = _GdiPlus, False=_WinApi _GDIPlus_GraphicsDispose($hGraphics) If Not $bGdiStarted Then _GDIPlus_Shutdown() Return $aReturn EndFunc ;==>_LEDTXT_Create_Gdi Func _LEDTXT_Destroy($aLed) Switch $aLed[10] Case True _GDIPlus_BitmapDispose($aLed[1]) _GDIPlus_GraphicsDispose($aLed[0]) Case Else _WinAPI_DeleteObject($aLed[9]) _WinAPI_ReleaseDC(0, $aLed[1]) _WinAPI_DeleteDC($aLed[0]) EndSwitch EndFunc ;==>_LEDTXT_Destroy Func _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, ByRef $iReturnW) $sText = StringReplace($sText, @LF, "") $iW -= Mod($iW, $iLedW + $iDistW) If Not $iTextSize Then $iTextSize = $iH Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iTextSize, $iTextOpt, 2) Local $tLayout = _GDIPlus_RectFCreate($iW, 0, 0, 0) Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat) Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width")) + $iW $iWidth -= Mod($iWidth, $iLedW + $iDistW) Local $iHeight = $iH ;Ceiling(DllStructGetData($aInfo[0], "Height")) DllStructSetData($aInfo[0], "Y", $iTextOffY) Local $hBmpTxt = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics) Local $hBmpLed = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics) Local $hBmpTmp = _GDIPlus_BitmapCreateFromGraphics($iLedW, $iHeight, $hGraphics) Local $hGfxTxt = _GDIPlus_ImageGetGraphicsContext($hBmpTxt) Local $hGfxLed = _GDIPlus_ImageGetGraphicsContext($hBmpLed) Local $hGfxTmp = _GDIPlus_ImageGetGraphicsContext($hBmpTmp) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) _GDIPlus_GraphicsClear($hGfxTxt, 0xFF000000) If $nBkColor Then _GDIPlus_GraphicsClear($hGfxLed, $nBkColor) _GDIPlus_GraphicsDrawStringEx($hGfxTxt, $sText, $hFont, $aInfo[0], $hFormat, $hBrush) Local $BitmapData = _GDIPlus_BitmapLockBits($hBmpTxt, $iW, 0, $iWidth - $iW, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local $Stride = DllStructGetData($BitmapData, "Stride") Local $Width = DllStructGetData($BitmapData, "Width") Local $Height = DllStructGetData($BitmapData, "Height") Local $Scan0 = DllStructGetData($BitmapData, "Scan0") Local $PixelData = DllStructCreate("ubyte lData[" & (Abs($Stride) * $Height - 1) & "]", $Scan0) If $hLedOff Then For $i = 0 To $Height - 1 Step $iLedH + $iDistH _GDIPlus_GraphicsDrawImage($hGfxTmp, $hLedOff, 0, $i) Next For $i = 0 To $iW - 1 Step $iLedW + $iDistW _GDIPlus_GraphicsDrawImage($hGfxLed, $hBmpTmp, $i, 0) Next EndIf For $col = 0 To $Width - 1 Step $iLedW + $iDistW If $hLedOff Then _GDIPlus_GraphicsDrawImage($hGfxLed, $hBmpTmp, $col + $iW, 0) For $row = 0 To $Height - 1 Step $iLedH + $iDistH If DllStructGetData($PixelData, 1, $row * $Stride + ($col * 4) + 1) Then _GDIPlus_GraphicsDrawImage($hGfxLed, $hLedOn, $col + $iW, $row) Next Next _GDIPlus_BitmapUnlockBits($hBmpTxt, $BitmapData) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BitmapDispose($hBmpTxt) _GDIPlus_GraphicsDispose($hGfxTxt) _GDIPlus_BitmapDispose($hBmpTmp) _GDIPlus_GraphicsDispose($hGfxTmp) _GDIPlus_GraphicsDispose($hGfxLed) $iReturnW = $iWidth Return $hBmpLed EndFunc ;==>_LEDTXT_Create_Bmp Func _LEDTXT_Create_Led($hGraphics, $iType, $iWidth, $iHeight, $nColor1, $nColor2) If Not $nColor1 And Not $nColor2 Then Return 0 Local $hBmp = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $hGraphics) Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp) Switch $iType Case 0 Local $hPen = _GDIPlus_PenCreate() Local $hPath = _GDIPlus_PathCreate() _GDIPlus_PathAddEllipse($hPath, 0, 0, $iWidth, $iHeight) Local $hBrushGrad = _GDIPlus_PathBrushCreateFromPath($hPath) _GDIPlus_PathBrushSetGammaCorrection($hBrushGrad, True) Local $aColors[2] = [1, $nColor2] _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrushGrad, $aColors) _GDIPlus_PathBrushSetCenterColor($hBrushGrad, $nColor1) _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrushGrad) _GDIPlus_PathCloseFigure($hPath) _GDIPlus_GraphicsDrawEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrushGrad) _GDIPlus_PathDispose($hPath) Case 1 Local $hPen = _GDIPlus_PenCreate() Local $hPath = _GDIPlus_PathCreate() _GDIPlus_PathAddRectangle($hPath, 0, 0, $iWidth, $iHeight) Local $hBrushGrad = _GDIPlus_PathBrushCreateFromPath($hPath) _GDIPlus_PathBrushSetGammaCorrection($hBrushGrad, True) Local $aColors[2] = [1, $nColor2] _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrushGrad, $aColors) _GDIPlus_PathBrushSetCenterColor($hBrushGrad, $nColor1) _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrushGrad) _GDIPlus_PathCloseFigure($hPath) _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrushGrad) _GDIPlus_PathDispose($hPath) Case 2 If $nColor1 Then Local $hBrush = _GDIPlus_BrushCreateSolid($nColor1) _GDIPlus_GraphicsFillEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hBrush) _GDIPlus_BrushDispose($hBrush) EndIf If $nColor2 Then Local $hPen = _GDIPlus_PenCreate($nColor2) _GDIPlus_GraphicsDrawEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) EndIf Case 3 If $nColor1 Then Local $hBrush = _GDIPlus_BrushCreateSolid($nColor1) _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $iWidth, $iHeight, $hBrush) _GDIPlus_BrushDispose($hBrush) EndIf If $nColor2 Then Local $hPen = _GDIPlus_PenCreate($nColor2) _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iWidth, $iHeight, $hPen) _GDIPlus_PenDispose($hPen) EndIf EndSwitch _GDIPlus_GraphicsDispose($hGfx) Return $hBmp EndFunc ;==>_LEDTXT_Create_Led4 points
-
transparent movable windows with drop shadow
argumentum and 3 others reacted to Nine for a topic
Here my take on it : #include <WinAPISys.au3> #include <GDIPlus.au3> #include <GuiConstants.au3> Opt("MustDeclareVars", True) Global $hGUI, $hGUI2, $hGUI3 Example() Func Example() _GDIPlus_Startup() $hGUI = GUICreateEx("main.png", 100, 100) $hGUI2 = GUICreateEx("item.png", 150, 400, $hGUI) $hGUI3 = GUICreateEx("item.png", 400, 400, $hGUI) GUIRegisterMsg($WM_NCHITTEST, WM_NCHITTEST) GUIRegisterMsg($WM_MOUSELEAVE, WM_MOUSELEAVE) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GDIPlus_Shutdown() EndFunc ;==>Example Func GUICreateEx($sImage, $iPosX = -1, $iPosY = -1, $hParent = 0) Local $hImage = _GDIPlus_ImageLoadFromFile($sImage) Local $hWnd = GUICreate("", -1, -1, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $hParent ? $WS_EX_MDICHILD : 0), $hParent) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_UpdateLayeredWindowEx($hWnd, -1, -1, $hBitmap) _WinAPI_DeleteObject($hBitmap) _GDIPlus_ImageDispose($hImage) GUISetState() Return $hWnd EndFunc ;==>GUICreateEx Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case $hGUI Return $HTCAPTION Case $hGUI2 ConsoleWrite("hovering GUI2" & @CRLF) Case $hGUI3 ConsoleWrite("hovering GUI3" & @CRLF) EndSwitch _WinAPI_TrackMouseEvent($hWnd, $TME_LEAVE) EndFunc ;==>WM_NCHITTEST Func WM_MOUSELEAVE($hWnd, $msg, $wParam, $lParam) ConsoleWrite("leaving " & $hWnd & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSELEAVE Func GUIUpdate($sImage, $hWnd) Local $hImage = _GDIPlus_ImageLoadFromFile($sImage) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_UpdateLayeredWindowEx($hWnd, -1, -1, $hBitmap) _WinAPI_DeleteObject($hBitmap) _GDIPlus_ImageDispose($hImage) EndFunc ;==>GUIUpdate4 points -
transparent movable windows with drop shadow
Musashi and 3 others reacted to pixelsearch for a topic
@Nine does this work for you ? ; SetBitmap($hGUI, $hImage, 255) _WinAPI_UpdateLayeredWindowEx($hGUI, -1, -1, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)) If it works, then we shouldn't need Function SetBitmap() and its 18 lines.4 points -
Just uploaded SciTEx86.zip & SciTEx64.zip which contain the Latest SciTE 5.5.3 versions released 9 October 2024.4 points
-
Version 1.6.1 has just been released! The function snippet, now uses "func" instead of "fun" for the string prefix. Variables declared via for loops are now recognized by the extension. include statements that fail to resolve, should no longer have links added to them. Sorry for the slow release. Personal things, combined with my vscode and docker that keeps crashing due to running out of memory, have delayed this release by at least a month. 😕 Anyway, i am currently looking into: adding errors for things like include statements that fail to resolve. improving the function signature helper (currently it disappears if the parser fails on that line, like when adding a comma within the parentheses, but there is nothing between the comma and the closing parenthesis) adding setting for omitting included functions and variables with the "__" prefix from the completion suggestions.4 points
-
AutoIt Snippets
Andreik and 3 others reacted to seadoggie01 for a topic
Expanding on Nine's task bar adventures... The overlay icon and tooltip were the only other interesting task bar things to me, so I added those + examples #include <GUIConstantsEx.au3> #include <WinAPIIcons.au3> ; For _WinAPI_DestroyIcon #include <WinAPIShellEx.au3> ; For _WinAPI_ShellExtractIcon Global Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" Global Const $sIID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}" Global Const $tagITaskbarList3 = _ "HrInit hresult();" & _ "AddTab hresult(hwnd);" & _ "DeleteTab hresult(hwnd);" & _ "ActivateTab hresult(hwnd);" & _ "SetActiveAlt hresult(hwnd);" & _ "MarkFullscreenWindow hresult(hwnd;boolean);" & _ "SetProgressValue hresult(hwnd;uint64;uint64);" & _ "SetProgressState hresult(hwnd;int);" & _ "RegisterTab hresult(hwnd;hwnd);" & _ "UnregisterTab hresult(hwnd);" & _ "SetTabOrder hresult(hwnd;hwnd);" & _ "SetTabActive hresult(hwnd;hwnd;dword);" & _ "ThumbBarAddButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarUpdateButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarSetImageList hresult(hwnd;ptr);" & _ "SetOverlayIcon hresult(hwnd;ptr;wstr);" & _ "SetThumbnailTooltip hresult(hwnd;wstr);" & _ "SetThumbnailClip hresult(hwnd;ptr);" Example() Func Example() Local $hGUI = GUICreate("AutoIt v3", 400, 100) GUISetState() Local $oTaskBar = TB_Init() TB_ToolTip($oTaskBar, $hGUI, "Working...") ; Load an icon -- this is a blue refresh on Win11 Local $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & "\shell32.dll", 238, 32, 32) TB_SetOverlayIcon($oTaskBar, $hGUI, $hIcon, "Blue refresh") For $i = 1 To 100 TB_SetProgress($oTaskBar, $hGUI, $i, 100) Sleep(25) Next ; Destroy the old icon _WinAPI_DestroyIcon($hIcon) Local $hSecondIcon = _WinAPI_ShellExtractIcon(@SystemDir & "\shell32.dll", 300, 32, 32) TB_SetOverlayIcon($oTaskBar, $hGUI, $hSecondIcon, "Green checkmark") TB_Flash($oTaskBar, $hGUI, 4, 300) TB_ToolTip($oTaskBar, $hGUI, "Waiting for you to close the window") While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Clear the icon overlay TB_SetOverlayIcon($oTaskBar, $hGUI, Null) _WinAPI_DestroyIcon($hSecondIcon) EndFunc ;==>Example Func TB_Init() Local $oTB = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList3, $tagITaskbarList3) $oTB.HrInit() Return $oTB EndFunc ;==>TB_Init Func TB_SetProgress(ByRef $oTB, $hWnd, $iCurrent, $iCompleted) $oTB.SetProgressValue($hWnd, $iCurrent, $iCompleted) EndFunc ;==>TB_SetProgress Func TB_Flash(ByRef $oTB, $hWnd, $iTimes, $iDelay) For $i = 1 To $iTimes $oTB.SetProgressState($hWnd, 0) Sleep($iDelay) $oTB.SetProgressValue($hWnd, 100, 100) Sleep($iDelay) Next $oTB.SetProgressState($hWnd, 0) EndFunc ;==>TB_Flash ; These are icons added to your taskbar icon, showing status usually. Each window only gets 1. Set $hIcon to NULL to clear. ; (Win11) Teams uses this to show your status (busy, free, inactive) and Outlook uses it to show if you have an unread email Func TB_SetOverlayIcon(ByRef $oTB, $hWnd, $hIcon, $sAltText = "") $oTB.SetOverlayIcon($hWnd, $hIcon, $sAltText) EndFunc ;==>TB_SetOverlayIcon ; Depending on settings and version, this may be difficult to see. On Win11 with taskbar previews, it is only visible after hovering over the preview window. Func TB_ToolTip(ByRef $oTB, $hWnd, $sTooltip) $oTB.SetThumbnailTooltip($hWnd, $sTooltip) EndFunc ;==>TB_ToolTip4 points -
4 points
-
Or a full interface version : #include <Constants.au3> Opt("MustDeclareVars", True) Interface() Func Interface() Local Const $sTagIDispatch = _ "GetTypeInfoCount hresult(dword*);" & _ "GetTypeInfo hresult(dword;dword;ptr*);" & _ "GetIDsOfNames hresult(struct*;struct*;dword;dword;struct*);" & _ "Invoke hresult(uint;struct*;dword;word;struct*;struct*;ptr;uint*);" Local Const $sCLSID_NetworkListManager = "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}" Local Const $sIID_INetworkListManager = "{DCB00000-570F-4A9B-8D69-199FDBA5723B}" Local Const $sTag_INetworkListManager = $sTagIDispatch & _ "GetNetworks hresult(int;ptr*);" & _ "GetNetwork hresult(ptr;ptr*)" & _ "GetNetworkConnections hresult(ptr*);" & _ "GetNetworkConnection hresult(ptr;ptr*);" & _ "IsConnectedToInternet hresult(short*);" & _ "IsConnected hresult(short*);" & _ "GetConnectivity hresult(int_ptr*);" & _ "SetSimulatedProfileInfo hresult(struct*);" & _ "ClearSimulatedProfileInfo hresult();" Local Const $sIID_IEnumNetworkConnections = "{DCB00006-570F-4A9B-8D69-199FDBA5723B}" Local Const $sTag_IEnumNetworkConnections = $sTagIDispatch & _ "NewEnum hresult(ptr*);" & _ "Next hresult(int;ptr*;int*);" & _ "Skip hresult(int);" & _ "Reset hresult();" & _ "Clone hresult(ptr*);" Local Enum $NLM_CONNECTIVITY_DISCONNECTED, $NLM_CONNECTIVITY_IPV4_NOTRAFFIC, $NLM_CONNECTIVITY_IPV6_NOTRAFFIC, _ $NLM_CONNECTIVITY_IPV4_SUBNET = 0x10, $NLM_CONNECTIVITY_IPV4_LOCALNETWORK = 0x20, $NLM_CONNECTIVITY_IPV4_INTERNET = 0x40, _ $NLM_CONNECTIVITY_IPV6_SUBNET = 0x100, $NLM_CONNECTIVITY_IPV6_LOCALNETWORK = 0x200, $NLM_CONNECTIVITY_IPV6_INTERNET = 0x400 Local Const $sIID_INetworkConnection = "{DCB00005-570F-4A9B-8D69-199FDBA5723B}" Local Const $sTag_INetworkConnection = $sTagIDispatch & _ "GetNetwork hresult(ptr*)" & _ "IsConnectedToInternet hresult(boolean*);" & _ "IsConnected hresult(boolean*);" & _ "GetConnectivity hresult(int*);" & _ "GetConnectionId hresult(clsid*);" & _ "GetAdapterId hresult(clsid*);" & _ "GetDomainType hresult(int*);" Local Enum $NLM_NETWORK_CATEGORY_PUBLIC, $NLM_NETWORK_CATEGORY_PRIVATE, $NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED Local Const $sIID_INetwork = "{DCB00002-570F-4A9B-8D69-199FDBA5723B}" Local Const $sTag_INetwork = $sTagIDispatch & _ "GetName hresult(wstr*);" & _ "SetName hresult(wstr);" & _ "GetDescription hresult(wstr*);" & _ "SetDescription hresult(wstr);" & _ "GetNetworkId hresult(clsid*);" & _ "GetDomainType hresult(int*);" & _ "GetNetworkConnections hresult(ptr*);" & _ "GetTimeCreatedAndConnected hresult(int*;int*;int*;int*);" & _ "IsConnectedToInternet hresult(boolean*);" & _ "IsConnected hresult(boolean*);" & _ "GetConnectivity hresult(int*);" & _ "GetCategory hresult(int*);" & _ "SetCategory hresult(int);" Local $pNWCs, $iNum, $pConn, $oNWC, $sGUID, $pNet, $oNet, $sName Local $oNLM_INetworkListManager = ObjCreateInterface($sCLSID_NetworkListManager, $sIID_INetworkListManager, $sTag_INetworkListManager) If Not IsObj($oNLM_INetworkListManager) Then Exit MsgBox($MB_OK, "Error", "INetworkListManager") $oNLM_INetworkListManager.GetNetworkConnections($pNWCs) Local $oNWCs = ObjCreateInterface($pNWCs, $sIID_IEnumNetworkConnections, $sTag_IEnumNetworkConnections) If Not IsObj($oNWCs) Then Exit MsgBox($MB_OK, "Error", "IEnumNetworkConnections") While True $oNWCs.Next(1, $pConn, $iNum) If Not $iNum Then ExitLoop $oNWC = ObjCreateInterface($pConn, $sIID_INetworkConnection, $sTag_INetworkConnection) If Not IsObj($oNWC) Then Exit MsgBox($MB_OK, "Error", "INetworkConnection") $oNWC.GetAdapterId($sGUID) ConsoleWrite("GetAdapterId: " & $sGUID & @CRLF) $oNWC.GetNetwork($pNet) $oNet = ObjCreateInterface($pNet, $sIID_INetwork, $sTag_INetwork) If Not IsObj($oNet) Then Exit MsgBox($MB_OK, "Error", "INetwork") $oNet.GetName($sName) ConsoleWrite("GetName: " & $sName & @CRLF) WEnd EndFunc ;==>Interface4 points
-
Simple Google Translate
dmob and 3 others reacted to pixelsearch for a topic
4 points -
I've made a transpiler for converting AutoIt-like class syntax into AutoIt code. GIthub: https://github.com/genius257/au3class/ Example for the syntax: #include-once Class Example $property = Null Func __construct($ts = 'now') $this.property = 0 EndFunc Func __destruct() ; Destructor code here. EndFunc Func method() Return "something" EndFunc Get Func dynamic() Return $this.dynamic & $this.property EndFunc Set Func dynamic($value) $this.property += 1 $this.dynamic = $value EndFunc EndClass $oExample = Example() $oExample.dynamic = 12 MsgBox(0, "", $oExample.dynamic) MsgBox(0, "", $oExample.method()) $oExample = Null class properties are defined as variables within the Class structure class methods are defined as function declarations within the Class structure property getters and setters need to have Get or Set in front of their function declaration Getter and setter can access their own underlying property, without triggering the getter or setter for said variable. Version 2 produces more code than version 1, but does not need any other scripts included to work. Version 2 is also faster than version 1, since version 2 creates specific code for looking up class members, instead of relying on AutoItObject_Internal with it's dynamic properties lookup. See the example folder on Github for building and using this: https://github.com/genius257/au3class/tree/master/Example4 points