Color of Edit and Text

Creating complex macros, dialogs, solving complex tasks, programming.

Color of Edit and Text

Postby boyonmoped on Sun Jun 08, 2008 3:48 am

okay i would like to know how to do 2 things

1.make the edit a color(just like where you type make that a color)

2.make where you type in an edit the text a color

I would really appreciate if anyone could help

Thanks
User avatar
boyonmoped
 
Posts: 86
Joined: Sat Jan 19, 2008 9:11 pm

Re: Color of Edit and Text

Postby Gintaras on Sun Jun 08, 2008 5:31 am

Function Dialog_edit_colors     ?
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str e3
e3="red text"
if(!ShowDialog("Dialog_edit_colors" &Dialog_edit_colors &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 145 99 "Form"
;1 Button 0x54030001 0x4 4 82 48 14 "OK"
;2 Button 0x54030000 0x4 56 82 48 14 "Cancel"
;3 Edit 0x54030080 0x204 8 38 128 16 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010601 "*" ""

ret
;messages
int textcolor=0xff
int backcolor=0x00ff00
int-- hbrush

sel message
,case WM_INITDIALOG
,hbrush=CreateSolidBrush(backcolor)
,
,ret 1
,case WM_DESTROY
,DeleteObject hbrush
,
,case WM_COMMAND goto messages2
,
,case WM_CTLCOLOREDIT
,if(lParam=id(3 hDlg))
,,SetTextColor wParam textcolor ;;text
,,SetBkMode wParam TRANSPARENT
,,ret hbrush ;;background
,;Similarly, you can use other WM_CTLCOLORx messages for other control classes and dialog itself.
,
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1



another example
Function Dialog_font_sample     ?
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;Shows how to set fonts and colors.

str controls = "6 3"
str lb6 e3
e3="Text"
lb6="item1[]item2"
if(!ShowDialog("Dialog_font_sample" &Dialog_font_sample &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 173 99 "Dialog Fonts"
;4 Static 0x54000000 0x4 10 22 48 14 "Text"
;6 ListBox 0x54230101 0x200 104 20 60 34 ""
;3 Edit 0x54030080 0x204 10 38 82 16 ""
;1 Button 0x54030001 0x4 4 82 48 14 "OK"
;2 Button 0x54030000 0x4 56 82 48 14 "Cancel"
;5 Button 0x54020007 0x4 4 6 166 54 "Text"
;END DIALOG
;DIALOG EDITOR: "" 0x2020103 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,__Font-- f
,f.Create("Courier New" 14 1)
,f.SetDialogFont(hDlg "3-5")
,f.SetDialogFontColor(hDlg 0xff0000 "3 4")
,
,__Font-- f2
,f2.Create("Comic Sans MS" 7 2)
,f2.SetDialogFont(hDlg "2")
,
,__Font-- f3
,f.SetDialogFontColor(hDlg 0x008000 "6")
,
,;note: __Font variables must not be local because they must exist while the dialog is open.
,;note: in a dialog, use different __Font variables for different fonts.

,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Color of Edit and Text

Postby boyonmoped on Sun Jun 08, 2008 2:47 pm

Thanks Gin

the first one with color edits works perfectly

but in the second one it errors on the first __Font--

it says unknown identifier

could you please fix it or tell me what to change?

should it be an int?

Thanks again bro
User avatar
boyonmoped
 
Posts: 86
Joined: Sat Jan 19, 2008 9:11 pm

Re: Color of Edit and Text

Postby boyonmoped on Sun Jun 08, 2008 3:05 pm

okay im trying to make one with multiple color edits
this is the code
but only the first one works
do you think you could please fix the code
thanks

\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3 4 8 9"
str e3 e4 si8 si9
si8="$qm$\findhtm.ico"
si9="$qm$\findhtm.ico"
if(!ShowDialog("TEST_COLOR" &TEST_COLOR &controls)) ret

BEGIN DIALOG
0 "" 0x90C80A44 0x100 0 0 169 95 "Logginer"
2 Button 0x54030000 0x4 114 70 48 14 "Close"
3 Edit 0x54030080 0x200 46 16 116 14 ""
4 Edit 0x54030080 0x200 46 44 116 14 ""
5 Static 0x54000000 0x0 32 18 48 12 "ID"
6 Static 0x54000000 0x0 12 46 48 12 "Password"
7 Static 0x54000000 0x0 20 72 74 10 "THIS IS A TEST"
8 Static 0x54000003 0x0 6 70 16 16 ""
9 Static 0x54000003 0x0 94 70 16 16 ""
END DIALOG
DIALOG EDITOR: "" 0x2020105 "" ""

ret
messages
int textcolor=0xFF
int background=0xF
int-- jbrush
if(message=WM_INITDIALOG) DT_Init(hDlg lParam)
int param=DT_GetParam(hDlg)

sel message
,case WM_INITDIALOG
,jbrush=CreateSolidBrush(background)
,ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2

,case WM_CTLCOLOREDIT
,if(lParam=id(3 hDlg))
,,SetTextColor wParam textcolor
,,SetBkMode wParam TRANSPARENT
,,ret jbrush

,case WM_CTLCOLOREDIT
,if(lParam=id(4 hDlg))
,,SetTextColor wParam textcolor
,,SetBkMode wParam TRANSPARENT
,,ret jbrush


ret
messages2
sel wParam
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
User avatar
boyonmoped
 
Posts: 86
Joined: Sat Jan 19, 2008 9:11 pm

Re: Color of Edit and Text

Postby Gintaras on Sun Jun 08, 2008 7:15 pm

don't need two "case WM_CTLCOLOREDIT". Just remove the second.

__Font has been added in some of recent QM versions. Your older QM version does not know what it is.
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Color of Edit and Text

Postby boyonmoped on Tue Jun 10, 2008 12:20 am

Thanks bro that worked perfectly

is there a way to just make the text color change and not even mess with the back ground

for example not even having the create brush or anything

Thanks
User avatar
boyonmoped
 
Posts: 86
Joined: Sat Jan 19, 2008 9:11 pm

Re: Color of Edit and Text

Postby Gintaras on Tue Jun 10, 2008 6:06 am

Not sure is it the best way but works. Replace

ret jbrush

to

ret COLOR_WINDOW+1

And remove all code where is used jbrush.
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Color of Edit and Text

Postby LyLerK on Wed May 13, 2009 3:21 pm

Is there a way to make this work dynamically? For example, if I click on a box, have it turn colored, but when I click on a second box, have the first box turn white again, and the second box turn colored?
LyLerK
 
Posts: 58
Joined: Sun Mar 20, 2005 12:11 am

Re: Color of Edit and Text

Postby Gintaras on Wed May 13, 2009 6:49 pm

replace

if(lParam=id(3 hDlg))

to

if(lParam=GetFocus)
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Color of Edit and Text

Postby r0n on Sat Sep 23, 2017 5:15 pm

When I have an colored background in an editfield, the text within that editfield becomes unreadable when it is being modified.

Example, put cursor somewhere within the asterisk and edit/modify the text.

Function tst_backgr     ?

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54231044 0x200 32 19 152 87 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

str controls = "3"
str e3="AAAA***AAAA"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
int textcolor=0x000000
int backcolor=0x00ffff
int-- hbrush
sel message
,case WM_INITDIALOG
,,hbrush=CreateSolidBrush(backcolor)
,case WM_DESTROY
,case WM_DESTROY
,,DeleteObject hbrush
,case WM_CTLCOLOREDIT
,,if(lParam=id(3 hDlg))
,,,SetTextColor wParam textcolor ;;text
,,,SetBkMode wParam TRANSPARENT
,,,ret hbrush ;;background
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1



EDIT:
Is there a redraw that must be done to avoid unreadable text?
r0n
Active Member
 
Posts: 495
Joined: Tue Jul 24, 2012 5:47 am

Re: Color of Edit and Text

Postby Gintaras on Sun Sep 24, 2017 6:35 pm

It seems multiline Edit controls don't redraw.
Replace

SetBkMode wParam TRANSPARENT

with

SetBkColor wParam backcolor
Gintaras
Site Admin
 
Posts: 10370
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: Color of Edit and Text

Postby r0n on Sun Sep 24, 2017 10:42 pm

Thank you! It works!
r0n
Active Member
 
Posts: 495
Joined: Tue Jul 24, 2012 5:47 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron