Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WM_KILLFOCUS

WM_KILLFOCUS

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.

    S D N 3 Replies Last reply
    0
    • A Anonymous

      Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.

      S Offline
      S Offline
      stolid_rock
      wrote on last edited by
      #2

      Hi there, All you have to do is create a handler for trapping the EN_KILLFOCUS so that you get the message that the edit control is loosing the focus. So inside the handler put the MessageBox that you want to popup. When the user clicks on OK on the dialog box, edit control looses the focus. So to ensure that the focus is on the edit control, create a control variable for the edit control suppose(m_control) do the following after the statement following the MessageBox CPoint set(0,0); m_control.SetFocus(); m_control.SetCaretPos(set); :)

      1 Reply Last reply
      0
      • A Anonymous

        Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Validating data during a WM_KILLFOCUS message indicates a bad design. That message gets sent in too many situations so picking and choosing which one(s) you are interested in will lead to trouble. The most reliable way of validating data on a dialog box is to check the state of each control anytime a control changes. Set up a "change" handler for each control and do the validating in it. If all conditions are met, only then do you enable the OK button. I do this for each of my dialogs. It is very clean and reliable. Read here for more.


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        1 Reply Last reply
        0
        • A Anonymous

          Hi, I have to validate a field entry on kill focus of the edit control.If the user enters invalid data, a error message box should pop up and focus should remain on the edit control only so as to allow user to change the wrong entry. The problem is, this validation should not occur when user is exiting from the dialog like pressing cancel or exit. But when he clicks on the cancel button, kill foucs gets called and if the user has entered wrong data, error message will pop. Infact he won't be able to exit until he corrects the entry, which is ridiculous. To avoid this problem, I switched validation from kill focus to SetFocus of the next control. The program behaviour is -- User enters data in Control A Then he puts cursor on Control B. Control B::On Set Focus validates the ControlA:data. IF wrong, pops up the message box and sets the focus to Control A. But whenever user presess OK on the message box, focus again goes to Control B rather than going to Control A. Again validate is called and again the message box pops up. This goes in loop. I didn't want to put the validations on En_change or use a bool vble for skipping the validations next time. Any ideas will help a lot both on killfocus and setfocus front.

          N Offline
          N Offline
          namaskaaram
          wrote on last edited by
          #4

          aaaah.....if ur specifiaction demandz u to have a validation of the data entered onkillfocus,then herez ur answer..... click thiz.....[^] cheerz.....:-D "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups