Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change color of static/edit using: SetTextColor and SetBkMode
#1
I noticed when using "DT_SetTextColor" the dialog is refreshed completely thus giving that short redraw effect (at least in my dialog).

My dialog is a folder browser using a listbox, certain filetypes get colored differently (rtf = purple, txt=black, doc=blue ,....)
The problem is that every time a file-item is clicked within the listbox the whole dialog refreshes (you can see the dialog refresh itself, it's very fast but still noticeable)

I cloned the items within "DT_SetTextColor" and then disabled the last line:
if(IsWindowVisible(hDlg)) InvalidateRect hDlg 0 1

And then it all worked without the refresh effect.

But for now I wanted know how to use "SetTextColor and SetBkMode" in the below example.
Using "SetTextColor and SetBkMode" I could then decide how to do the refresh if it's still needed.
Probably this should work also then: RedrawWindow(###CONTROL_ID### 0 0 RDW_INVALIDATE)

What I have below doesn't work but any example of how to do it is greatly appreciated.
(I have a way of doing this with the background color, there are examples of that ,but I can't get the textcolor method working...)

(The editfield and static needs to change color on buttonpress.)

Function change_txt_color_on_buttonpress
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 95 80 48 14 "Button"
;4 Edit 0x54231044 0x200 30 10 152 22 ""
;5 Static 0x54000000 0x0 90 40 48 12 "TEST"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "4"
str e4="TEST"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,,GdiObject-- brush1=CreateSolidBrush(ColorFromRGB(240 240 100))
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_CTLCOLOREDIT goto messages2

ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3
,;,;;; ?
,,;SetBkMode wParam TRANSPARENT
,,;SetTextColor wParam ColorFromRGB(0 0 255)
,,;ret brush1
ret 1
#2
This seems to work but is it possible to preserve the transparency of the static control?

Function change_txt_color_on_buttonpress
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 95 80 48 14 "Button"
;4 Edit 0x54231044 0x200 30 10 152 22 ""
;5 Static 0x54000000 0x0 90 40 48 12 "TEST"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "4"
str e4="TEST"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
__GdiHandle- t_hbrush
sel message
,case WM_INITDIALOG
,,int backcolor_at_start=0xffffff
,,t_hbrush=CreateSolidBrush(backcolor_at_start)
,,int- col_1;col_1=ColorFromRGB(255 10 120)
,,int- col_2;col_2=ColorFromRGB(0 110 120) ;; NEW COLOR
,case WM_DESTROY
,,t_hbrush.Delete
,case WM_COMMAND goto messages2
,case [WM_CTLCOLORSTATIC,WM_CTLCOLOREDIT] ;; WM_CTLCOLORLISTBOX not used in this example
,,if(lParam=id(4 hDlg))
,,,SetBkMode wParam TRANSPARENT
,,,SetTextColor wParam col_1
,,,ret t_hbrush
,,if(lParam=id(5 hDlg))
,,,SetBkMode wParam TRANSPARENT
,,,SetTextColor wParam col_1
,,,ret t_hbrush
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3
,,col_1=col_2        
,,RedrawWindow(id(4 hDlg) 0 0 RDW_INVALIDATE) ;; redraw control editfield
,,RedrawWindow(id(5 hDlg) 0 0 RDW_INVALIDATE) ;; redraw control statc
,,ret t_hbrush
ret 1
#3
for the static control don't return t_hbrush
instead use
Code:
Copy      Help
ret GetStockObject(NULL_BRUSH)

i edited your code a little removed unneeded parts

Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 95 80 48 14 "Button"
;4 Edit 0x54231044 0x200 30 10 152 22 ""
;5 Static 0x54000000 0x0 90 40 48 12 "TEST"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "4"
str e4="TEST"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
__GdiHandle- t_hbrush
sel message
,case WM_INITDIALOG
,int backcolor_at_start=0xffffff
,t_hbrush=CreateSolidBrush(backcolor_at_start)
,int- col_1;col_1=ColorFromRGB(255 10 120)
,int- col_2;col_2=ColorFromRGB(0 110 120) ;; NEW COLOR
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case [WM_CTLCOLORSTATIC,WM_CTLCOLOREDIT] ;; WM_CTLCOLORLISTBOX not used in this example
,if(lParam=id(4 hDlg))
,,SetBkMode wParam TRANSPARENT
,,SetTextColor wParam col_1
,,ret t_hbrush
,if(lParam=id(5 hDlg))
,,SetBkMode wParam TRANSPARENT
,,SetTextColor wParam col_1
,,ret GetStockObject(NULL_BRUSH)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3
,,col_1=col_2
,,RedrawWindow(id(4 hDlg) 0 0 RDW_INVALIDATE) ;; redraw control editfield
,,RedrawWindow(id(5 hDlg) 0 0 RDW_INVALIDATE) ;; redraw control statc
ret 1
#4
Thanks!!!
#5
after taking another look at this 

these lines can be eliminated
__GdiHandle- t_hbrush
int backcolor_at_start=0xffffff
,t_hbrush=CreateSolidBrush(backcolor_at_start)

and instead use 
Code:
Copy      Help
ret GetStockObject(DC_BRUSH)
for the edit control

full code
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Button 0x54032000 0x0 95 80 48 14 "Button"
;4 Edit 0x54231044 0x200 30 10 152 22 ""
;5 Static 0x54000000 0x0 90 40 48 12 "TEST"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "4"
str e4="TEST"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,int- col_1;col_1=ColorFromRGB(255 10 120)
,int- col_2;col_2=ColorFromRGB(0 110 120) ;; NEW COLOR
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case [WM_CTLCOLORSTATIC,WM_CTLCOLOREDIT] ;; WM_CTLCOLORLISTBOX not used in this example
,if(lParam=id(4 hDlg))
,,SetBkMode wParam TRANSPARENT
,,SetTextColor wParam col_1
,,ret GetStockObject(DC_BRUSH)
,if(lParam=id(5 hDlg))
,,SetBkMode wParam TRANSPARENT
,,SetTextColor wParam col_1
,,ret GetStockObject(NULL_BRUSH)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3
,col_1=col_2
,RedrawWindow(id(4 hDlg) 0 0 RDW_INVALIDATE) ;; redraw control editfield
,RedrawWindow(id(5 hDlg) 0 0 RDW_INVALIDATE) ;; redraw control statc
ret 1
#6
Thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)