AutoIt Forums: How do I use DrawThemeTextEx to get glowing text on aero glass? - AutoIt Forums

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

How do I use DrawThemeTextEx to get glowing text on aero glass?

#21 User is offline   Vadersapien 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 131
  • Joined: 11-October 09
  • Gender:Male

Posted 11 November 2009 - 07:12 AM

Got the text positioned...but...say my _DrawTime() function is like this:
[ autoIt ]    ( Popup )
Func _DrawTime()     Local $hDC = _WinAPI_GetDC($hGUI)     Local $tClientRect = _WinAPI_GetClientRect($hGUI)     Local $tST = _Date_Time_GetLocalTime()     Local $sText = _Date_Time_SystemTimeToTimeStr($tST)     Local $hFont = _WinAPI_CreateFont(15, 6, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _         $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Segoe UI') ; Edit as necessary.         DllStructSetData($tClientRect, "Top", 76)         _DrawGlowingText($hDC, $sText, $tClientRect, 10, $hFont, 0x000000) ; BGR, implementing RGB is easy.         _WinAPI_DeleteObject($hFont)     _WinAPI_ReleaseDC($hGUI, $hDC) EndFunc  

Positioning the text with this code:
[ autoIt ]    ( Popup )
DllStructSetData($tClientRect, "Top", 76)  

It works, but leaves a big white rectangle at the top...any idea why?

#22 User is offline   Authenticity 

  • Mass Spammer!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 2,588
  • Joined: 22-January 09
  • Gender:Male

Posted 11 November 2009 - 02:01 PM

Make sure you handle $WM_ERASEBKGND and fill the client area, the DWM seeks for pixels with the color 0x000000 (100% transparent black) in your GUI to apply the blur effect:

[ autoIt ]    ( Popup )
Func _WM_ERASEBKGND($hWnd, $iMsg, $iwParam, $ilParam)     Local $hDC = $iwParam     Local $tClientRect = _WinAPI_GetClientRect($hWnd)     Local $hBrush = _WinAPI_GetStockObject($BLACK_BRUSH)         _WinAPI_FillRect($hDC, DllStructGetPtr($tClientRect), $hBrush)     Return 1 EndFunc

This post has been edited by Authenticity: 11 November 2009 - 02:01 PM


#23 User is offline   GtaSpider 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 197
  • Joined: 09-April 06
  • Gender:Male
  • Location:Germany

Posted 11 November 2009 - 02:48 PM

View PostAuthenticity, on 10 November 2009 - 03:32 AM, said:

This code is from this article. This guy tried numerous things and the best he came up with is this one which requires much more code (for every control) but not as much dealing with owner drawn controls:

[ autoIt ]    ( ExpandCollapse - Popup )
#include <Constants.au3> #include <Date.au3> #include <EditConstants.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) If Not IsDeclared("WM_DWMCOMPOSITIONCHANGED") Then Global Const $WM_DWMCOMPOSITIONCHANGED = 0x031E If Not IsDeclared("WM_PRINT") Then Global Const $WM_PRINT = 0x0317 If Not IsDeclared("WM_PRINTCLIENT") Then Global Const $WM_PRINTCLIENT = 0x0318 If Not IsDeclared("tagBP_PAINTPARAMS") Then Global Const $tagBP_PAINTPARAMS = "uint Size;uint Flags;" & $tagRECT & ";ptr BlendFunction;" If Not IsDeclared ("tagDWM_BLURBEHIND") Then Global Const $tagDWM_BLURBEHIND = "uint Flags;int Enable;hwnd RgnBlur;int TransitionOnMaximized;" If Not IsDeclared("tagPAINTSTRUCT") Then Global Const $tagPAINTSTRUCT = "hwnd hDC;int Erase;" & $tagRECT & ";int Restore;int IncUpdate;ubyte Reserved[32]" If Not IsDeclared("tagDTTOPTS") Then Global Const $tagDTTOPTS = _ "uint Size;uint Flags;uint clrText;uint clrBorder;uint clrShadow;int TextShadowType;" & $tagPOINT & _ ";int BorderSize;int FontPropId;int ColorPropId;int StateId;int ApplyOverlay;int GlowSize;ptr DrawTextCallback;int lParam;" Global Enum $BPBF_COMPATIBLEBITMAP, $BPBF_DIB, $BPBF_TOPDOWNDIB, $BPBF_TOPDOWNMONODIB Global Const $PRF_CHECKVISIBLE = 0x00000001 Global Const $PRF_NONCLIENT = 0x00000002 Global Const $PRF_CLIENT = 0x00000004 Global Const $PRF_ERASEBKGND = 0x00000008 Global Const $PRF_CHILDREN = 0x00000010 Global Const $PRF_OWNED = 0x00000020 Global Const $DWM_BB_ENABLE = 0x00000001 Global Const $DWM_BB_BLURREGION = 0x00000002 Global Const $DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004 Global Const $DTT_GRAYED = 0x00000001 Global Const $DTT_FLAGS2VALIDBITS = $DTT_GRAYED Global Const $DTT_TEXTCOLOR = 0x00000001 Global Const $DTT_BORDERCOLOR = 0x00000002 Global Const $DTT_SHADOWCOLOR = 0x00000004 Global Const $DTT_SHADOWTYPE = 0x00000008 Global Const $DTT_SHADOWOFFSET = 0x00000010 Global Const $DTT_BORDERSIZE = 0x00000020 Global Const $DTT_FONTPROP = 0x00000040 Global Const $DTT_COLORPROP = 0x00000080 Global Const $DTT_STATEID = 0x00000100 Global Const $DTT_CALCRECT = 0x00000200 Global Const $DTT_APPLYOVERLAY = 0x00000400 Global Const $DTT_GLOWSIZE = 0x00000800 Global Const $DTT_CALLBACK = 0x00001000 Global Const $DTT_COMPOSITED = 0x00002000 Global Const $DTT_VALIDBITS = BitOR($DTT_TEXTCOLOR, $DTT_BORDERCOLOR, $DTT_SHADOWCOLOR, $DTT_SHADOWTYPE, $DTT_SHADOWOFFSET, $DTT_BORDERSIZE, _         $DTT_FONTPROP, $DTT_COLORPROP, $DTT_STATEID, $DTT_CALCRECT, $DTT_APPLYOVERLAY, $DTT_GLOWSIZE, $DTT_COMPOSITED) Global $hUxTheme = DllOpen("uxtheme.dll") Global $hGUI = GUICreate("Test", 300, 300) Global $hTheme = _WinAPI_OpenThemeData($hGUI, "globals", $hUxTheme) ; Initialize buffered painting for the current thread. _WinAPI_BufferedPaintInit($hUxTheme) Global $Edit = GUICtrlCreateInput("Hello World",20,10,260,25);Wont work Global $hEdit = GUICtrlGetHandle(-1) GUICtrlSetFont(-1, 15, 500) Global $hEditProc = DllCallbackRegister("_EditProc", "int", "hwnd;uint;wparam;lparam") Global $hWndProc = _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, DllCallbackGetPtr($hEditProc)) GUIRegisterMsg($WM_ERASEBKGND, "_WM_ERASEBKGND") GUIRegisterMsg($WM_DWMCOMPOSITIONCHANGED, "_WM_DWMCOMPOSITIONCHANGED") GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") _DrawTime() _SendMessage($hGUI, $WM_DWMCOMPOSITIONCHANGED) AdlibEnable("_DrawTime", 1000) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_CloseThemeData($hTheme, $hUxTheme) _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $hWndProc) DllCallbackFree($hEditProc) ;Closes down buffered painting for the current thread. _WinAPI_BufferedPaintUnInit($hUxTheme) GUIDelete() Exit Func _EditProc($hWnd, $iMsg, $iwParam, $ilParam)     Local $hDC, $hBufferedDC, $hPaintBuffer     Local $tPS, $pPS     Local $tRect         Switch $iMsg         Case $WM_PAINT             $tPS = DllStructCreate($tagPAINTSTRUCT)             $pPS = DllStructGetPtr($tPS)             $hDC = _WinAPI_BeginPaint($hWnd, $pPS)             $tRect = DllStructCreate($tagRECT)                         For $i = 1 To 4                 DllStructSetData($tRect, $i, DllStructGetData($tPS, $i+2))             Next                         $hPaintBuffer = _WinAPI_BeginBufferedPaint($hDC, DllStructGetPtr($tRect), $BPBF_TOPDOWNDIB, 0, $hBufferedDC, $hUxTheme)             _SendMessage($hWnd, $WM_PRINTCLIENT, $hBufferedDC, $PRF_CLIENT)             _WinAPI_BufferedPaintSetAlpha($hPaintBuffer, 0, 255, $hUxTheme)             If $hPaintBuffer Then _WinAPI_EndBufferedPaint($hPaintBuffer, True, $hUxTheme)                         _WinAPI_EndPaint($hWnd, $pPS)             Return 0     EndSwitch         Return _WinAPI_CallWindowProc($hWndProc, $hWnd, $iMsg, $iwParam, $ilParam) EndFunc Func _DrawTime()     Local $hDC = _WinAPI_GetDC($hGUI)     Local $tClientRect = _WinAPI_GetClientRect($hGUI)     Local $tST = _Date_Time_GetLocalTime()     Local $sText = _Date_Time_SystemTimeToTimeStr($tST)     Local $hFont = _WinAPI_CreateFont(40, 15, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _         $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial Black') ; Edit as necessary.             DllStructSetData($tClientRect, "Top", 50)     _DrawGlowingText($hDC, $sText, $tClientRect, 10, $hFont, 0x0000aa) ; BGR, implementing RGB is easy.     _WinAPI_DeleteObject($hFont)     _WinAPI_ReleaseDC($hGUI, $hDC) EndFunc Func _WM_ERASEBKGND($hWnd, $iMsg, $iwParam, $ilParam)     Local $hDC = $iwParam     Local $tClientRect = _WinAPI_GetClientRect($hWnd)     Local $hBrush = _WinAPI_GetStockObject($BLACK_BRUSH)     _WinAPI_FillRect($hDC, DllStructGetPtr($tClientRect), $hBrush)     _WinAPI_DeleteObject($hBrush)         Return 1 EndFunc Func _WM_DWMCOMPOSITIONCHANGED($hWnd, $iMsg, $iwParam, $ilParam)     Local $tMargs = DllStructCreate($tagMARGINS)     If _WinAPI_DwmIsCompositionEnabled() Then         For $i = 1 To 4             DllStructSetData($tMargs, $i, -1)         Next         _WinAPI_DwmExtendFrameIntoClientArea($hWnd, $tMargs)     EndIf     Return 0 EndFunc Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)     If _WinAPI_HiWord($iwParam) = $EN_CHANGE Then         _WinAPI_InvalidateRect($hWnd, 0, False)         Return 0     EndIf         Return $GUI_RUNDEFMSG EndFunc Func _DrawGlowingText($hDC, $sText, $tRc, $iGlowSize = 10, $hFont = 0, $iTextClr = -1)     Local $hCDC     Local $hBrush, $hOldBrush     Local $tRcText     Local $tBI, $tDTO     Local $hDIBBmp, $hOldBmp     Local $hOldFont     Local $tST     Local $iFlags = BitOR($DTT_GLOWSIZE, $DTT_COMPOSITED)     $hCDC = _WinAPI_CreateCompatibleDC($hDC)     $tBI = DllStructCreate($tagBITMAPINFO)     DllStructSetData($tBI, "Size", DllStructGetSize($tBI)-4)     DllStructSetData($tBI, "Width", DllStructGetData($tRc, "Right")-DllStructGetData($tRc, "Left"))     DllStructSetData($tBI, "Height", -(DllStructGetData($tRc, "Bottom")-DllStructGetData($tRc, "Top")))     DllStructSetData($tBI, "Planes", 1)     DllStructSetData($tBI, "BitCount", 32)     DllStructSetData($tBI, "Compression", 0) ; BI_RGB     $hDIBBmp = _WinAPI_CreateDIBSection($hDC, $tBI)     $hOldBmp = _WinAPI_SelectObject($hCDC, $hDIBBmp)     If $hFont Then $hOldFont = _WinAPI_SelectObject($hCDC, $hFont)      $tDTO = DllStructCreate($tagDTTOPTS)     DllStructSetData($tDTO, "Size", DllStructGetSize($tDTO))     If $iTextClr <> -1 Then         $iFlags = BitOR($iFlags, $DTT_TEXTCOLOR)         DllStructSetData($tDTO, "clrText", $iTextClr)     EndIf     DllStructSetData($tDTO, "Flags", $iFlags)     DllStructSetData($tDTO, "GlowSize", $iGlowSize)     _WinAPI_DrawThemeTextEx($hTheme, $hCDC, 0, 0, $sText, _         BitOR($DT_SINGLELINE, $DT_CENTER, $DT_VCENTER, $DT_NOPREFIX), $tRc, $tDTO)     _WinAPI_BitBlt($hDC, DllStructGetData($tRc, "Left"), DllStructGetData($tRc, "Top"), _         DllStructGetData($tRc, "Right")-DllStructGetData($tRc, "Left"), _         DllStructGetData($tRc, "Bottom")-DllStructGetData($tRc, "Top"), $hCDC, 0, 0, 0xCC0020) ; SRCCOPY     _WinAPI_SelectObject($hCDC, $hOldBmp)     If $hFont Then _WinAPI_SelectObject($hCDC, $hOldFont)     _WinAPI_DeleteObject($hDIBBmp)     _WinAPI_DeleteDC($hCDC) EndFunc Func _WinAPI_DwmExtendFrameIntoClientArea($hWnd, ByRef $tMargins)     Local $aResult = DllCall("dwmapi.dll", "int", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($tMargins))     If @error Then Return SetError(@error, @extended, -1)     Return $aResult[0] EndFunc Func _WinAPI_DwmIsCompositionEnabled()     Local $aResult = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "int*", 0)     If @error Then Return SetError(@error, @extended, -1)     Return SetError($aResult[0], 0, $aResult[1]) EndFunc Func _WinAPI_DwmEnableBlurBehindWindow($hWnd, ByRef $tBlurBehind)     Local $aResult = DllCall("dwmapi.dll", "int", "DwmEnableBlurBehindWindow", "hwnd", $hWnd, "ptr", DllStructGetPtr($tBlurBehind))         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0] = 0) EndFunc Func _WinAPI_CreateDIBSection($hDC, Const ByRef $tBmpInfo, $iUsage = 0, $pBits = 0, $hSecond = 0, $iOffset = 0)     Local $aResult = DllCall("gdi32.dll", "hwnd", "CreateDIBSection", "hwnd", $hDC, "ptr", DllStructGetPtr($tBmpInfo), _                         "uint", $iUsage, "ptr", $pBits, "hwnd", $hSecond, "uint", $iOffset)     If @error Then Return SetError(@error, @extended, 0)     If $aResult[0] = 87 Then Return SetError(1, 1, 0); 87 = ERROR_INVALID_PARAMETER     If $aResult[0] = 0 Then Return SetError(1, 2, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_BeginPaint($hWnd, $pPaintStruct)     Local $aResult = DllCall("user32.dll", "hwnd", "BeginPaint", "hwnd", $hWnd, "ptr", $pPaintStruct)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_EndPaint($hWnd, $pPaintStruct)     Local $aResult = DllCall("user32.dll", "int", "EndPaint", "hwnd", $hWnd, "ptr", $pPaintStruct)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_DrawThemeTextEx($hTheme, $hDC, $iPartId, $iStateId, $sText, $iFlags, ByRef $tRect, Const ByRef $tDTTOPTS)     Local $aResult = DllCall("uxtheme.dll", "int", "DrawThemeTextEx", "ptr", $hTheme, "hwnd", $hDC, "int", $iPartId, "int", $iStateId, _                         "wstr", $sText, "int", -1, "uint", $iFlags, "ptr", DllStructGetPtr($tRect), "ptr", DllStructGetPtr($tDTTOPTS))     If @error Then Return SetError(@error, @extended, 0)     If $aResult[0] <> 0 Then Return SetError(1, 0, 0)     Return SetError(0, 0, $aResult[0] = 0) EndFunc Func _WinAPI_OpenThemeData($hWnd, $sClassList, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "hwnd", "OpenThemeData", "hwnd", $hWnd, "wstr", $sClassList)     If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_CloseThemeData($hTheme, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "CloseThemeData", "hwnd", $hTheme)     If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc   Func _WinAPI_BufferedPaintInit($hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "BufferedPaintInit")         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc Func _WinAPI_BufferedPaintUnInit($hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "BufferedPaintUnInit")         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc Func _WinAPI_BeginBufferedPaint($hDC, $pRc, $iBufferFormat, $pPaintParams ,ByRef $phDC, $hDll = "uxtheme.dll")     Local $tHDC = DllStructCreate("hwnd")     Local $aResult = DllCall($hDll, "hwnd", "BeginBufferedPaint", "hwnd", $hDC, "ptr", $pRc, "int", $iBufferFormat, "ptr", $pPaintParams, "ptr", DllStructGetPtr($tHDC))         If @error Then Return SetError(@error, @extended, 0)     $phDC = DllStructGetData($tHDC, 1)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_EndBufferedPaint($hPaintBuffer, $fUpdateTarget = True, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "EndBufferedPaint", "hwnd", $hPaintBuffer, "int", $fUpdateTarget)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc Func _WinAPI_BufferedPaintSetAlpha($hPaintBuffer, $pRc, $bAlpha = 255, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "BufferedPaintSetAlpha", "hwnd", $hPaintBuffer, "ptr", $pRc, "ubyte", $bAlpha)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc


Another simpler method is to handle the basic controls' WM_CTLCOLOREDIT or WM_CTLCOLORBTN (for example), isn't as satisfying, but it's easier:

[ autoIt ]    ( ExpandCollapse - Popup )
#include <Constants.au3> #include <Date.au3> #include <EditConstants.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) If Not IsDeclared("WM_DWMCOMPOSITIONCHANGED") Then Global Const $WM_DWMCOMPOSITIONCHANGED = 0x031E If Not IsDeclared("WM_PRINT") Then Global Const $WM_PRINT = 0x0317 If Not IsDeclared("WM_PRINTCLIENT") Then Global Const $WM_PRINTCLIENT = 0x0318 If Not IsDeclared("WM_CTLCOLOREDIT") Then Global Const $WM_CTLCOLOREDIT = 0x0133 If Not IsDeclared("tagBP_PAINTPARAMS") Then Global Const $tagBP_PAINTPARAMS = "uint Size;uint Flags;" & $tagRECT & ";ptr BlendFunction;" If Not IsDeclared ("tagDWM_BLURBEHIND") Then Global Const $tagDWM_BLURBEHIND = "uint Flags;int Enable;hwnd RgnBlur;int TransitionOnMaximized;" If Not IsDeclared("tagPAINTSTRUCT") Then Global Const $tagPAINTSTRUCT = "hwnd hDC;int Erase;" & $tagRECT & ";int Restore;int IncUpdate;ubyte Reserved[32]" If Not IsDeclared("tagDTTOPTS") Then Global Const $tagDTTOPTS = _ "uint Size;uint Flags;uint clrText;uint clrBorder;uint clrShadow;int TextShadowType;" & $tagPOINT & _ ";int BorderSize;int FontPropId;int ColorPropId;int StateId;int ApplyOverlay;int GlowSize;ptr DrawTextCallback;int lParam;" Global Enum $BPBF_COMPATIBLEBITMAP, $BPBF_DIB, $BPBF_TOPDOWNDIB, $BPBF_TOPDOWNMONODIB Global Const $PRF_CHECKVISIBLE = 0x00000001 Global Const $PRF_NONCLIENT = 0x00000002 Global Const $PRF_CLIENT = 0x00000004 Global Const $PRF_ERASEBKGND = 0x00000008 Global Const $PRF_CHILDREN = 0x00000010 Global Const $PRF_OWNED = 0x00000020 Global Const $DWM_BB_ENABLE = 0x00000001 Global Const $DWM_BB_BLURREGION = 0x00000002 Global Const $DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004 Global Const $DTT_GRAYED = 0x00000001 Global Const $DTT_FLAGS2VALIDBITS = $DTT_GRAYED Global Const $DTT_TEXTCOLOR = 0x00000001 Global Const $DTT_BORDERCOLOR = 0x00000002 Global Const $DTT_SHADOWCOLOR = 0x00000004 Global Const $DTT_SHADOWTYPE = 0x00000008 Global Const $DTT_SHADOWOFFSET = 0x00000010 Global Const $DTT_BORDERSIZE = 0x00000020 Global Const $DTT_FONTPROP = 0x00000040 Global Const $DTT_COLORPROP = 0x00000080 Global Const $DTT_STATEID = 0x00000100 Global Const $DTT_CALCRECT = 0x00000200 Global Const $DTT_APPLYOVERLAY = 0x00000400 Global Const $DTT_GLOWSIZE = 0x00000800 Global Const $DTT_CALLBACK = 0x00001000 Global Const $DTT_COMPOSITED = 0x00002000 Global Const $DTT_VALIDBITS = BitOR($DTT_TEXTCOLOR, $DTT_BORDERCOLOR, $DTT_SHADOWCOLOR, $DTT_SHADOWTYPE, $DTT_SHADOWOFFSET, $DTT_BORDERSIZE, _         $DTT_FONTPROP, $DTT_COLORPROP, $DTT_STATEID, $DTT_CALCRECT, $DTT_APPLYOVERLAY, $DTT_GLOWSIZE, $DTT_COMPOSITED) Global $hUxTheme = DllOpen("uxtheme.dll") Global $hGUI = GUICreate("Test", 300, 300) Global $hTheme = _WinAPI_OpenThemeData($hGUI, "globals", $hUxTheme) Global $hBrush = _WinAPI_CreateSolidBrush(0) Global $Edit = GUICtrlCreateInput("Hello World",20,10,260,25) Global $hEdit = GUICtrlGetHandle(-1) GUICtrlSetFont(-1, 15, 500) GUIRegisterMsg($WM_ERASEBKGND, "_WM_ERASEBKGND") GUIRegisterMsg($WM_DWMCOMPOSITIONCHANGED, "_WM_DWMCOMPOSITIONCHANGED") GUIRegisterMsg($WM_CTLCOLOREDIT, "_WM_CTLCOLOREDIT") _DrawTime() _SendMessage($hGUI, $WM_DWMCOMPOSITIONCHANGED) AdlibEnable("_DrawTime", 1000) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hBrush) _WinAPI_CloseThemeData($hTheme, $hUxTheme) GUIDelete() Exit Func _WM_CTLCOLOREDIT($hWnd, $iMsg, $iwParam, $ilParam)     Local $hDC = $iwParam     _WinAPI_SetTextColor($hDC, 0x00FFFF)     _WinAPI_SetBkColor($hDC, 0)     Return $hBrush EndFunc Func _DrawTime()     Local $hDC = _WinAPI_GetDC($hGUI)     Local $tClientRect = _WinAPI_GetClientRect($hGUI)     Local $tST = _Date_Time_GetLocalTime()     Local $sText = _Date_Time_SystemTimeToTimeStr($tST)     Local $hFont = _WinAPI_CreateFont(40, 15, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _         $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial Black') ; Edit as necessary.             DllStructSetData($tClientRect, "Top", 50)     _DrawGlowingText($hDC, $sText, $tClientRect, 10, $hFont, 0x0000aa) ; BGR, implementing RGB is easy.     _WinAPI_DeleteObject($hFont)     _WinAPI_ReleaseDC($hGUI, $hDC) EndFunc Func _WM_ERASEBKGND($hWnd, $iMsg, $iwParam, $ilParam)     Local $hDC = $iwParam     Local $tClientRect = _WinAPI_GetClientRect($hWnd)     Local $hBrush = _WinAPI_GetStockObject($BLACK_BRUSH)     _WinAPI_FillRect($hDC, DllStructGetPtr($tClientRect), $hBrush)     _WinAPI_DeleteObject($hBrush)         Return 1 EndFunc Func _WM_DWMCOMPOSITIONCHANGED($hWnd, $iMsg, $iwParam, $ilParam)     Local $tMargs = DllStructCreate($tagMARGINS)     If _WinAPI_DwmIsCompositionEnabled() Then         For $i = 1 To 4             DllStructSetData($tMargs, $i, -1)         Next         _WinAPI_DwmExtendFrameIntoClientArea($hWnd, $tMargs)     EndIf     Return 0 EndFunc Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)     If _WinAPI_HiWord($iwParam) = $EN_CHANGE Then         _WinAPI_InvalidateRect($hWnd, 0, False)         Return 0     EndIf         Return $GUI_RUNDEFMSG EndFunc Func _DrawGlowingText($hDC, $sText, $tRc, $iGlowSize = 10, $hFont = 0, $iTextClr = -1)     Local $hCDC     Local $hBrush, $hOldBrush     Local $tRcText     Local $tBI, $tDTO     Local $hDIBBmp, $hOldBmp     Local $hOldFont     Local $tST     Local $iFlags = BitOR($DTT_GLOWSIZE, $DTT_COMPOSITED)     $hCDC = _WinAPI_CreateCompatibleDC($hDC)     $tBI = DllStructCreate($tagBITMAPINFO)     DllStructSetData($tBI, "Size", DllStructGetSize($tBI)-4)     DllStructSetData($tBI, "Width", DllStructGetData($tRc, "Right")-DllStructGetData($tRc, "Left"))     DllStructSetData($tBI, "Height", -(DllStructGetData($tRc, "Bottom")-DllStructGetData($tRc, "Top")))     DllStructSetData($tBI, "Planes", 1)     DllStructSetData($tBI, "BitCount", 32)     DllStructSetData($tBI, "Compression", 0) ; BI_RGB     $hDIBBmp = _WinAPI_CreateDIBSection($hDC, $tBI)     $hOldBmp = _WinAPI_SelectObject($hCDC, $hDIBBmp)     If $hFont Then $hOldFont = _WinAPI_SelectObject($hCDC, $hFont)      $tDTO = DllStructCreate($tagDTTOPTS)     DllStructSetData($tDTO, "Size", DllStructGetSize($tDTO))     If $iTextClr <> -1 Then         $iFlags = BitOR($iFlags, $DTT_TEXTCOLOR)         DllStructSetData($tDTO, "clrText", $iTextClr)     EndIf     DllStructSetData($tDTO, "Flags", $iFlags)     DllStructSetData($tDTO, "GlowSize", $iGlowSize)     _WinAPI_DrawThemeTextEx($hTheme, $hCDC, 0, 0, $sText, _         BitOR($DT_SINGLELINE, $DT_CENTER, $DT_VCENTER, $DT_NOPREFIX), $tRc, $tDTO)     _WinAPI_BitBlt($hDC, DllStructGetData($tRc, "Left"), DllStructGetData($tRc, "Top"), _         DllStructGetData($tRc, "Right")-DllStructGetData($tRc, "Left"), _         DllStructGetData($tRc, "Bottom")-DllStructGetData($tRc, "Top"), $hCDC, 0, 0, 0xCC0020) ; SRCCOPY     _WinAPI_SelectObject($hCDC, $hOldBmp)     If $hFont Then _WinAPI_SelectObject($hCDC, $hOldFont)     _WinAPI_DeleteObject($hDIBBmp)     _WinAPI_DeleteDC($hCDC) EndFunc Func _WinAPI_DwmExtendFrameIntoClientArea($hWnd, ByRef $tMargins)     Local $aResult = DllCall("dwmapi.dll", "int", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($tMargins))     If @error Then Return SetError(@error, @extended, -1)     Return $aResult[0] EndFunc Func _WinAPI_DwmIsCompositionEnabled()     Local $aResult = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "int*", 0)     If @error Then Return SetError(@error, @extended, -1)     Return SetError($aResult[0], 0, $aResult[1]) EndFunc Func _WinAPI_DwmEnableBlurBehindWindow($hWnd, ByRef $tBlurBehind)     Local $aResult = DllCall("dwmapi.dll", "int", "DwmEnableBlurBehindWindow", "hwnd", $hWnd, "ptr", DllStructGetPtr($tBlurBehind))         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0] = 0) EndFunc Func _WinAPI_CreateDIBSection($hDC, Const ByRef $tBmpInfo, $iUsage = 0, $pBits = 0, $hSecond = 0, $iOffset = 0)     Local $aResult = DllCall("gdi32.dll", "hwnd", "CreateDIBSection", "hwnd", $hDC, "ptr", DllStructGetPtr($tBmpInfo), _                         "uint", $iUsage, "ptr", $pBits, "hwnd", $hSecond, "uint", $iOffset)     If @error Then Return SetError(@error, @extended, 0)     If $aResult[0] = 87 Then Return SetError(1, 1, 0); 87 = ERROR_INVALID_PARAMETER     If $aResult[0] = 0 Then Return SetError(1, 2, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_BeginPaint($hWnd, $pPaintStruct)     Local $aResult = DllCall("user32.dll", "hwnd", "BeginPaint", "hwnd", $hWnd, "ptr", $pPaintStruct)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_EndPaint($hWnd, $pPaintStruct)     Local $aResult = DllCall("user32.dll", "int", "EndPaint", "hwnd", $hWnd, "ptr", $pPaintStruct)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_DrawThemeTextEx($hTheme, $hDC, $iPartId, $iStateId, $sText, $iFlags, ByRef $tRect, Const ByRef $tDTTOPTS)     Local $aResult = DllCall("uxtheme.dll", "int", "DrawThemeTextEx", "ptr", $hTheme, "hwnd", $hDC, "int", $iPartId, "int", $iStateId, _                         "wstr", $sText, "int", -1, "uint", $iFlags, "ptr", DllStructGetPtr($tRect), "ptr", DllStructGetPtr($tDTTOPTS))     If @error Then Return SetError(@error, @extended, 0)     If $aResult[0] <> 0 Then Return SetError(1, 0, 0)     Return SetError(0, 0, $aResult[0] = 0) EndFunc Func _WinAPI_OpenThemeData($hWnd, $sClassList, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "hwnd", "OpenThemeData", "hwnd", $hWnd, "wstr", $sClassList)     If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_CloseThemeData($hTheme, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "CloseThemeData", "hwnd", $hTheme)     If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc   Func _WinAPI_BufferedPaintInit($hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "BufferedPaintInit")         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc Func _WinAPI_BufferedPaintUnInit($hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "BufferedPaintUnInit")         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc Func _WinAPI_BeginBufferedPaint($hDC, $pRc, $iBufferFormat, $pPaintParams ,ByRef $phDC, $hDll = "uxtheme.dll")     Local $tHDC = DllStructCreate("hwnd")     Local $aResult = DllCall($hDll, "hwnd", "BeginBufferedPaint", "hwnd", $hDC, "ptr", $pRc, "int", $iBufferFormat, "ptr", $pPaintParams, "ptr", DllStructGetPtr($tHDC))         If @error Then Return SetError(@error, @extended, 0)     $phDC = DllStructGetData($tHDC, 1)     Return SetError(0, 0, $aResult[0]) EndFunc Func _WinAPI_EndBufferedPaint($hPaintBuffer, $fUpdateTarget = True, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "EndBufferedPaint", "hwnd", $hPaintBuffer, "int", $fUpdateTarget)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc Func _WinAPI_BufferedPaintSetAlpha($hPaintBuffer, $pRc, $bAlpha = 255, $hDll = "uxtheme.dll")     Local $aResult = DllCall($hDll, "int", "BufferedPaintSetAlpha", "hwnd", $hPaintBuffer, "ptr", $pRc, "ubyte", $bAlpha)         If @error Then Return SetError(@error, @extended, 0)     Return SetError(0, $aResult[0], $aResult[0] = 0) EndFunc


I guess that Vista doesn't make it easy with the old GDI drawing controls. ::


Thanks alot for your answer :)
The first Method is realy complicated, and flickrs a little bit (sometimes it tooks some seconds until the text is black again).
The second Method is nice, but its hard to read anyway.
I founded out, that we dont need WM_CTLCOLOREDIT. It's very easy:
[ autoIt ]    ( Popup )
Global $Edit = GUICtrlCreateInput("Hello World",20,10,260,25) GUICtrlSetColor(-1,0xFFFFFF) GUICtrlSetBkColor(-1,0) GUICtrlSetFont(-1, 15, 500)

