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

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


Edit Focus

George Grodentzik -- george@adsc.com
Friday, February 09, 1996

I am trying to return focus to an edit control after the kill focus 
has determined there is an error. MFC has no pre kill focus message.
How can I prevent  the next set focus keeping in mind that it is the 
next set focus which causes the previous edit controls kill focus. I
would appreciate any ideas and sample code. I have experimented with 
pretranslate messages but seem to have problems between views.

Thank you in advance




Kit Kauffmann -- kitk@mudshark.sunquest.com
Monday, February 12, 1996

>I am trying to return focus to an edit control after the kill focus 
>has determined there is an error. MFC has no pre kill focus message.
>How can I prevent  the next set focus keeping in mind that it is the 
>next set focus which causes the previous edit controls kill focus. I
>would appreciate any ideas and sample code. I have experimented with 
>pretranslate messages but seem to have problems between views.
>
>Thank you in advance
>

I did this (published a complete MFC class in first issue of VC++ Developer) 
in a somewhat different way, by using the parental killfocus notification 
messages, such as EN_KILLFOCUS, LBN_KILLFOCUS, etc. by:

1. Posting a (user-defined) message to perform validation with the HWND of 
the control (anything else doesn't allow focus processing to complete, a 
problem with all the focus messages - you can't use SetFocus from any of them.)

2. Responding to the message posted in #1 by validating the given HWND and 
then, if necessary, posting a WM_NEXTDLGCTL message (much more usable than 
SetFocus in such situations) to get the focus back to the offending control.

My code required you to override WindowProc and check for WM_COMMAND's with 
the appropriate killfocus messages, rather than creating message maps for 
all the possible controls, which would be rather error-prone (or actually, 
just pass the message to a function which checks for them).  

I also checked that the parent of the window getting the focus is also the 
parent of the offending control, since applications which force you to 
validate when you are moving to another app are VERY annoying.

Furthermore, I checked a list (which each window could augment) of windows 
on which you don't want validation to occur (IDCANCEL, for example).  If you 
have a button which puts today's date in an edit control, you don't want the 
user to be forced to enter a valid date in order to press the 'Today' button.

Code for this can be retrieved from my ftp site (I hope - somebody said they 
were having problems with my site):

mudshark.sunquest.com in file pub\kitk\validate.zip

HTH!





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