Solved

Kill focus CEdit control

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.

695 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