Same effect but much less code.

So. Does anybody now perhaps another method to draw black (or dark) Text in AutoIt Controls (like GuiCtrlCreateInput,Button,...)

Quote

I guess that Vista doesn't make it easy with the old GDI drawing controls. ::

I guess you're right ;-) Windows allways try to make it easy for devs. But why the heck not with Aero developing? ;P

Greetings,
Spdier

#24 User is offline   Vadersapien 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 131
  • Joined: 11-October 09
  • Gender:Male

Posted 02 December 2009 - 08:00 AM

A quick question...how would I make the text positioned from the top and not the center?

#25 User is online   Yashied 

  • Happy in Moscow
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 1,891
  • Joined: 01-November 08
  • Gender:Male
  • Location:The dark spiral galaxy

Posted 24 May 2010 - 08:16 PM

View PostGtaSpider, on 09 November 2009 - 08:16 PM, said:

Hey there,

Is there also a posibility to draw e.g. Inputs (GuiCtrlCreateInput) on Aero? So that black is not transparency? (I think we just have to set the Alpha Channel to 255 (0xFF000000).)
Any Ideas?

You can do the following trick.

[ autoIt ]    ( Popup )
#Include <WinAPIEx.au3> #Include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $hForm, $AlphaKey = 0xABABAB $hForm = GUICreate('MyGUI', 400, 400, -1, -1, -1, $WS_EX_LAYERED) GUISetBkColor($AlphaKey) GUICtrlCreateInput('Simple Text', 20, 20, 360, 19) GUICtrlCreateEdit('', 20, 47, 360, 200) GUICtrlCreateButton('OK', 165, 370, 70, 23) _WinAPI_SetLayeredWindowAttributes($hForm, $AlphaKey, 0, $LWA_COLORKEY) _WinAPI_DwmExtendFrameIntoClientArea($hForm) GUISetState() Do Until GUIGetMsg() = -3

