Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Edit Control read only mode.

76 views
Skip to first unread message

pj

unread,
Jun 6, 2007, 7:55:20 PM6/6/07
to
Hi,

I have this edit control in a dialog which I want in a read only mode.
In my program, I set the text in this control. But frustrating thing
is, the text is always highligted when the dialog shows up. Is there
any way to clear this highlighting?

Also, is there a way to keep the background white even if it is
readonly?

Thanks,
-PJ

Jeff Partch

unread,
Jun 6, 2007, 8:02:40 PM6/6/07
to
"pj" <pran...@gmail.com> wrote in message
news:1181174120.3...@a26g2000pre.googlegroups.com...

> Hi,
>
> I have this edit control in a dialog which I want in a read only mode.
> In my program, I set the text in this control. But frustrating thing
> is, the text is always highligted when the dialog shows up. Is there
> any way to clear this highlighting?

In your OnInitDialog handler shift the focus to another control, or in a
CEdit subclass handle WM_GETDLGCODE and don't return the DLGC_HASSETSEL
flag.

>
> Also, is there a way to keep the background white even if it is
> readonly?
>

Handle its WM_CTLCOLORSTATIC.

--
Jeff Partch [VC++ MVP]

Joseph M. Newcomer

unread,
Jun 6, 2007, 10:49:46 PM6/6/07
to
One way is to avoid this is to SetFocus yourself and return FALSE from OnInitDialog.
Another is to not make it the first control in tab order.

The business of setting select-all when focus is received is one of the continuous
annoyances of edit controls. I'm sure that someone, somewhere, actually likes this
feature, but I have yet to find that person.. Mostly it is just annoying.

One way is to subclass it, and in the subclass add an OnSetFocus handler, do a PostMessage
of a user-defined message which then does a SetSel to 0,0.

Using a reflected =WM_CTLCOLOR handler would solve the problem, but it is likely to annoy
the user because the white appearance will suggest the control is active. OTOH, you can
make it a less objectionable shade of gray.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Tom Serface

unread,
Jun 7, 2007, 2:16:44 AM6/7/07
to
You may want to change it to a static control (with an ID other than
IDC_STATIC). You could still assign a value to it like any other control,
it just would never get focus and wouldn't look like a user could type
anything into the control. I use this a lot for showing read only data.

Tom

"pj" <pran...@gmail.com> wrote in message
news:1181174120.3...@a26g2000pre.googlegroups.com...

AliR (VC++ MVP)

unread,
Jun 7, 2007, 3:21:27 AM6/7/07
to
Here is an example of a white read only edit I did a while ago:
http://www.learnstar.com/AliR/EditReadOnly.zip

AliR.


"pj" <pran...@gmail.com> wrote in message
news:1181174120.3...@a26g2000pre.googlegroups.com...

Alexander Grigoriev

unread,
Jun 7, 2007, 11:43:39 AM6/7/07
to
One can do copy from read-only edit control, which is very handy sometimes.

"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:OHYewtMq...@TK2MSFTNGP05.phx.gbl...

Joseph M. Newcomer

unread,
Jun 7, 2007, 2:23:45 PM6/7/07
to
I have taken to adding read-only edit controls instead of static controls in situations
where I want the ability to highlight and copy text.
joe

Unknown

unread,
Jun 7, 2007, 3:02:34 PM6/7/07
to
On Wed, 06 Jun 2007 23:55:20 -0000, pj wrote:

>Also, is there a way to keep the background white even if it is
>readonly?

http://bobmoore.mvps.org/Win32/w32tip45.htm

--
Bob Moore
http://bobmoore.mvps.org/
(this is a non-commercial site and does not accept advertising)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tom Serface

unread,
Jun 7, 2007, 4:34:43 PM6/7/07
to
Good point. I still find the read only thing annoying since it almost
implies the text could be edited, but I guess if it's precluded from getting
focus that would help a great deal.

Tom

"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:%23XRZeqR...@TK2MSFTNGP02.phx.gbl...

0 new messages