nend Posted September 24, 2014 Share Posted September 24, 2014 Hello, I've found a nice example in the helpfile "_WinAPI_DrawThemeTextEx" It works perfect but I'm trying for the last two days to change the text realtime. This code is very nice but a bit to difficult for me. is there anyone who can help me? This is the code from the "Autoit helpfile" expandcollapse popup#include <APIThemeConstants.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> #include <WinAPITheme.au3> #include <WindowsConstants.au3> If Not _WinAPI_DwmIsCompositionEnabled() Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Require Windows Vista or later with enabled Aero theme.') Exit EndIf OnAutoItExitRegister('OnAutoItExit') ; Create GUI Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 240, 240) GUICtrlCreateIcon(@ScriptDir & '\Extras\Soccer.ico', 0, 88, 68, 64, 64) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel('', 70, 130, 100, 30) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetState(-1, $GUI_DISABLE) Global $g_hLabel = GUICtrlGetHandle(-1) GUISetBkColor(0) ; Register label window proc Global $g_hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam') Local $pDll = DllCallbackGetPtr($g_hDll) Global $g_hProc = _WinAPI_SetWindowLong($g_hLabel, $GWL_WNDPROC, $pDll) ; Create the "sheet of glass" effect for the entire window. You must call this function whenever DWM composition is toggled. _WinAPI_DwmExtendFrameIntoClientArea($hForm) GUISetState(@SW_SHOW) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _DrawText($hDC, $sText, $tRECT) ; Original idea by Authenticity Local $iWidth = DllStructGetData($tRECT, 3) - DllStructGetData($tRECT, 1) Local $iHeight = DllStructGetData($tRECT, 4) - DllStructGetData($tRECT, 2) Local $tDTTOPTS = DllStructCreate($tagDTTOPTS) DllStructSetData($tDTTOPTS, 'Size', DllStructGetSize($tDTTOPTS)) DllStructSetData($tDTTOPTS, 'Flags', BitOR($DTT_TEXTCOLOR, $DTT_GLOWSIZE, $DTT_COMPOSITED)) DllStructSetData($tDTTOPTS, 'clrText', 0x0000C0) DllStructSetData($tDTTOPTS, 'GlowSize', 12) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateDIB($iWidth, -$iHeight) Local $hSv1 = _WinAPI_SelectObject($hMemDC, $hBitmap) Local $hFont = _WinAPI_CreateFont(26, 0, 0, 0, $FW_NORMAL, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Segoe Script') Local $hSv2 = _WinAPI_SelectObject($hMemDC, $hFont) $tRECT = _WinAPI_CreateRect(0, 0, $iWidth, $iHeight) Local $hTheme = _WinAPI_OpenThemeData($hForm, 'Globals') _WinAPI_DrawThemeTextEx($hTheme, 0, 0, $hMemDC, $sText, $tRECT, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER), $tDTTOPTS) _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hMemDC, 0, 0, $SRCCOPY) _WinAPI_CloseThemeData($hTheme) _WinAPI_SelectObject($hMemDC, $hSv1) _WinAPI_DeleteObject($hBitmap) _WinAPI_SelectObject($hMemDC, $hSv2) _WinAPI_DeleteObject($hFont) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>_DrawText Func _WinProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_PAINT Local $tPAINTSTRUCT Local $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT) _DrawText($hDC, 'Soccer', _WinAPI_GetClientRect($hWnd)) _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT) Return 0 EndSwitch Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc Func OnAutoItExit() _WinAPI_SetWindowLong($g_hLabel, $GWL_WNDPROC, $g_hProc) DllCallbackFree($g_hDll) EndFunc ;==>OnAutoItExit Link to comment Share on other sites More sharing options...
Solution UEZ Posted September 24, 2014 Solution Share Posted September 24, 2014 Try this: expandcollapse popup#include <APIThemeConstants.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> #include <WinAPITheme.au3> #include <WindowsConstants.au3> If Not _WinAPI_DwmIsCompositionEnabled() Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Require Windows Vista or later with enabled Aero theme.') Exit EndIf OnAutoItExitRegister('OnAutoItExit') ; Create GUI Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 240, 240) GUICtrlCreateIcon('c:\Program Files (x86)\AutoIt3\Examples\Helpfile\Extras\Soccer.ico', 0, 88, 68, 64, 64) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel('', 0, 130, 240, 30, 0x201) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetState(-1, $GUI_DISABLE) Global $g_hLabel = GUICtrlGetHandle(-1) GUISetBkColor(0) Global $sT = 'Soccer' ; Register label window proc Global $g_hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam') Local $pDll = DllCallbackGetPtr($g_hDll) Global $g_hProc = _WinAPI_SetWindowLong($g_hLabel, $GWL_WNDPROC, $pDll) ; Create the "sheet of glass" effect for the entire window. You must call this function whenever DWM composition is toggled. _WinAPI_DwmExtendFrameIntoClientArea($hForm) GUISetState(@SW_SHOW) Sleep(1000) $sT = 'makes me happy' _WinAPI_RedrawWindow($hForm) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _DrawText($hDC, $sText, $tRECT) ; Original idea by Authenticity Local $iWidth = DllStructGetData($tRECT, 3) - DllStructGetData($tRECT, 1) Local $iHeight = DllStructGetData($tRECT, 4) - DllStructGetData($tRECT, 2) Local $tDTTOPTS = DllStructCreate($tagDTTOPTS) DllStructSetData($tDTTOPTS, 'Size', DllStructGetSize($tDTTOPTS)) DllStructSetData($tDTTOPTS, 'Flags', BitOR($DTT_TEXTCOLOR, $DTT_GLOWSIZE, $DTT_COMPOSITED)) DllStructSetData($tDTTOPTS, 'clrText', 0x0000C0) DllStructSetData($tDTTOPTS, 'GlowSize', 12) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateDIB($iWidth, -$iHeight) Local $hSv1 = _WinAPI_SelectObject($hMemDC, $hBitmap) Local $hFont = _WinAPI_CreateFont(26, 0, 0, 0, $FW_NORMAL, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, 'Segoe Script') Local $hSv2 = _WinAPI_SelectObject($hMemDC, $hFont) $tRECT = _WinAPI_CreateRect(0, 0, $iWidth, $iHeight) Local $hTheme = _WinAPI_OpenThemeData($hForm, 'Globals') _WinAPI_DrawThemeTextEx($hTheme, 0, 0, $hMemDC, $sText, $tRECT, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER), $tDTTOPTS) _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hMemDC, 0, 0, $SRCCOPY) _WinAPI_CloseThemeData($hTheme) _WinAPI_SelectObject($hMemDC, $hSv1) _WinAPI_DeleteObject($hBitmap) _WinAPI_SelectObject($hMemDC, $hSv2) _WinAPI_DeleteObject($hFont) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>_DrawText Func _WinProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_PAINT Local $tPAINTSTRUCT Local $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT) _DrawText($hDC, $sT, _WinAPI_GetClientRect($hWnd)) _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT) Return 0 EndSwitch Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc Func OnAutoItExit() _WinAPI_SetWindowLong($g_hLabel, $GWL_WNDPROC, $g_hProc) DllCallbackFree($g_hDll) EndFunc ;==>OnAutoItExit Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
nend Posted September 24, 2014 Author Share Posted September 24, 2014 (edited) Thanks UEZ, This works perfect. Thank, now I can proceed with my project. Edited September 24, 2014 by nend Link to comment Share on other sites More sharing options...
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