A more complex example.

[ autoIt ]    ( ExpandCollapse - Popup )
#Include <GUIConstantsEx.au3> #Include <WinAPIEx.au3> #Include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Opt('WinWaitDelay', 0) Global Const $WM_NCXBUTTONDOWN = 0x00AB Global $hForm, $Area, $hDll, $pDll, $hHook, $AlphaKey = 0xABABAB OnAutoItExitRegister('OnAutoItExit') $hForm = GUICreate('MyGUI', 400, 400, -1, -1, -1, $WS_EX_LAYERED) GUISetBkColor($AlphaKey) $Area = GUICtrlCreateLabel('', 0, 0, 400, 400) GUICtrlSetBkColor(-1, $AlphaKey) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateInput('Simple Text', 20, 20, 360, 19) GUICtrlCreateEdit('', 20, 47, 360, 200) GUICtrlCreateButton('OK', 165, 370, 70, 23) _WinAPI_SetLayeredWindowAttributes($hForm, $AlphaKey, 0, $LWA_COLORKEY) _WinAPI_DwmExtendFrameIntoClientArea($hForm) $hDll = DllCallbackRegister('_MouseHook', 'ptr', 'int;wparam;lparam') $pDll = DllCallbackGetPtr($hDll) $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pDll, 0) GUISetState() Do Until GUIGetMsg() = -3 Func _MouseHook($iCode, $wParam, $lParam)     If $iCode > -1 Then         Switch $wParam             Case $WM_LBUTTONDOWN, $WM_MBUTTONDOWN, $WM_RBUTTONDOWN, $WM_XBUTTONDOWN, $WM_NCXBUTTONDOWN                 Local $Data = GUIGetCursorInfo($hForm)                 If (IsArray($Data)) And ($Data[4] = $Area) Then                     If Not BitAND(WinGetState($hForm), 8) Then                         WinActivate($hForm)                     EndIf                     Return -1                 EndIf         EndSwitch     EndIf     Return _WinAPI_CallNextHookEx($hHook, $iCode, $wParam, $lParam) EndFunc   ;==>_MouseHook Func OnAutoItExit()     _WinAPI_UnhookWindowsHookEx($hHook)     DllCallbackFree($hDll) EndFunc   ;==>OnAutoItExit

WinAPIEx.au3

Attached Image

This post has been edited by Yashied: 24 May 2010 - 08:22 PM


#26 User is offline   XxShadowxX 

  • Newbie
  • Group: Full Members
  • Posts: 6
  • Joined: 22-April 10

Posted 05 June 2010 - 07:07 PM

Hmm...your example doesn't work for me. I'm on Windows Vista (maybe the API changed between Vista and 7?) See attached.
Attached Image

#27 User is offline   MilesAhead 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 209
  • Joined: 12-January 08

Posted 18 August 2010 - 09:22 PM

View PostYashied, on 24 May 2010 - 03:16 PM, said:

You can do the following trick.


Thanks for this Yashied. I used your code and example to provide an alternative Gui option for 7 users.

On Vista Glass, or if the option is disabled on 7, the Gui looks like this:

http://www.favessoft.com/Selector.jpg

but if the 7 user enabled the .ini option it uses your code:

http://www.favessoft.com/SelectorTrans.jpg

edit: I kludged it to make the text easier to read. A little cheesy but maybe I'll find a better way later. :)

This post has been edited by MilesAhead: 18 August 2010 - 10:06 PM


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users