15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Q: CEdit control tabbing

Karen Fura -- kfura@pop.seanet.com
Thursday, September 19, 1996

Environment: Windows 95, MSVC 4.1, MFC

My objective is to create a dialog with
some simple single-line edit fields whose
text is selected whether the user tabs to
a field or a field is clicked on with
the mouse.  The tabbing works fine, that is
when a field is tabbed to the text is selected.  
This happens without any programming.  To 
facilitate the selecting of text on a mouse click, 
I wrote a tiny handler called when the focus is received 
( ON_EN_SETFOCUS ).  The text is not selected when 
this handler completes.  But I CAN select the text 
elsewhere in the code, not in the setfocus handler.

This is probably something trivial but I cannot 
find it.  If anyone could point me to a code
example or information in MSDN, I would be
very thankful.

My handler follows.


Karen Fura


// always show text selected when focus received.
void CMyDlg::OnSetfocusArchEdit() 
{
    CEdit* pEditArchName = (CEdit*) GetDlgItem(IDC_ARCH_EDIT);
    pEditArchName->SetSel ( 0, -1 );
}


 




Mike Blaszczak -- mikeblas@nwlink.com
Sunday, September 22, 1996

[Mini-digest: 2 responses]

At 05:12 PM 9/19/96 -0700, Karen Fura wrote:
>Environment: Windows 95, MSVC 4.1, MFC

>My objective is to create a dialog with
>some simple single-line edit fields whose
>text is selected whether the user tabs to
>a field or a field is clicked on with
>the mouse.  The tabbing works fine, that is
>when a field is tabbed to the text is selected.  
>This happens without any programming.  To 
>facilitate the selecting of text on a mouse click, 
>I wrote a tiny handler called when the focus is received 
>( ON_EN_SETFOCUS ).  The text is not selected when 
>this handler completes.  But I CAN select the text 
>elsewhere in the code, not in the setfocus handler.

You'll need to do this by subclassing the edit control
and reacting to the mouse messages.  When the user clicks
on the mouse, the control gets focus (and a set focus message)
and _then_ the selection is set.

.B ekiM
http://www.nwlink.com/~mikeblas/
Don't look at my hands: look at my _shoulders_!
These words are my own. I do not speak on behalf of Microsoft.

-----From: David.Lowndes@bj.co.uk

>I wrote a tiny handler called when the focus is received 
>( ON_EN_SETFOCUS ).  The text is not selected when 
>this handler completes.  But I CAN select the text 
>elsewhere in the code, not in the setfocus handler.

Karen,

You're probably doing this too early, and some later built-in
processing is altering the selection as a result of the mouse
click.

One technique I often find useful in these circumstances is
to delay the processing by posting a user defined message to
the same window and have it do the real processing there.

In your situation I'd move the code you have in the OnSetFocus
handler to a user defined message handler, and replace the
OnSetFocus processing with a PostMessage of the user
defined message.

Dave Lowndes




| Вернуться в корень Архива |