Solved

Kill focus CEdit control

Posted on 2007-03-22
3
1,836 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
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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 66
Safe conversion? 4 59
c++ reading data from file into two dimensional array 3 96
c++, dynamic object by json 1 25
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now