1. Windows Help - how to change text color of an edit field when it changes?

I am new to Windows programming, so I would like to know where to code the
following situation:

I have an edit control, and I want the text color to change if the user alters
that field. I tried the onChange (IDE class module for the event) (for
w32HChange) of the edit control. But it does not do anything. And if I place a
setText call for that control in the event handler, it crashes.

Andy Katz

B.S. Computer Science, 1978
Rensselaer Polytechnic Institute (RPI)

new topic     » topic index » view message » categorize

2. Re: Windows Help - how to change text color of an edit field when it changes?

Andrew Katz wrote:
> 
> I am new to Windows programming, so I would like to know where to code the
> following
> situation:
> 
> I have an edit control, and I want the text color to change if the user alters
> that field. I tried the onChange (IDE class module for the event) (for
> w32HChange)
> of the edit control. But it does not do anything. And if I place a setText
> call
> for that control in the event handler, it crashes.
> 
> Andy Katz
> 
> B.S. Computer Science, 1978
> Rensselaer Polytechnic Institute (RPI)

Andy,

The following worked for me:

--  code generated by Win32Lib IDE v0.20.1

 
include Win32Lib.ew
without warning

--------------------------------------------------------------------------------
--  Window Window1
constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300,
0, 0 )
constant EditText2 = createEx( EditText, "EditText2", Window1, 76, 64, 200, 20,
0, 0 )
---------------------------------------------------------
--------------------------------------------------------------------------------
sequence SomeTextInEdit

--------------------------------------------------------------------------------
procedure Window1_onActivate (integer self, integer event, sequence
params)--params is ()
  SomeTextInEdit = getText(EditText2)
end procedure
setHandler( Window1, w32HActivate, routine_id("Window1_onActivate"))
--------------------------------------------------------------------------------
procedure EditText2_onKeyPress (integer self, integer event, sequence
params)--params is ( int keyCode, int shift )
if params[1] = VK_RETURN and not equal(SomeTextInEdit,
    getText(EditText2))then
       setWindowBackColor(EditText2, Pink)
    end if
end procedure
setHandler( EditText2, w32HKeyPress, routine_id("EditText2_onKeyPress"))


WinMain( Window1,Normal )


Dan Moyer

new topic     » goto parent     » topic index » view message » categorize

3. Re: Windows Help - how to change text color of an edit field when it changes?

Andy,

and here is code example to do what you *actually* asked for, 
changing the color of the TEXT (but I'd think you'd prefer the other one,
changing the BACKGROUND color of the edit box, anyway); notice I had to use
RichEdit for color, and onKeyDown event and scancode 13 to trap enter key 
for richEdit, as opposed to onKeyPress for regular editbox.

--  code generated by Win32Lib IDE v0.20.1

 
include Win32Lib.ew
without warning

--------------------------------------------------------------------------------
--  Window Window1
constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300,
0, 0 )
constant EditText2 = createEx( EditText, "EditText2", Window1, 76, 64, 200, 20,
0, 0 )
constant RichEdit3 = createEx( RichEdit, "RichEdit3", Window1, 80, 92, 196, 28,
w32or_all({ES_NOHIDESEL}), 0 )
---------------------------------------------------------
--------------------------------------------------------------------------------
sequence SomeTextInEdit
sequence SomeTextInRichEdit
--------------------------------------------------------------------------------
procedure Window1_onActivate (integer self, integer event, sequence
params)--params is ()
  SomeTextInEdit = getText(EditText2)
  SomeTextInRichEdit = getStream(RichEdit3, StreamText)
end procedure
setHandler( Window1, w32HActivate, routine_id("Window1_onActivate"))
--------------------------------------------------------------------------------
procedure EditText2_onKeyPress (integer self, integer event, sequence
params)--params is ( int keyCode, int shift )
if params[1] = VK_RETURN and not equal(SomeTextInEdit,
    getText(EditText2))then
       setWindowBackColor(EditText2, Pink)
    end if
end procedure
setHandler( EditText2, w32HKeyPress, routine_id("EditText2_onKeyPress"))
--------------------------------------------------------------------------------
procedure RichEdit3_onKeyDown (integer self, integer event, sequence
params)--params is ( atom scanCode, atom shift )
if params[1] = 13 and not equal(SomeTextInRichEdit, getStream(RichEdit3,
    StreamText))then
       setFont(RichEdit3, {BrightRed, "Arial"},9, {"ALL", Normal})
       setIndex(RichEdit3, 1)
    end if
end procedure
setHandler( RichEdit3, w32HKeyDown, routine_id("RichEdit3_onKeyDown"))


WinMain( Window1,Normal )


Dan Moyer

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu