Chefito Posted July 2, 2008 Share Posted July 2, 2008 Hello people. How do I change the color of the control Edit (background color), and the size and color of the font in a control Edit created with the function _GUICtrlEdit_Create? Thank you. Link to comment Share on other sites More sharing options...
Zedna Posted July 2, 2008 Share Posted July 2, 2008 1) use RichEdit control (search forum for some not finished UDFs)2) use subclassing with DllCallBack UDF (see subclass example) : http://www.autoitscript.com/forum/index.php?showtopic=50768 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Chefito Posted July 2, 2008 Author Share Posted July 2, 2008 Wow, very pretty . I Look up the RichEdit. Picasso is a machine . Thank you very much. Link to comment Share on other sites More sharing options...
Valuater Posted July 2, 2008 Share Posted July 2, 2008 (edited) A simpler approach...http://www.autoitscript.com/forum/index.ph...st&p=425262*** XSkin is not required8) Edited July 2, 2008 by Valuater Link to comment Share on other sites More sharing options...
rasim Posted July 3, 2008 Share Posted July 3, 2008 Another simpler approach: #include <GuiConstantsEx.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> GUICreate("Test", 300, 200) $edit = GUICtrlCreateEdit("Hello world!", 10, 10, 280, 180) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetBkColor(-1, 0x9BFF9B) GUICtrlSetState(-1, $GUI_FOCUS) _SetFont(GUICtrlGetHandle($edit), 12, 800, 2, "Arial") GUISetState() Do Until GUIGetMsg() = -3 Func _SetFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont) Local $hDc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) Local $nPixel = DllCall("gdi32.dll", "int", "GetDeviceCaps", "hwnd", $hDc[0], "int", $LOGPIXELSY) Local $nHeight = DllCall("kernel32.dll", "int", "MulDiv", "int", $nFontSize, "int", $nPixel[0], "int", 72) Local $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $nHeight[0], "int", 0, _ "int", 0, "int", 0, "int", $nFontWeight, "dword", BitAND($nFontAtrribute, 2), _ "dword", BitAND($nFontAtrribute, 4), "dword", BitAND($nFontAtrribute, 8), "int", $DEFAULT_CHARSET, _ "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _ "str", $nFont) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $WM_SETFONT, "int", $hFont[0], "int", 1) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDc[0]) DllCall("user32.dll", "int", "DeleteObject", "hwnd", $hFont[0]) EndFunc muttley Link to comment Share on other sites More sharing options...
Zedna Posted July 3, 2008 Share Posted July 3, 2008 Another simpler approach:Nice example rasim!! Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Chefito Posted July 4, 2008 Author Share Posted July 4, 2008 Thank you all for your responses. Especially to rasim. That function is what needed. Very good work rasim. You have me saved muttley Link to comment Share on other sites More sharing options...
Chefito Posted July 5, 2008 Author Share Posted July 5, 2008 (edited) Hi again. I tested this code and does not work the backcolor control and the color of font: #include <GuiConstantsEx.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #Include <GuiEdit.au3> $gui=GUICreate("Test", 300, 200) $edit = _GUICtrlEdit_Create($gui,"Hello world!", 10, 10, 280, 180) GUICtrlSetColor(-1, 0xFF0000);not work GUICtrlSetBkColor(-1, 0x9BFF9B);not work _SetFont($edit, 16, 800, 2, "Arial") GUISetState() Do Until GUIGetMsg() = -3 Func _SetFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont) Local $hDc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) Local $nPixel = DllCall("gdi32.dll", "int", "GetDeviceCaps", "hwnd", $hDc[0], "int", $LOGPIXELSY) Local $nHeight = DllCall("kernel32.dll", "int", "MulDiv", "int", $nFontSize, "int", $nPixel[0], "int", 72) Local $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $nHeight[0], "int", 0, _ "int", 0, "int", 0, "int", $nFontWeight, "dword", BitAND($nFontAtrribute, 2), _ "dword", BitAND($nFontAtrribute, 4), "dword", BitAND($nFontAtrribute, 8), "int", $DEFAULT_CHARSET, _ "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _ "str", $nFont) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $WM_SETFONT, "int", $hFont[0], "int", 1) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDc[0]) DllCall("user32.dll", "int", "DeleteObject", "hwnd", $hFont[0]) EndFunc This only works with the function GUICtrlCreateEdit (controlID). Is there a way to solve this? Did you call SendMessage? How? My problem is I made a counter that looked very fast in a control label, but failed the refresh, and saw a flickering effect. This happened with the function GUICtrlCreateLabel and with the function GUICtrlCreateEdit, but it don´t happen with _GUICtrlEdit_Create. Another thing, can we create a control label with apis? It is this option in the UDF. If this can not with a control label, this will do with a control Edit blocked. thanks. Edited July 5, 2008 by Chefito Link to comment Share on other sites More sharing options...
rasim Posted July 6, 2008 Share Posted July 6, 2008 (edited) ChefitoTry this:expandcollapse popup#include <FontConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> $hGUI = GUICreate("Test", 300, 200) $hEdit = _GUICtrlEdit_Create($hGUI, "Hello world!", 10, 10, 280, 180) _SetFont($hEdit, 12, 800, 2, "Arial") GUIRegisterMsg($WM_CTLCOLOREDIT, "WM_CTLCOLOREDIT") GUISetState() Do Until GUIGetMsg() = -3 Func _SetFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont) Local $hDc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) Local $nPixel = DllCall("gdi32.dll", "int", "GetDeviceCaps", "hwnd", $hDc[0], "int", $LOGPIXELSY) Local $nHeight = DllCall("kernel32.dll", "int", "MulDiv", "int", $nFontSize, "int", $nPixel[0], "int", 72) Local $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $nHeight[0], "int", 0, _ "int", 0, "int", 0, "int", $nFontWeight, "dword", BitAND($nFontAtrribute, 2), _ "dword", BitAND($nFontAtrribute, 4), "dword", BitAND($nFontAtrribute, 8), "int", $DEFAULT_CHARSET, _ "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _ "str", $nFont) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $WM_SETFONT, "int", $hFont[0], "int", 1) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDc[0]) DllCall("user32.dll", "int", "DeleteObject", "hwnd", $hFont[0]) EndFunc Func WM_CTLCOLOREDIT($hWnd, $Msg, $wParam, $lParam) DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $wParam, "int", 0xFF0000) DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $wParam, "int", 0x0000FF) Return True EndFuncEdit: also you may to use GUICtrlCreateEdit() function with GuiEdit.au3 UDF functions. Edited July 6, 2008 by rasim Link to comment Share on other sites More sharing options...
Chefito Posted July 10, 2008 Author Share Posted July 10, 2008 Forgive it has taken so long to respond. Thank you for your reply. It is very interesting. But is not exactly what I want. Do not paint the background of control, only the background of the text. And moreover, affects all edit controls. I think I'll have to watch the GuiEdit.au3 UDF functions. Thank you very much. Link to comment Share on other sites More sharing options...
rasim Posted July 11, 2008 Share Posted July 11, 2008 Chefito Do not paint the background of control, only the background of the text.OK! Try this: expandcollapse popup#include <FontConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> Global Const $TRANSPARENT = 1 $hGUI = GUICreate("Test", 300, 200) $hEdit = _GUICtrlEdit_Create($hGUI, "", 10, 10, 280, 180) _SetFont($hEdit, 12, 800, 1, "MS Sans Serif") GUIRegisterMsg($WM_CTLCOLOREDIT, "WM_CTLCOLOREDIT") GUISetState() Do Until GUIGetMsg() = -3 Func _SetFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont) Local $hDc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) Local $nPixel = DllCall("gdi32.dll", "int", "GetDeviceCaps", "hwnd", $hDc[0], "int", $LOGPIXELSY) Local $nHeight = DllCall("kernel32.dll", "int", "MulDiv", "int", $nFontSize, "int", $nPixel[0], "int", 72) Local $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $nHeight[0], "int", 0, _ "int", 0, "int", 0, "int", $nFontWeight, "dword", BitAND($nFontAtrribute, 2), _ "dword", BitAND($nFontAtrribute, 4), "dword", BitAND($nFontAtrribute, 8), "int", $DEFAULT_CHARSET, _ "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _ "str", $nFont) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $WM_SETFONT, "int", $hFont[0], "int", 1) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDc[0]) DllCall("user32.dll", "int", "DeleteObject", "hwnd", $hFont[0]) EndFunc Func WM_CTLCOLOREDIT($hWnd, $Msg, $wParam, $lParam) Switch $lParam Case $hEdit DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $wParam, "int", $TRANSPARENT) DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $wParam, "int", 0x0000FF) $aResult = DllCall("GDI32.dll", "hwnd", "GetStockObject", "int", 0) Return $aResult[0] EndSwitch Return "GUI_RUNDEFMSG" EndFunc Link to comment Share on other sites More sharing options...
Chefito Posted July 11, 2008 Author Share Posted July 11, 2008 (edited) Nothing. It does not work the background color control Edit. I have done this, but the refresh is bad. It seems that it is a great defect of AutoIt. expandcollapse popup#include <FontConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <winapi.au3> #include <GuiConstantsEx.au3> $hGUI = GUICreate("Test", 300, 200) GUISetBkColor(0x0a0a0a) $hEdit = _GUICtrlEdit_Create($hGUI, "", 10, 10, 100, 24,$ES_MULTILINE+$ES_READONLY+$ES_CENTER,0) ;ControlDisable("Test","","Edit1") _SetFont($hEdit, 18, 800, 1, "MS Sans Serif") GUIRegisterMsg($WM_CTLCOLORSTATIC, "WM_CTLCOLORSTATIC") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() ;_GUICtrlEdit_SetText($hEdit,"0") Global $cont=0 Do Sleep(30) _GUICtrlEdit_SetText($hEdit,$cont) $cont=$cont+1 Until GUIGetMsg() = -3 Func _SetFont($hWnd, $nFontSize, $nFontWeight, $nFontAtrribute, $nFont) Local $hDc = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", $hWnd) Local $nPixel = DllCall("gdi32.dll", "int", "GetDeviceCaps", "hwnd", $hDc[0], "int", $LOGPIXELSY) Local $nHeight = DllCall("kernel32.dll", "int", "MulDiv", "int", $nFontSize, "int", $nPixel[0], "int", 72) Local $hFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $nHeight[0], "int", 0, _ "int", 0, "int", 0, "int", $nFontWeight, "dword", BitAND($nFontAtrribute, 2), _ "dword", BitAND($nFontAtrribute, 4), "dword", BitAND($nFontAtrribute, 8), "int", $DEFAULT_CHARSET, _ "int", $OUT_DEFAULT_PRECIS, "int", $CLIP_DEFAULT_PRECIS, "int", $DEFAULT_QUALITY, "int", 0, _ "str", $nFont) DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $WM_SETFONT, "int", $hFont[0], "int", 1) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "hwnd", $hDc[0]) DllCall("user32.dll", "int", "DeleteObject", "hwnd", $hFont[0]) EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit) $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) Switch $hWndFrom Case $hEdit, $hWndEdit Switch $iCode Case $EN_SETFOCUS; Sent when an edit control receives the keyboard focus _WinAPI_SetFocus($hGUI) ; no return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc;==>WM_COMMAND Func WM_CTLCOLORSTATIC($hWnd, $Msg, $wParam, $lParam) Switch $lParam Case $hEdit SetTextColor($wParam,0x00ff00) SetBkColor($wParam,0xff0000) Return 1 EndSwitch Return $GUI_RUNDEFMSG EndFunc Func SetBkColor($hDC, $nColor) $h=_WinAPI_SetBkColor($hDC,$nColor) Return $h EndFunc Func SetTextColor($hDC, $nColor) $h=_WinAPI_SetTextColor($hDC,$nColor) Return $h EndFunc Overall, I'm having a lot of problems with the refresh of the gui. In my program, when I load a page web, It do a small flickering the window (disappears for a moment). My code is very big. It may be by this. I don´t Know. I load the page web in a control IE. Edited July 11, 2008 by Chefito 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