WildByDesign Posted 22 hours ago Posted 22 hours ago Recently I have been playing around with _WinAPI_SetTextColor, _WinAPI_SetBkColor, _WinAPI_SetBkMode and a few other functions in an attempt to change the background color and text color of another app. We can use Notepad (classic win32 notepad) as an example. I have been able to successfully get the handle for Notepad, for the Edit box class and the DC handle. However, none of the colors seem to change. But I guess what I am wondering is if what I am trying to do is technically even possible or not. I just don't want to put too much time into it if it's impossible to do. You have to have Notepad (classic win32) already running for my example because it gets the handle by looking for window title 'Untitled - Notepad' or modified unsaved '*Untitled - Notepad'. Anyway, just wondering if anyone has any experience with doing this or knows if it's technically possible or not. Thank you for your time. Here is some of what I have been trying: Spoiler expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <WinAPIGdi.au3> #include <WinAPITheme.au3> #include <FontConstants.au3> #include <MsgBoxConstants.au3> #include <StructureConstants.au3> #include <WinAPIGdi.au3> #include <WinAPIGdiDC.au3> #include <WinAPIHObj.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Global $aArray, $sClassName, $hWndExplorer, $g_hDC, $test1, $test2, $test3 $aArray = WinList() For $n = 1 To $aArray[0][0] $sClassName = _WinAPI_GetClassName($aArray[$n][1]) ; get handle for File Explorer ;If $sClassName = "CabinetWClass" Then $hWndExplorer = $aArray[$n][1] If $aArray[$n][0] = 'Untitled - Notepad' Then $hWndExplorer = $aArray[$n][1] If $aArray[$n][0] = '*Untitled - Notepad' Then $hWndExplorer = $aArray[$n][1] Next ConsoleWrite($hWndExplorer & @CRLF) Local $hGUI = GUICreate("The external process 3", 350, 220) Local $idButton_Add = GUICtrlCreateButton("Add $WS_EX_LAYERED and attributes" & @crlf & _ "To DetailsPaneHwndHostClass in Explorer", 25, 40, 300, 100, 0x2000) ; $BS_MULTILINE = 0x2000 GUISetState(@SW_SHOW, $hGUI) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_Add ;Local $hControl = ControlGetHandle($hWndExplorer, "", "[CLASS:Microsoft.UI.Content.DesktopChildSiteBridge]") Local $hControl = ControlGetHandle($hWndExplorer, "", "[CLASS:Edit]") ConsoleWrite("$hControl " & $hControl & @CRLF) ConsoleWrite("$hWndExplorer " & $hWndExplorer & @CRLF) $g_hDC = _WinAPI_GetDC($hControl) ConsoleWrite("$g_hDC " & $g_hDC & @CRLF) $test1 = _WinAPI_SetTextColor($g_hDC, 0xFFFFFF) $test2 = _WinAPI_SetBkColor($g_hDC, 0xFFFFFF) $test3 = _WinAPI_SetBkMode($g_hDC, $OPAQUE) ConsoleWrite("$test1 " & $test1 & @CRLF) ConsoleWrite("$test2 " & $test2 & @CRLF) ConsoleWrite("$test3 " & $test3 & @CRLF) _WinAPI_ReleaseDC($hControl, $g_hDC) ;Local $hControl = ControlGetHandle($hWndExplorer, "", "[CLASS:DetailsPaneHwndHostClass]") ;Local $hControl = ControlGetHandle($hWndExplorer, "", "[CLASS:SysTreeView32]") ;Local $aList = WinList($hWndExplorer) ;_ArrayDisplay($aList, "test") ;WinSetTrans($hControl, "", 100) #cs Local $hRgn = _WinAPI_CreateEllipticRgn(_WinAPI_CreateRectEx(0, 0, 0, 0)) _WinAPI_DwmEnableBlurBehindWindow($hControl, 1, 0, $hRgn) If $hRgn Then _WinAPI_DeleteObject($hRgn) EndIf _WinAPI_DwmEnableBlurBehindWindow10($hControl, True) If $sClassName = "CabinetWClass" Then WinActivate("[CLASS:Shell_TrayWnd]") WinActivate($hControl) EndIf #ce ;_WinAPI_DwmExtendFrameIntoClientArea($hControl, _WinAPI_CreateMargins(-1, -1, -1, -1)) ;__WinAPI_Set_Window_Style($hControl, $WS_EX_LAYERED, _ ; ($nMsg = $idButton_Add ? True : False), _ ; add or remove... ; True) ; True = ...the extended style ;_WinAPI_SetLayeredWindowAttributes($hControl, 0xff222222, 120) ;_WinAPI_SetWindowTheme($hControl, "", "") ;_WinAPI_SetWindowTheme($hControl, 'CFD') Local $AlphaKey = 0x00000000 ;_WinAPI_SetLayeredWindowAttributes($hControl, $AlphaKey, 0, $LWA_COLORKEY + $LWA_ALPHA, True) ;_WinAPI_DwmExtendFrameIntoClientArea($hControl, _WinAPI_CreateMargins(-1, -1, -1, -1)) Local $iTransColor, $iAlpha Local $iInfo = _WinAPI_GetLayeredWindowAttributes($hControl, $iTransColor, $iAlpha) #cs MsgBox($MB_SYSTEMMODAL, 'Layered GUI', "Button on layered Window Clicked" & @CRLF & "Information about this window: " & @CRLF & _ "Transparent Color: " & $iTransColor & @CRLF & _ "Alpha Value: " & $iAlpha & @CRLF & _ "LWA_COLORKEY: " & (BitAND($iInfo, $LWA_COLORKEY) = $LWA_COLORKEY) & @CRLF & _ "LWA_ALPHA: " & (BitAND($iInfo, $LWA_ALPHA) = $LWA_ALPHA)) #ce _WinAPI_SetWindowPos($hControl, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER)) ; +++ EndSwitch WEnd ;=========================================== Func __WinAPI_Set_Window_Style($hWnd, $i_Style, $b_Add, $b_exStyle = False) ; compacted code (from Kafu's original) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local $iIndex = $b_exStyle ? $GWL_EXSTYLE : $GWL_STYLE ; $iIndex as named by msdn & help file Local $i_Style_Old = _WinAPI_GetWindowLong($hWnd, $iIndex) If $b_Add Then If BitAND($i_Style_Old, $i_Style) Then Return ; style already applied _WinAPI_SetWindowLong($hWnd, $iIndex, BitOR($i_Style_Old, $i_Style)) Else ; remove If Not BitAND($i_Style_Old, $i_Style) Then Return ; style not set _WinAPI_SetWindowLong($hWnd, $iIndex, BitXOR($i_Style_Old, $i_Style)) EndIf Local $iRet = _WinAPI_SetWindowPos($hWnd, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER)) ; +++ If Not $iRet Then MsgBox($MB_TOPMOST, "_WinAPI_SetWindowPos", "Error = " & _WinAPI_GetLastError() & " Message = " & _WinAPI_GetLastErrorMessage()) EndFunc ;==>__WinAPI_Set_Window_Style
WildByDesign Posted 22 hours ago Author Posted 22 hours ago I was also trying with _WinAPI_SetSysColors but no success there either.
ahmet Posted 21 hours ago Posted 21 hours ago Can you try creating an edit box within your GUI? Then try to apply those functions to your edit box.
WildByDesign Posted 21 hours ago Author Posted 21 hours ago Yes, I have tried creating a GUI within AutoIt to confirm that those functions do work well. It just seems to not work on another process, in this case Notepad as example. The functions succeed without failure which is good, but nothing changes visually in Notepad.
ahmet Posted 18 hours ago Posted 18 hours ago Can you share the code that works where you set text color of an edit box inside AutoIt's GUI?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now