Vadersapien Posted November 11, 2009 Author Posted November 11, 2009 Got the text positioned...but...say my _DrawTime() function is like this: 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: DllStructSetData($tClientRect, "Top", 76) It works, but leaves a big white rectangle at the top...any idea why? Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
Authenticity Posted November 11, 2009 Posted November 11, 2009 (edited) 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: 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 Edited November 11, 2009 by Authenticity
GtaSpider Posted November 11, 2009 Posted November 11, 2009 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: 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: 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: 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,...) 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 www.AutoIt.de - Moderator of the German AutoIt Forum Â
Vadersapien Posted December 2, 2009 Author Posted December 2, 2009 A quick question...how would I make the text positioned from the top and not the center? Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
Yashied Posted May 24, 2010 Posted May 24, 2010 (edited) 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. #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. 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 Edited May 24, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
XxShadowxX Posted June 5, 2010 Posted June 5, 2010 Hmm...your example doesn't work for me. I'm on Windows Vista (maybe the API changed between Vista and 7?) See attached.
MilesAhead Posted August 18, 2010 Posted August 18, 2010 (edited) 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.jpgbut if the 7 user enabled the .ini option it uses your code:http://www.favessoft.com/SelectorTrans.jpgedit: I kludged it to make the text easier to read. A little cheesy but maybe I'll find a better way later. Edited August 18, 2010 by MilesAhead My Freeware Page
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