?
Solved

Kill focus CEdit control

Posted on 2007-03-22
3
Medium Priority
?
1,990 Views
Last Modified: 2013-11-20
Hi,

I have a dialog containing 5 Edit boxes. Is there a way to handle the case where any one of those Edit boxes loses focus as opposed to putting an OnKillFocus event for every single Edit box?
Can this be done in MFC?

Regards,
maloriopolium
0
Comment
Question by:maloriopolium
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18777750
Add OnKillFocus handler for all the edit boxes.

Inside each one write

CWnd* pWndParent = GetParent();
pWndParent.SetFocus();

Also read:
www.codeproject.com/dialog/killfocus.asp

Best Regards,
DeepuAbrahamK
0
 
LVL 9

Accepted Solution

by:
Priyesh earned 200 total points
ID: 18784534
Manually add the following in your dialog cpp file in the message map section
      ON_CONTROL_RANGE(EN_KILLFOCUS, IDC_EDIT1, IDC_EDIT5, OnEditKillFocus)
Add handler in dialog as
void CDlgTestDlg::OnEditKillFocus(UINT unID)
{
      TRACE(_T("%d\n"), unID) ;
}
and in the header file,
afx_msg void OnEditKillFocus(UINT unID) ;

Note* the IDC_EDIT1 to IDC_EDIT5 must be in a continous range in ascending order for this to work. So if you have added controls to the dialog at different times, edit your resource.h to make sure these are continuous.
0
 

Author Comment

by:maloriopolium
ID: 18784708
Thanks Priyesh,

That worked exactly like I wanted it to.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question