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. Filter the EN_KILLFOCUS message from CIPAddressCtrl

Filter the EN_KILLFOCUS message from CIPAddressCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 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.
  • Z Offline
    Z Offline
    zhangyoung
    wrote on last edited by
    #1

    You will get a EN_KILLFOCUS message,when the focus switch from CIPAddressCtrl to another control, and this is normal case. But when you click at the dots among four ip fields, you will get the EN_KILLFOCUS message too(with SPY++), which is not what I want, because I just want to do data validation when the CIPAddressCtrl lost focus. How can I filer the EN_KILLFOCUS message when I click the dots??? :doh:

    C 1 Reply Last reply
    0
    • Z zhangyoung

      You will get a EN_KILLFOCUS message,when the focus switch from CIPAddressCtrl to another control, and this is normal case. But when you click at the dots among four ip fields, you will get the EN_KILLFOCUS message too(with SPY++), which is not what I want, because I just want to do data validation when the CIPAddressCtrl lost focus. How can I filer the EN_KILLFOCUS message when I click the dots??? :doh:

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Not sure if this will work or not, but in the message handler for EN_KILLFOCUS, check where the focus "went" with GetFocus[^] or CWnd::GetFocus[^] (whichever suits you best) and determine if the newly focused control is still "inside" the IP address control. I suspect it has four separate edit fields for each segment and all four have the IP address control thing set as its parent, so i supose a GetParent[^] or CWnd::GetParent[^] call can tell you if the user is still editing the IP address or is trying to leave the control altogether. If you try this, do share with us if it worked or not, thanks in advance.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

      Z 1 Reply Last reply
      0
      • C Code o mat

        Not sure if this will work or not, but in the message handler for EN_KILLFOCUS, check where the focus "went" with GetFocus[^] or CWnd::GetFocus[^] (whichever suits you best) and determine if the newly focused control is still "inside" the IP address control. I suspect it has four separate edit fields for each segment and all four have the IP address control thing set as its parent, so i supose a GetParent[^] or CWnd::GetParent[^] call can tell you if the user is still editing the IP address or is trying to leave the control altogether. If you try this, do share with us if it worked or not, thanks in advance.

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

        Z Offline
        Z Offline
        zhangyoung
        wrote on last edited by
        #3

        Thank you mat. You are right.I just call GetFocus and determine weather the EN_KILLFOCUS comes from the focused control.

        BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam)
        {
        // TODO: Add your specialized code here and/or call the base class
        UINT notificationCode = (UINT)HIWORD(wParam);
        if (notificationCode == EN_KILLFOCUS || notificationCode == CBN_KILLFOCUS)
        {
        HWND hwnd = (HWND)lParam;
        if (hwnd == NULL)
        {
        return false;
        }
        CWnd* pWnd = CWnd::FromHandle(hwnd);
        int nID = pWnd->GetDlgCtrlID();
        if (GetFocus() != NULL && GetFocus()->m_hWnd == pWnd->m_hWnd) // Add this
        {
        return false;
        }
        GetParent()->PostMessage(UM_KILLFOCUS, nID, 0);
        }
        return CDialog::OnCommand(wParam, lParam);
        }

        C 1 Reply Last reply
        0
        • Z zhangyoung

          Thank you mat. You are right.I just call GetFocus and determine weather the EN_KILLFOCUS comes from the focused control.

          BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam)
          {
          // TODO: Add your specialized code here and/or call the base class
          UINT notificationCode = (UINT)HIWORD(wParam);
          if (notificationCode == EN_KILLFOCUS || notificationCode == CBN_KILLFOCUS)
          {
          HWND hwnd = (HWND)lParam;
          if (hwnd == NULL)
          {
          return false;
          }
          CWnd* pWnd = CWnd::FromHandle(hwnd);
          int nID = pWnd->GetDlgCtrlID();
          if (GetFocus() != NULL && GetFocus()->m_hWnd == pWnd->m_hWnd) // Add this
          {
          return false;
          }
          GetParent()->PostMessage(UM_KILLFOCUS, nID, 0);
          }
          return CDialog::OnCommand(wParam, lParam);
          }

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          A bit less "specific" than the approach i might have chosen, but if it works for you, then great! :thumbsup:

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

          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