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

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


Problem with OnKillFocus in CEdit

Sanjay -- SGUPTA@aegonusa.com
Wednesday, January 03, 1996



I have this MDI app with one of the views derived from CFOrmView. I also 
have a class CMyEdit derived from CEdit with one overriden function 
OnKillFocus. I create CMyEdit controls in the Form view dynamically at 
runtime. Now the problem is that when you try to tab out of a CMyEdit 
control, OnKillFocus get called which posts a message to the parent. Now the 
parent message handler check the value from the CMyEdit control and verifies 
against values from a text file. If the value is invalid, it displays a 
dialog box with values listed in a listbox and allows the user to choose a 
correct value. It works fine except in couple of cases. If the CMyEdit 
control which has a valid help file associated with it has the input focus, 
and I try to use ALT+TAB key to switch to a diferent task, valid help dialog 
box pops up. Or if I try to use the toolbar to display another dialog box, 
My valid help dialog box also popsup and causes some kind of problem because 
I have two dialog boxes up.

What I would like to do is that if the focus goes to toolbar or menu or 
other application, I don't want to validate the field help. I want to 
validate the field help only if focus is transferred to another field in the 
form view. I have an idea that if I derive OnChar function for CMyEdit 
class, I can probably trap ALT+TAB, but still I won't be able to trap mous 
clicks like when you use toolbar.

Any help will be appreciated.

Sanjay Gupta

SGUPTA@AEGONUSA.COM



Geoffrey Nicholls -- geoff@gazelle.com
Wednesday, January 03, 1996

[Mini-digest: 4 responses]

>I have this MDI app with one of the views derived from CFOrmView. I also 
>have a class CMyEdit derived from CEdit with one overriden function 
>OnKillFocus. I create CMyEdit controls in the Form view dynamically at 
>runtime. Now the problem is that when you try to tab out of a CMyEdit 
>control, OnKillFocus get called which posts a message to the parent. Now the 
>parent message handler check the value from the CMyEdit control and verifies 
>against values from a text file. If the value is invalid, it displays a 
>dialog box with values listed in a listbox and allows the user to choose a 
>correct value. It works fine except in couple of cases. If the CMyEdit 
>control which has a valid help file associated with it has the input focus, 
>and I try to use ALT+TAB key to switch to a diferent task, valid help dialog 
>box pops up. Or if I try to use the toolbar to display another dialog box, 
>My valid help dialog box also popsup and causes some kind of problem because 
>I have two dialog boxes up.

MFC has a mechanism to handle something very much like this already. Perhaps
the way that MFC does it for the case of DDV_MinMaxInt in DoDataExchange
will help you find a way to handle it for you.

Geoffrey Nicholls

-----From: Niels Ull Jacobsen 

See the MS sample FCSVAL, which does exactly this.  A simple way to do
it is to set a flag in OnKillFocus saying "this control should be
validated". Then in OnSetFocus of every control on the dialog (except
the Cancel button), call a function which loops thorugh all controls
and validates those which need validating.

--
Niels Ull Jacobsen, Kruger A/S

Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
group and should be taken as legally binding in every respect. Pigs
will grow wings and fly.

-----From: "Gupta, Sanjay" 

To sum up your request, you would like to detect when user jump from
one of the control of your dialog to another control of the SAME
dialog. And you don't care for any other focus target new control.


The parameter you receive by OnKillFocus(), is a TEMPORARY pointer to
the window which will get focused. You may compare the parent of this
window with the parent of your subclassed control.  If both parents are
the same, you can post your message, and if not...

I see a tiny problem which may appear if you don't check your Edit
control for a non-sibling window in OnKillFocus : if the Edit has an
invalid value, what will you do ?  If the user comes back into your
dialog, the Edit will keep on having the same invalid value...

It is never easy to handle focus problems...


I hope this help.

   Christophe  -- a poor lonely frenchie --

-----From: "Mark F. Fling" 

Override your form view's OnActivateView virtual function like this:

void myView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView )
{
  m_bValidate = bActivate;
}

where "m_bValidate", if true, indicates a validation is necessary 
whenever input focus is lost.  For example,

ON_EN_KILLFOCUS(IDC_FIELD1,  ValidateField1)

void myView::ValidateField1()
{
   if (m_bValidate)
   { // Continue with validation
   }
} 

This eliminates the bothersome prompting for validation on a field by 
field basis whenver you focus to another application, or even another MDI 
window.  Be sure to initialize to FALSE in your CView-derived constructor.

Regards.

___________________________________________________________________________
Mark F. Fling                                         mfling@stratacorp.com
Strata Corporation / SBA                               Voice (805) 967-3051
922 Via Brocha                                           Fax (805) 967-8203
Santa Barbara, CA  93110 





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