Solved

Kill focus CEdit control

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
if loop in java 3 114
scoreUp challenge 14 48
How to split this in C++ 4 78
Problem to open Excel file 15 45
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

744 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

12 Experts available now in Live!

Get 1:1 Help Now