Leaderboard
Popular Content
Showing content with the highest reputation on 06/27/2023 in all areas
-
AutoIt Snippets
TheDcoder and one other reacted to seadoggie01 for a topic
Perhaps then the brightness calculation here (specifically, the IsColorLight function) would be helpful? Essentially (((5 * Green) + (2 * Red) + Blue) > (8 * 128)); I've got no idea why it works, but stumbled on it earlier when I was looking for a "better" way to calculate color since your method didn't work for me I think it's a cool idea either way2 points -
richedit resizable scrollbars
mike1950r reacted to pixelsearch for a topic
Mike, you should resize the RichEdit control when the GUI is resized, then you shouldn't have issues with the RichEdit scrollbars. Below are a couple of functions (from a personal long script) where you can pick what you want (e.g the resize part) to solve your richedit scrollbar issue : ;================================================================= Func _GuiPrev() If $g_hGuiPrev = 0 Then ; only once during whole script $g_hGuiPrev = GUICreate("Preview in RichEdit control (read-only)", $g_iGui_W, $g_iGui_H, -1, -1, _ BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) ; $g_cLabel just to allow resizing of a richedit control ! ; Melba23 - https://www.autoitscript.com/forum/topic/204198-richedit-resize/?do=findComment&comment=1466930 $g_cLabel = GUICtrlCreateLabel("", 1, 1, $g_iGui_W - 2, $g_iGui_H - 2) GUICtrlSetResizing($g_cLabel, 1) GUICtrlSetState($g_cLabel, $GUI_DISABLE) ; Most important! (Melba23) $g_hRichEdit = _GUICtrlRichEdit_Create($g_hGuiPrev, "", 1, 1, $g_iGui_W - 2, $g_iGui_H - 2, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_WANTRETURN, $ES_NOHIDESEL, $ES_READONLY)) ; no hozizontal scrollbar ; BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $WS_HSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $ES_NOHIDESEL, $ES_READONLY)) ; horizontal scrollbar ; To do (done) : switch $ES_READONLY off/on after richedit creation (keep the interesting Malkey's link below +++) ; https://www.autoitscript.com/forum/topic/141238-richedit-friendly-name-hyperlinks/?do=findComment&comment=993231 ; No need to use _GUICtrlRichEdit_SetBkColor as white background hurts my eyes. Keep the following line for its syntax ; _GUICtrlRichEdit_SetBkColor($g_hRichEdit, 0x00FFFFFF) ; white (note: my background is grey). White to match Forum background ; 2 following lines to allow clickable url's inside richedit controls, not forgetting $EN_LINK in Func WM_NOTIFY _GUICtrlRichEdit_SetEventMask($g_hRichEdit, $ENM_LINK) _GUICtrlRichEdit_AutoDetectURL($g_hRichEdit, True) ; True to detect URLs in text, False not to ; Nine's - https://www.autoitscript.com/forum/topic/206070-setup-permanent-font-for-richedit-control/?do=findComment&comment=1484072 Local $hFont = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Lucida Console') ; trying to match $g_idEdit font _SendMessage($g_hRichEdit, $WM_SETFONT, $hFont, True) ; True = the control redraws itself _WinAPI_DeleteObject($hFont) _SetTabStops($g_hRichEdit, 14) ; 14 corresponds approx. to 4 characters width (as my Scite) in this RichEdit control with this font Else _GUICtrlRichEdit_SetText($g_hRichEdit, "") ; useful on 2nd(+) preview, to erase the text that was in the richedit control EndIf GUISetState(@SW_DISABLE, $g_hGui) GUISetState(@SW_SHOW, $g_hGuiPrev) _PreviewOrGenerate(1) ; 1 = Preview (in RichEdit control) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; to take care of clickable url's in richedit control GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; to resize richedit control when its Gui is resized While 4 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; close $g_hGuiPrev (as $g_hGui is disabled at this stage) ExitLoop; While 4 Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; goal is to resize correctly... the richedit control in $g_hGuiPrev _Resize() EndSwitch Wend GUIRegisterMsg($WM_SIZE, "") GUIRegisterMsg($WM_NOTIFY, "") GUISetState(@SW_HIDE, $g_hGuiPrev) GUISetState(@SW_ENABLE, $g_hGui) ControlFocus($g_hGui, "", $g_idEdit) EndFunc ;==>_GuiPrev ;================================================================= Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $g_hGuiPrev Then _Resize() ; Return 0 ; "If an application processes this message, it should return zero." (msdn) ... but bad display in this script ! EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE ;================================================================= Func _Resize() ; Get the new position and size of the label... Local $aPos = ControlGetPos($g_hGuiPrev, "", $g_cLabel) ; ...and set the RichEdit to the same position and size WinMove($g_hRichEdit, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndFunc ;==>_Resize I applied it to the code you presented in your post, it worked fine : #include <EditConstants.au3> #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; GUI $iWidth = 800 $iHeight = 600 $iLeft = 0 $iTop = 0 $hStyle = BitOR($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX) $hExStyle = $WS_EX_DLGMODALFRAME $hGlo_WE_GUI = GUICreate("Gui title", $iWidth , $iHeight, $iLeft, $iTop, $hStyle, $hExStyle) ; $g_cLabel just to allow resizing of a richedit control ! ; Melba23 - https://www.autoitscript.com/forum/topic/204198-richedit-resize/?do=findComment&comment=1466930 $g_cLabel = GUICtrlCreateLabel("", 0, 0, $iWidth - 100, $iHeight - 100) GUICtrlSetResizing($g_cLabel, 1) GUICtrlSetState($g_cLabel, $GUI_DISABLE) ; Most important! (Melba23) ; Richedit Control $hStyle = BitOR($ES_MULTILINE, $ES_WANTRETURN, $ES_NOHIDESEL, $WS_VSCROLL, $WS_HSCROLL) $hExStyle = $WS_EX_CLIENTEDGE $hGlo_WE_Control = _GUICtrlRichEdit_Create($hGlo_WE_GUI, "", 0, 0, $iWidth - 100, $iHeight - 100, $hStyle, $hExStyle) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; to resize richedit control when its Gui is resized While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hGlo_WE_Control) Exit Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; goal is to resize correctly... the richedit control in $hGlo_WE_GUI _Resize() EndSwitch WEnd ;================================================================= Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGlo_WE_GUI Then _Resize() ; Return 0 ; "If an application processes this message, it should return zero." (msdn) ... but bad display in this script ! EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE ;================================================================= Func _Resize() ; Get the new position and size of the label... Local $aPos = ControlGetPos($hGlo_WE_GUI, "", $g_cLabel) ; ...and set the RichEdit to the same position and size WinMove($hGlo_WE_Control, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndFunc ;==>_Resize In my script, I still have a minor issue with the resize part (solved with a workaround) but let's hope you won't face it. Good luck1 point -
Dunno if you'll ever read this, but I wanted to let you know that I'm testing this out and so far it's looking really great - wanted to commend you for the hard work on this - very incredible stuff, kudos!1 point
-
AutoIt Snippets
seadoggie01 reacted to argumentum for a topic
#include-once ; if used as include #include <WinAPISysWin.au3> #include <WindowsConstants.au3> ConsoleWrite('- IsDarkMode: ' & IsDarkMode() & @CRLF) Func IsDarkMode() ; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1520332 ; https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor Return (PerceivedBrightnessOfColor(_WinAPI_GetSysColor($COLOR_WINDOWTEXT)) _ > PerceivedBrightnessOfColor(_WinAPI_GetSysColor($COLOR_WINDOW))) ; if the text is perceived as brighter than the background then Return True EndFunc ;==>IsDarkMode Func PerceivedBrightnessOfColor($color) ; https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes#know-when-dark-mode-is-enabled ; This function performs a quick calculation of the perceived brightness of a color, and takes into consideration ; ways that different channels in an RGB color value contribute to how bright it looks to the human eye. Local $a = StringSplit(Hex($color, 6), ""), $r = 2 * Dec($a[1] & $a[2]), $g = 5 * Dec($a[3] & $a[4]), $b = 1 * Dec($a[5] & $a[6]) Return ($r + $g + $b) EndFunc ;==>PerceivedBrightnessOfColor ..yes. If the perceived color is brighter than the background then it can be said to be in dark mode. Based on the link you shared, I cooked the above and it makes sense. The 5 + 2 + 1 = 8 makes sense too. All in all the above is a better approach than my 1st attempt at determining dark mode. Thanks for sharing @seadoggie011 point -
Richedit horizontal scroll right arrow problem
mikell reacted to pixelsearch for a topic
Mike, the following script solves partially your issue. If you immediately drag the horizontal scroll box at its rightmost position, then the horizonal scroll right arrow will be deactivated, as discussed before. But this is not enough, as some other ways of scrolling aren't solved by the script. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <GuiScrollBars.au3> Global $sText = "", $hGui, $hRichEdit For $n = 2 To 100 $sText &= $n & " - This is a single long line intended to cause a hoizontal scroll bar to appear in the RichEdit control." & @CRLF Next $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, $sText, 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL)) ; _GUICtrlRichEdit_SetEventMask($hRichEdit, BitOR($ENM_SCROLL, $ENM_SCROLLEVENTS)) _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_SCROLLEVENTS) GUISetState(@SW_SHOW) $tSCROLLBARINFO = _GUIScrollBars_GetScrollBarInfoEx($hRichEdit, $OBJID_HSCROLL) $iMaxScrollHoriz = $tSCROLLBARINFO.Right - $tSCROLLBARINFO.xyThumbTop - $tSCROLLBARINFO.Left ConsoleWrite("$iMaxScrollHoriz = " & $iMaxScrollHoriz & @crlf & @crlf) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam) #forceref $iMsg, $iWparam Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu $tNMHDR = DllStructCreate($tagNMHDR, $iLparam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hRichEdit Select Case $iCode = $EN_MSGFILTER $tMsgFilter = DllStructCreate($tagMSGFILTER, $iLparam) Switch DllStructGetData($tMsgFilter, "msg") Case $WM_HSCROLL ; 276 Local $iRightScrollThumb = _GUIScrollBars_GetScrollBarXYThumbBottom($hRichEdit, $OBJID_HSCROLL) ConsoleWrite("$iRightScrollThumb = " & $iRightScrollThumb & " / " & _ "$iMaxScrollHoriz = " & $iMaxScrollHoriz & @crlf) If $iRightScrollThumb = $iMaxScrollHoriz Then _GUIScrollBars_EnableScrollBar($hRichEdit, $SB_HORZ, $ESB_DISABLE_RIGHT) Else _GUIScrollBars_EnableScrollBar($hRichEdit, $SB_HORZ, $ESB_ENABLE_BOTH) EndIf Case $WM_VSCROLL ; 277 EndSwitch EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Anyway, that's a start, better than nothing1 point -
omi Or this: _ProcessCloseEx("cmd.exe") Func _ProcessCloseEx($sPID) If IsString($sPID) Then $sPID = ProcessExists($sPID) If Not $sPID Then Return SetError(1, 0, 0) Return Run(@ComSpec & " /c taskkill /F /PID " & $sPID & " /T", @SystemDir, @SW_HIDE) EndFunc1 point