Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 830151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:59:50+00:00 2026-05-15T03:59:50+00:00

I stumbled upon a curious problem with MFC. I have a Dialog where I

  • 0

I stumbled upon a curious problem with MFC. I have a Dialog where I check every Edit field on ON_EN_KILLFOCUS if it’s valid. If validation doesn’t go through I set focus back and show error message. This would be fine, if only I would close the dialog. I mean if I leave wrongly entered field and press close button or X, then ON_EN_KILLFOCUS is invoked first, after other handling events, because message appears and focus goes back to the field. So my question: Is there a way to find out in ON_EN_KILLFOCUS which event will be after it? If yes then I can check if its close event and then close dialog, not returning my focus to wrongly entered Edit field. Any help would be so much help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:59:51+00:00Added an answer on May 15, 2026 at 3:59 am

    In general, you cannot know what event comes after the focus changed event.

    However, it is possible to solve this, you change the conditions when the validation logic is fired – validate an edit control when

    • focus is lost
    • and the focus is lost to another edit control

    By checking that the focus is lost to another control, you are saying to the user, “don’t move on to this component – you haven’t filled out the current one correctly yet!”.

    It captures the user’s intent better than validating on any focus change. It will also not run validation when the user clicks Close or the system X button, or any other button.
    Of course, you will need add explicit validation when the OK button is clicked.

    Not only is this fairly simple to code (check that the new focus window is a child of the dialog and is an input component – you can determine it’s an input component by looking at the Window Class name of the window. EDIT for edit boxes.)

    This also deals with cases where the user shifts focus for other reasons, such as a System Message Box, or other focus grabbing event. Since the focus is not moving to one of your other edit controls, then validation is not run, and the focus is not forced back to your application, which could be quite annoying for some people!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I stumbled upon this code and I am curious as to what use may
I stumbled upon this problem and it took my a while to realise what
I stumbled upon a problem of how to make work together acts_as_taggable (on steroids)
I stumbled upon Jtalk here http://nicolaspetton.github.com/jtalk/index.html#download but when clicking on download I have 404
I'm studying for a final exam and I stumbled upon a curious question that
I stumbled upon a rather exotic c++ namespace problem: condensed example: extern C {
I stumbled upon a problem from the last Facebook Hacker Cup (so it's NOT
I stumbled upon a problem where i need an instance of the class inside
I stumbled upon this site http://nathanborror.com/ and really loved the way they have done
I stumbled upon a function called v8Locale in Chrome's Developer Console. I was curious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.