Re: One-click selection Edit Control problem
Instead of catching WM_LBUTTONDOWN catch WM_LBUTTONUP.
void CFocusEdit::OnLButtonUp(UINT nFlags, CPoint point)
{
CEdit::OnLButtonUp(nFlags, point);
if (!m_bFocusFlag)
{
SetSel(0, -1);
}
m_bFocusFlag = TRUE;
}
But let me mention that there is a flaw in this design. If the user tabs
into the edit control m_bFocusFlag remains false, and then the user edits
the content of the control, and if they click the mouse somewhere else in
the edit control, the control will select everything. I'm sure that is not
the intended function of that click!
AliR.
"Mikel" <mikel.luri@gmail.com> wrote in message
news:2a0247c6-3aee-46d0-b51f-0c4ba935f542@m44g2000hsc.googlegroups.com...
Hi,
In my app, I have a modeless dialog that shows the coordinates of a
line the user is editing with mouse/keyboard. The dialog also accepts
input, so the user can type the coordinates.
The dialog has several edit controls and I'd like to select the whole
text in them by just clicking once on them. I've found in
http://www.railjonrogut.com/ an example on how to do it. It's just by
handling OnLButtonDown and OnKillFocus, like this:
void CFocusEdit::OnLButtonDown(UINT nFlags, CPoint point)
{
CEdit::OnLButtonDown(nFlags, point);
if (!m_bFocusFlag)
{
SetSel(0, -1);
}
m_bFocusFlag = TRUE;
}
void CFocusEdit::OnEnKillfocus()
{
m_bFocusFlag = FALSE;
}
It works fine, except when the dialog doesn't have the focus and the
user clicks on an edit control. In that case, the dialog is activated
and the focus goes to the edit control but the text on it is not
always selected. It is only selected if the user clicks to the right
of the text. If he clicks on the text, it is selected from the start
to the point where the click happened. If he clicks to the left of the
text, the caret is placed before the first character and no text is
selected.
If the text were left aligned, most of the time it would work, but I
want the text right aligned, and I prefer it to work always, not "most
of the time".
Funnily (well, probably not so funnily), if I set a breakpoint in
OnLButtonDown, it does work. So I guess it has to do with the
Activation/Focus-changing process, but I don't know much about that
process, so, anyone knows how to handle this last case, or another way
to implement one-click selection in a way that also works in that
case?
Thanks in advance.
Mikel