One-click selection Edit Control problem
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