Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/11/2022 in all areas

  1. https://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.16.1-rc1-setup.zip https://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.16.1-rc1.zip 3.3.16.1 (xxx, 2022) (Release) AutoIt: - Fixed #3866: REGEXPCLASS broken in 3.3.16.0. - Fixed #3875: GUICtrlSetResizing() performance. - Fixed #3865: Image Control resizing behave as forced $GUI_DOCKWIDTH and $GUI_DOCKHEIGHT. - Fixed #3764: StringRegExp() crash with patterns that cause infinite recursion. - Fixed #3876: Hex Number Arithmetic is incorrect. - Fixed #3879: Dim Map to Array. UDFs: - Fixed #3867: Changes in 'SecurityConstants.au3' to avoid name conflict. THIS IS A SCRIPT BREAKING CHANGE - Added: UBound[2] example. - Added: StringRegExp[5] example. - Added: _GUICtrlEdit_SetPadding() function and example. - Fixed: Regression in 3.3.15.1, _WinAPI_RegCreateKey() and _WinAPI_RegOpenkey(). - Added: _WinAPI_RegDeleteKey() can use $hKey as in RegRead(). - Fixed: Regression of #3835 on _GDIPlus_GraphicsGet*(). - Fixed #3871: _ArrayDisplay() Hang sorted array with Null element. - Fixed: _FTP_FileGetSize() very big size. - Fixed #3872: FTP-Server in AutoIt Help no longer accessible. - Fixed #3877: GUICtrlCreateLabel() overlapping controls doc precision ($WS_CLIPSIBLINGS). - Added #3863: _WinAPI_GetCapture(). - Added: Allows _DebugArrayDisplay() to be used in UserFunc. - Added: _ArrayDisplay() and _DebugArrayDisplay() support Min Column width. - Added: _Array2DCreate() support 1D and/or 2D arrays. - Added: _DebugReportVar() display DllStruct content. - Fixed #3883: _DebugArrayDisplay() produces uncalled console message. - Added: _ArrayDisplay() and _DebugArrayDisplay() display {Array[dims]}, {Map[nentry]} and {Object}.
    1 point
  2. Since you are working with JSON, you could also use UDF's designed specifically for that purpose, like the ones in JSON.au3, which can handle JSON escaping & unescaping for you: #include <Constants.au3> #include <Debug.au3> #include <MyIncludes\json\json.au3> ;<== Modify path as needed example() Func example() Const $JSON = '{"message":"Invalid license","errors":{"key":"\u0627\u06cc\u0646 ' & _ '\u0644\u0627\u06cc\u0633\u0646\u0633 \u062f\u0631 \u0633\u06cc\u0633' & _ '\u062a\u0645 \u0645\u0648\u062c\u0648\u062f \u0646\u06cc\u0633\u062a"}}' Local $oJson = Null ;Set up debug messages to go to notepad _DebugSetup("JSON Parsing Example", False, 5) ;Decode JSON into dictionary object $oJson = Json_Decode($JSON) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Json_Decode failed - @error = " & @error) ;Display examples of escaped and unescaped JSON unicode output _DebugOut("Raw JSON") _DebugOut(Json_Encode($oJson) & @CRLF) _DebugOut("Raw JSON with unescaped unicode") _DebugOut(Json_Encode($oJson, $JSON_UNESCAPED_UNICODE) & @CRLF) _DebugOut("Pretty-printed JSON") _DebugOut(Json_Encode($oJson, $JSON_PRETTY_PRINT) & @CRLF) _DebugOut("Pretty-printed JSON with unescaped unicode") _DebugOut(Json_Encode($oJson, $JSON_PRETTY_PRINT + $JSON_UNESCAPED_UNICODE) & @CRLF) _DebugOut("Parsed JSON values") _DebugOut(".message = " & Json_Get($oJson, ".message")) _DebugOut(".errors = " & Json_Encode(Json_Get($oJson, ".errors"), $JSON_UNESCAPED_UNICODE)) _DebugOut(".errors.key = " & Json_Get($oJson, ".errors.key")) EndFunc Output: Raw JSON {"message":"Invalid license","errors":{"key":"\u0627\u06cc\u0646 \u0644\u0627\u06cc\u0633\u0646\u0633 \u062f\u0631 \u0633\u06cc\u0633\u062a\u0645 \u0645\u0648\u062c\u0648\u062f \u0646\u06cc\u0633\u062a"}} Raw JSON with unescaped unicode {"message":"Invalid license","errors":{"key":"این لایسنس در سیستم موجود نیست"}} Pretty-printed JSON { "message": "Invalid license", "errors": { "key": "\u0627\u06cc\u0646 \u0644\u0627\u06cc\u0633\u0646\u0633 \u062f\u0631 \u0633\u06cc\u0633\u062a\u0645 \u0645\u0648\u062c\u0648\u062f \u0646\u06cc\u0633\u062a" } } Pretty-printed JSON with unescaped unicode { "message": "Invalid license", "errors": { "key": "این لایسنس در سیستم موجود نیست" } } Parsed JSON values .message = Invalid license .errors = {"key":"این لایسنس در سیستم موجود نیست"} .errors.key = این لایسنس در سیستم موجود نیست
    1 point
  3. Not sure if this is, what you are looking for : (Author is @guinness - Source from : https://www.autoitscript.com/wiki/Snippets_(_Internet_)#GetTimeOnline) ; Retrieve the current time from TimeAPI.org. Ideal if your Windows clock is out of sync. ConsoleWrite(_GetTimeOnline(0) & @CRLF) ; TimeZone UTC. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetTimeOnline ; Description ...: Retrieve the current date and time from TimeAPI.org. ; Syntax ........: _GetTimeOnline($iTimeZone) ; Parameters ....: $iTimeZone - An integer value of the timezone . ; 0 - UTC (Universal Time) ; 1 - EST (Eastern Time) ; 2 - CST (Central Time) ; 3 - MST (Mountain Time) ; 4 - PST (Pacific Time) ; 5 - AKST (Alaska Time) ; 6 - HAST (Hawaii-Aleutian Time) ; Return values .: Success: Returns the current Date and Time in the format YYYY/MM/DD HH:MM:SS ; Failure: Sets @error to non-zero and returns the same format as a successful return but using the system time. ; Author ........: guinness ; Link ..........: According to http://www.programmableweb.com/api/timeapi, this is for non-commercial use. ; Example .......: Yes ; =============================================================================================================================== Func _GetTimeOnline($iTimeZone) Local $aTimeZone[7] = ['utc', 'est', 'cst', 'mst', 'pst', 'akst', 'hast'] Local $sRead = BinaryToString(InetRead('http://www.timeapi.org/' & $aTimeZone[$iTimeZone] & '/now?format=\Y/\m/\d%20\H:\M:\S')) If @error Then Return SetError(1, 0, @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC) EndIf Return $sRead EndFunc ;==>_GetTimeOnline
    1 point
  4. The reverse operation is no harder: ; JSON Unicode to AutoIt UCS2 string Local $s = '{"message":"Invalid license","errors":{"key":"\u0627\u06cc\u0646 \u0644\u0627\u06cc\u0633\u0646\u0633 \u062f\u0631 \u0633\u06cc\u0633\u062a\u0645 \u0645\u0648\u062c\u0648\u062f \u0646\u06cc\u0633\u062a"}}' Local $t = Execute("'" & StringRegExpReplace($s, "\\u([[:xdigit:]]{4})", "' & ChrW(0x$1) & '") & "'") MsgBox(0, "", $t) ; AutoIt UCS2 string to JSON Unicode Local $u = Execute("'" & StringRegExpReplace($t, "([\x{0100}-\x{FFFF}])", "\\u' & StringLower(Hex(AscW('$1'), 4)) & '") & "'") MsgBox(0, "", $u) ConsoleWrite('JSON strings are ' & ($s == $u ? 'equal' : 'different!') & @LF)
    1 point
  5. Hey everyone! Check the first post for the latest update with a whole slew of improvements and new features! Much time and care was put into improving the functionality and stability of selecting and manipulating controls (selection rectangle, copy, paste, drag, resize, etc...) Everything seems to be working pretty well, but slows down considerably when selecting massive groups. I've done what I could for now, but will need to think about how to improve this. Particularly neat is the new feature for aligning the selected controls. Select several controls, then right click on a control or use the edit menu to arrange and align the selected controls. Everything will be aligned to the FIRST selected control. Also cool is that groups of controls can be selected and resized together proportionally. Also, when copying and pasting multiple controls at once, they maintain their relative positions instead of stacking on top of each other. Unfortunately, the rich edit control for syntax highlighting was removed. It was causing so many issues and was not worth it to me to fight it. Standard edit works fine for now. I still need to add control style properties, but I am running out of ideas. Needing some suggestions! But keep it simple. 😏 What's Changed? FIXED: Lots of handling of copy+paste scenarios FIXED: Tooltip when resizing multiple controls FIXED: Changed the selection rectangle so controls don't bounce around during right-to-left selection anymore FIXED: Right-click when multiple controls are selected FIXED: Lagging when dragging many controls at once FIXED: Improved a lot of flickering when dragging things FIXED: Select a control after drawing (instead of drawing on top of it) ADDED: New menu item, shortcut key Ctrl+X, and context menu item to 'Cut' selected controls ADDED: Cut/Copy/Paste will now maintain relative positions and spacing ADDED: Improved paste functionality When pasting with Ctrl+V, control will follow mouse waiting to be placed by single click When pasting with menu or right-click, control will be placed at mouse position ADDED: Resizing multiple-selected controls will resize proportionally as a group ADDED: Resize using any of the selected grippies, not just the last selected ADDED: Status messages for changing some settings (F3, F7) ADDED: Tool button icons now built into the exe, so resources folder is not necessary to run ADDED: Improved selection detection Left-to-right selection requires entire control to be in the rectangle Right-to-left selection selects anything that crosses the rectangle ADDED: Right-click menu items: Arrange-> Align left/center/right, top/middle/bottom, space vertical/horizontal ADDED: Ask to save (definition) dialog when closing, only when a change was detected since the last save MAINT: Added logging function and debug flag for testing/development MAINT: Downgraded to AutoIT v3.3.14.5 for personal reasons (removed maps) UPDATED: Better startup loading, so windows open at the same time UPDATED: Better redrawing with working with multiple controls UPDATED: Reverted back to standard edit box for code preview due to more issues with rich edit than it was worth REMOVED: DPI scaling - not reliable enough to keep for now
    1 point
  6. wow thank you very much it was just what I was looking for, I never thought I would have to use the GUIOnEventMode, well thank you for your help honestly I had no idea how to do it
    1 point
  7. Try this: Local $s = '{"message":"Invalid license","errors":{"key":"\u0627\u06cc\u0646 \u0644\u0627\u06cc\u0633\u0646\u0633 \u062f\u0631 \u0633\u06cc\u0633\u062a\u0645 \u0645\u0648\u062c\u0648\u062f \u0646\u06cc\u0633\u062a"}}' Local $t = Execute("'" & StringRegExpReplace($s, "\\u([[:xdigit:]]{4})", "' & ChrW(0x$1) & '") & "'") MsgBox(0, "", $t) This is standard JSON encoding for general Unicode.
    1 point
  8. #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> Opt("GUIOnEventMode", 1) _Gui() Func _Gui() Global $ConvertService = GUICreate("ConvertService", 714, 416, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "_onChange") GUISetOnEvent($GUI_EVENT_MINIMIZE, "_onChange") Local $lbl_title = GUICtrlCreateLabel("Convert Service Name and CommandLine", 144, 24, 291, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0078D7) Local $lbl_Service = GUICtrlCreateLabel("Services :", 73, 65, 73, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0078D7) Global $edt_Service = _GUICtrlRichEdit_Create($ConvertService, "", 16, 91, 201, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_SetFont($edt_Service, 8, "MS Sans Serif") Global $btn_convert = GUICtrlCreateButton("Convert", 240, 192, 100, 25) GUICtrlSetOnEvent(-1, "_onChange") GUICtrlSetFont(-1, 10, 800, 0) Local $lbl_ScConfigs = GUICtrlCreateLabel("Sc Configs : ", 239, 227, 90, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0078D7) Global $chb_Stop = GUICtrlCreateCheckbox("Stop", 240, 256, 97, 17) Global $chb_Start = GUICtrlCreateCheckbox("Start", 240, 280, 97, 17) Global $chb_Config = GUICtrlCreateCheckbox("Config", 240, 304, 97, 17) Global $cmb_config = GUICtrlCreateCombo("", 240, 328, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "boot|system|auto|demand|disabled|delayed-auto") Global $btn_clear = GUICtrlCreateButton("Clear", 240, 328 + 25 + 7, 100, 25) GUICtrlSetOnEvent(-1, "_onChange") Local $lbl_Converted = GUICtrlCreateLabel("Converted :", 446, 67, 83, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0078D7) Global $edt_Converted = _GUICtrlRichEdit_Create($ConvertService, "", 382, 91, 313, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY )) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") _WinAPI_SetFocus($edt_Service) GUISetState(@SW_SHOW, $ConvertService) While 1 Sleep(100) WEnd EndFunc Func _onChange() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($edt_Service) _GUICtrlRichEdit_Destroy($edt_Converted) GUIDelete($ConvertService) Exit Case $btn_clear _GUICtrlRichEdit_SetSel($edt_Service, 0, -1, True) ; select all, but hide _GUICtrlRichEdit_ReplaceText($edt_Service, "") ; replace all _GUICtrlRichEdit_SetSel($edt_Service, 0, 0) ; set cursor to start _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True) ; select all, but hide _GUICtrlRichEdit_ReplaceText($edt_Converted, "") ; replace all _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0) ; set cursor to start Case $btn_convert _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True) ; select all, but hide _GUICtrlRichEdit_ReplaceText($edt_Converted, "") ; replace all _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0) ; set cursor to start Local $iAll_Lines = _GUICtrlRichEdit_GetLineCount ( $edt_Service ) Local $sConverted = "" Local $sText = "" For $iLine = 1 To $iAll_Lines $sText = _GUICtrlRichEdit_GetTextInLine ( $edt_Service, $iLine ) If $sText<>"" Then If _IsChecked($chb_Stop) Then $sConverted = _create_commandline($sText, "stop") If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted, $sConverted & @LF ) EndIf If _IsChecked($chb_Start) Then $sConverted = _create_commandline($sText, "start") If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted, $sConverted & @LF ) EndIf If _IsChecked($chb_Config) Then Local $sSC_config = GUICtrlRead($cmb_config) If $sSC_config = "" Then $sSC_config = Default $sConverted = _create_commandline($sText, "config", $sSC_config) If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted, $sConverted & @LF ) EndIf EndIf Next EndSwitch EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func _create_commandline($serviceName, $sSc_SW, $sSc_config_SW = Default) Local $sOutput = "" Local $oError = False Switch $sSc_SW Case "stop" $sOutput = "sc stop " & '"' & $serviceName & '"' Case "start" $sOutput = "sc start " & '"' & $serviceName & '"' Case "config" ;<boot|system|auto|demand|disabled|delayed-auto> Switch $sSc_config_SW Case 1, "boot" $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "boot" Case 2, "system" $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "system" Case 3, "auto", Default $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "auto" Case 4, "demand" $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "demand" Case 5, "disabled" $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "disabled" Case 6, "delayed-aut" $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "delayed-aut" EndSwitch EndSwitch If $sOutput Then Return $sOutput Return $oError EndFunc
    1 point
  9. Wow, 5 lines and only the last line is correct syntax! May I suggest you check the helpfile for the correct syntax of using the functions '_ispressed' and 'mouseclick' and study / try the examples for these functions. #include <Misc.au3> ; $click= ("{alt}+{d}") Local $keyAlt = 12 Local $keyD = 44 If _ispressed($keyAlt) and _IsPressed($keyD) Then MouseClick ( "right" , Default, Default , 22 , 10 ) ; Return ; can only be used in a function EndIf
    1 point
  10. https://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.16.1-rc2-setup.zip https://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.16.1-rc2.zip 3.3.16.1 (xxx, 2022) (Release) AutoIt: - Fixed #3866: REGEXPCLASS broken in 3.3.16.0. - Fixed #3865: Image Control resizing behave as forced $GUI_DOCKWIDTH and $GUI_DOCKHEIGHT. - Fixed #3864: StringRegExp() crash with patterns that cause infinite recursion. - Fixed #3876: Hex Number Arithmetic is incorrect. - Fixed #3869: Subtraction operator before power operation is parsed incorrectly. - Fixed #3879: Dim Map to Array. - Fixed #3875: GUICtrlSetResizing() performance by Reverting #3831: GUICtrlSetPos() $GUI_DOCKHCENTER. - Fixed: missing uninstalling file GUICtrlInternals.au3 since 3.3.15.2. UDFs: - Added: UBound[2] example. - Added: StringRegExp[5] example. - Added: _GUICtrlEdit_SetPadding() function and example. - Added: _WinAPI_RegDeleteKey() can use $hKey as in RegRead(). - Added #3863: _WinAPI_GetCapture(). - Added: Allows _DebugArrayDisplay() to be used in UserFunc. - Added: _ArrayDisplay() and _DebugArrayDisplay() support Min Column width. - Added: _Array2DCreate() support 1D and/or 2D arrays. - Added: _DebugReportVar() display DllStruct content. - Added: _ArrayDisplay() and _DebugArrayDisplay() display {Array[dims]}, {Map[nentry]} and {Object}. - Fixed #3867: Changes in 'SecurityConstants.au3' to avoid name conflict. THIS IS A SCRIPT BREAKING CHANGE - Fixed: Regression in 3.3.15.1, _WinAPI_RegCreateKey() and _WinAPI_RegOpenkey(). - Fixed: Regression of #3835 on _GDIPlus_GraphicsGet*(). - Fixed #3871: _ArrayDisplay() Hang sorted array with Null element. - Fixed: _FTP_FileGetSize() very big size. - Fixed #3872: FTP-Server in AutoIt Help no longer accessible. - Fixed #3877: GUICtrlCreateLabel() overlapping controls doc precision ($WS_CLIPSIBLINGS). - Fixed #3883: _DebugArrayDisplay() produces uncalled console message.
    1 point
  11. drapdv

    Mail UDF

    Really helped me out. Thank you, this was a perfect solution for sending email with office365!
    1 point
  12. Hi everybody Even if this thread isn't recent, maybe what follows could be interesting to a new approach of the issue ? Please have a look at this picture and the corresponding script : #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPISysWin.au3> GUICreate("$BS_OWNERDRAW issue ?", 300, 250) $cInput1 = GUICtrlCreateInput("Input1", 10, 10, 200, 20) $cInput2 = GUICtrlCreateInput("Input2", 10, 40, 200, 20) $cButton1 = GUICtrlCreateButton("Button1 $GUI_SS_DEFAULT_BUTTON", _ 10, 70, 200, 30, $GUI_SS_DEFAULT_BUTTON) $hButton1 = GUICtrlGetHandle($cButton1) $iStyle_Button1 = _WinAPI_GetWindowLong($hButton1, $GWL_STYLE) $cButton2 = GUICtrlCreateButton("Button2 $DEFPUSHBUTTON (0x0001)", _ 10, 110, 200, 30, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_DEFPUSHBUTTON)) $hButton2 = GUICtrlGetHandle($cButton2) $iStyle_Button2 = _WinAPI_GetWindowLong($hButton2, $GWL_STYLE) $cButton3 = GUICtrlCreateButton("Button3 $BS_OWNERDRAW (0x000B)", _ 10, 150, 200, 30, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_OWNERDRAW)) $hButton3 = GUICtrlGetHandle($cButton3) $iStyle_Button3 = _WinAPI_GetWindowLong($hButton3, $GWL_STYLE) GUISetState(@SW_SHOW) MsgBox($MB_TOPMOST,"Styles of 3 Buttons ", _ $iStyle_Button1 & @CRLF & @CRLF & @CRLF & _ $iStyle_Button2 & @CRLF & @CRLF & @CRLF & _ $iStyle_Button3) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton1 MsgBox(0, "", "button1 triggered") Case $cButton2 MsgBox(0, "", "button2 triggered") Case $cButton3 MsgBox(0, "", "button3 triggered") EndSwitch WEnd ; https://www.autoitscript.com/forum/topic/162593-changing-button-colors-on-click/ $BS_OWNERDRAW is a style which is added when you change the background color of a button control and it's value is 0x000B (11 decimal) If you BitOr() its value to the default button style, you should get a total of 1342242816 + 11 = 1342242827 Instead of that, we see that AutoIt indicates 1342242817, exactly as if we had added... a $DEFPUSHBUTTON Style (0x0001) I thought of that when I tried Melba23's example, after creating several Input controls and changed the background color of the button, because after that, each Enter key in any Input field triggered the button, exactly as when the button gets the $DEFPUSHBUTTON style. My apologies if this was already discussed or solved in another thread. Thanks for reading.
    1 point
  13. Might be a workaround: #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <GDIPlus.au3> _GDIPlus_Startup() $hDLL = DllOpen("user32.dll") $hGUI = GUICreate("Test", 500, 500) $cInput = GUICtrlCreateInput("Input", 10, 10, 200, 20) $cButton = GUICtrlCreateButton("Button", 10, 40, 80, 30) $cLabel = GUICtrlCreateLabel("", 10, 90, 220, 20) GUISetState(@SW_SHOW) ; Move the focus to the button and then back to the input Sleep(1000) GUICtrlSetState($cButton, $GUI_FOCUS) Sleep(1000) GUICtrlSetState($cInput, $GUI_FOCUS) GUICtrlSetData($cLabel, "Press Enter and nothing happens") ; Wait for ENTER to be pressed and released While 1 If _IsPressed("0D", $hDLL) Then While 1 If Not _IsPressed("0D", $hDLL) Then ExitLoop 2 EndIf Sleep(10) WEnd EndIf Sleep(10) WEnd ; Colour button ;~ GUICtrlSetData($cLabel, "Colouring the button") ;~ GUICtrlSetBkColor($cButton, 0x00FF00) GUICtrlSetData($cButton, "") GUICtrlSetStyle($cButton, BitOR($BS_BITMAP, $GUI_SS_DEFAULT_BUTTON)) Global $hHBitmap = _GDIPlus_BtnCtrlSetBgColorSolid($hGUI, $cButton, 0x00FF00, "Button") ; Move the focus to the button and then back to the input again Sleep(1000) GUICtrlSetState($cButton, $GUI_FOCUS) Sleep(1000) GUICtrlSetState($cInput, $GUI_FOCUS) GUICtrlSetData($cLabel, "Now press Enter again and see the difference") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($hDLL) _WinAPI_DeleteObject($hHBitmap) _GDIPlus_Shutdown() Exit Case $cButton MsgBox(0, "", "button triggered") EndSwitch If _IsPressed("0D", $hDLL) Then While 1 If Not _IsPressed("0D", $hDLL) Then _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($cButton), $BM_SETIMAGE, 0, 0)) GUICtrlSetStyle($cButton, 0) GUICtrlSetData($cButton, "Button") ExitLoop 1 EndIf Sleep(10) WEnd EndIf WEnd Func _GDIPlus_BtnCtrlSetBgColorSolid($hGUI, $iCtrlID, $iColor, $sText = "", $sFont = "Arial", $fSize = 8.5, $iFontColor = 0xFF000000) ;coded by UEZ 2014 Local $aSize = ControlGetPos($hGUI, "", $iCtrlID) If @error Then Return SetError(1, 0, 0) If $sText = "" Then $sText = ControlGetText($hGUI, "", $iCtrlID) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($aSize[2], $aSize[3]) Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $iColor) _GDIPlus_GraphicsFillRect($hGfx, 2, 2, $aSize[2] - 4, $aSize[3] - 4, $hBrush) _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 5) _GDIPlus_GraphicsSetSmoothingMode($hGfx, 2) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fSize) Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, $aSize[2], $aSize[3]) Local Const $hBrush_Font = _GDIPlus_BrushCreateSolid($iFontColor) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) _GDIPlus_GraphicsDrawStringEx($hGfx, $sText, $hFont, $tLayout, $hFormat, $hBrush_Font) Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BrushDispose($hBrush_Font) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_FontDispose($hFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BrushDispose($hBrush) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($iCtrlID), $BM_SETIMAGE, 0, $hHBitmap)) Return $hHBitmap EndFuncEdit: forgot to cleanup the bitmap resource. Br, UEZ
    1 point
  14. As close as I could get ... ; http://www.autoitscript.com/forum/topic/113811-guictrlbutton-settextcolor/ ; based on post by Yashied #include <GUIButton.au3> #include <GUIImageList.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> GUICreate('MyGUI', 200, 100) GUICtrlCreateButton('OK', 65, 10, 70, 23) GUICtrlCreateButton('OK', 65, 40, 70, 23) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlCreateButton('', 65, 70, 70, 23) _GUICtrlButton_SetTextBkColor(-1, 'OK', 0xFF0000, 0x00FF00) GUISetState() Do Until GUIGetMsg() = -3 Func _GUICtrlButton_SetTextBkColor($iCtrlID, $sText, $iTextColor, $iBkColor) Local $hWnd, $hTheme, $hImageList, $hBitmap, $hBack, $hDC, $hMemDC, $hSrcDC, $tRect, $pRect, $Width, $Height, $Prev, $Flags = BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER) $hWnd = GUICtrlGetHandle($iCtrlID) If Not $hWnd Then Return 0 EndIf $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'BUTTON') If (@error) Or (Not $hTheme[0]) Then GUICtrlSetColor($iCtrlID, $iTextColor) GUICtrlSetData($iCtrlID, $sText) Return 1 EndIf $Width = _WinAPI_GetClientWidth($hWnd) $Height = _WinAPI_GetClientHeight($hWnd) $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4) $tRect = DllStructCreate('int[4]') DllStructSetData($tRect, 1, -4, 1) DllStructSetData($tRect, 1, -4, 2) DllStructSetData($tRect, 1, $Width - 4, 3) DllStructSetData($tRect, 1, $Height - 4, 4) $pRect = DllStructGetPtr($tRect) $hDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8) ;$hBack = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8) $hBack = _WinAPI_CreateSolidBitmap($hWnd, $iBkColor, $Width - 8, $Height - 8) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_SelectObject($hSrcDC, $hBack) _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT)) _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16))) _WinAPI_SetBkMode($hMemDC, $TRANSPARENT) ; PBS_NORMAL, PBS_HOT, PBS_PRESSED, PBS_DISABLED, PBS_DEFAULTED For $i = 1 To 5 $Prev = _WinAPI_SelectObject($hMemDC, $hBitmap) DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme[0], 'hwnd', $hSrcDC, 'int', 4, 'int', $i, 'ptr', $pRect, 'ptr', 0) _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY) If $i = 4 Then DllCall('uxtheme.dll', 'int', 'DrawThemeText', 'ptr', $hTheme[0], 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'wstr', $sText, 'int', -1, 'dword', $Flags, 'dword', 0, 'ptr', $pRect) Else _WinAPI_DrawText($hMemDC, $sText, $tRect, $Flags) EndIf _WinAPI_SelectObject($hMemDC, $Prev) _GUIImageList_Add($hImageList, $hBitmap) Next ; PBS_HOT (Stylus Hot) _GUIImageList_SetImageCount($hImageList, 6) _GUIImageList_Copy($hImageList, 1, 5) _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBack) DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme[0]) $Prev = _GUICtrlButton_GetImageList($hWnd) If $Prev[0] Then _GUIImageList_Destroy($Prev[0]) EndIf GUICtrlSetData($iCtrlID, '') If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then _GUIImageList_Destroy($hImageList) Return 0 EndIf Return 1 EndFunc ;==>_GUICtrlButton_SetTextBkColor
    1 point
  15. Yashied

    Button Text Color

    One way. #Include <Constants.au3> #Include <GUIConstantsEx.au3> #Include <StaticConstants.au3> #Include <WindowsConstants.au3> #Include <WinAPI.au3> Dim $Button[4] $hForm = GUICreate('MyGUI', 350, 63) $Button[0] = GUICtrlCreateButton('', 20, 20, 70, 23) GUICtrlCreateLabel('Button1', 20, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 11, -1, -1, 'Times') GUICtrlSetColor(-1, 0xFF00FF) $Button[1] = GUICtrlCreateButton('', 100, 20, 70, 23) GUICtrlCreateLabel('Button2', 100, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 11, -1, -1, 'Comic Sans MS') GUICtrlSetColor(-1, 0xFF0000) $Button[2] = GUICtrlCreateButton('', 180, 20, 70, 23) GUICtrlCreateLabel('Button1', 180, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 10, -1, 2) GUICtrlSetColor(-1, 0x00FF00) $Button[3] = GUICtrlCreateButton('', 260, 20, 70, 23) GUICtrlCreateLabel('Button1', 260, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, -1, -1, 4) GUICtrlSetColor(-1, 0x0000FF) $hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam') $pDll = DllCallbackGetPtr($hDll) For $i = 0 To UBound($Button) - 1 $hProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $pDll) Next GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 ExitLoop Case $Button[0], $Button[1], $Button[2], $Button[3] MsgBox(0, 'Message', 'Button is pressed.', 0, $hForm) EndSwitch WEnd For $i = 0 To UBound($Button) - 1 _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $hProc) Next DllCallbackFree($hDll) Func _WinProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_PAINT Local $tRECT = DllStructCreate($tagRECT) Local $Ret = DllCall('user32.dll', 'int', 'GetUpdateRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRECT), 'int', 1) If $Ret[0] Then _WinAPI_InvalidateRect(GUICtrlGetHandle(_WinAPI_GetDlgCtrlID($hWnd) + 1), $tRECT) EndIf EndSwitch Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc
    1 point
×
×
  • Create New...