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. MFC CIPAddressCtrl - How to detect blank field (octet)?

MFC CIPAddressCtrl - How to detect blank field (octet)?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestionannouncement
8 Posts 3 Posters 4 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.
  • M Offline
    M Offline
    Member_16326708
    wrote on last edited by
    #1

    I'm using a CIPAddressCtrl which gets filled with a device's IP. The user can edit this IP and I need to make sure none of the fields (octets) are blank if the user wants to update the device with the new IP. If any are blank and the user tries to update (with a click of a button), then there will be an error. I see there is a SetFieldFocus that can set the focus if an octet is blank, but I'm not sure if it's useful for what I need or how to use it in my case. Is there any work around to achieve this? Thanks.

    C 1 Reply Last reply
    0
    • M Member_16326708

      I'm using a CIPAddressCtrl which gets filled with a device's IP. The user can edit this IP and I need to make sure none of the fields (octets) are blank if the user wants to update the device with the new IP. If any are blank and the user tries to update (with a click of a button), then there will be an error. I see there is a SetFieldFocus that can set the focus if an octet is blank, but I'm not sure if it's useful for what I need or how to use it in my case. Is there any work around to achieve this? Thanks.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      In order to validate the use input, call the GetAddress method and check its return value. See the documentation: CIPAddressCtrl Class | Microsoft Learn[^].

      "In testa che avete, Signor di Ceprano?" -- Rigoletto

      M 1 Reply Last reply
      0
      • C CPallini

        In order to validate the use input, call the GetAddress method and check its return value. See the documentation: CIPAddressCtrl Class | Microsoft Learn[^].

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        M Offline
        M Offline
        Member_16326708
        wrote on last edited by
        #3

        Tried that already. GetAddress doesn't tell you whether or not an octet is blank. If you do GetAddress and get the four octets and one of them is blank, then it's just a zero. However, it could also mean that the user could have entered zero. The IPM_GETADDRESS message returns the number of non-blank fields so that'll probably work for me unless anyone has any other ideas.

        M 1 Reply Last reply
        0
        • M Member_16326708

          Tried that already. GetAddress doesn't tell you whether or not an octet is blank. If you do GetAddress and get the four octets and one of them is blank, then it's just a zero. However, it could also mean that the user could have entered zero. The IPM_GETADDRESS message returns the number of non-blank fields so that'll probably work for me unless anyone has any other ideas.

          M Offline
          M Offline
          Member_16326708
          wrote on last edited by
          #4

          DWORD dwIPAddr; iNonBlankOctets = ::SendMessage(hWnd, IPM_GETADDRESS, 0, (LPARAM)&dwIPAddr); This worked for me.

          D 1 Reply Last reply
          0
          • M Member_16326708

            DWORD dwIPAddr; iNonBlankOctets = ::SendMessage(hWnd, IPM_GETADDRESS, 0, (LPARAM)&dwIPAddr); This worked for me.

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

            But how would you differentiate between an empty octet and an octet containing 0?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            M 1 Reply Last reply
            0
            • D David Crow

              But how would you differentiate between an empty octet and an octet containing 0?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              M Offline
              M Offline
              Member_16326708
              wrote on last edited by
              #6

              iNonBlankOctets = ::SendMessage(hWnd, IPM_GETADDRESS, 0, (LPARAM)&dwIPAddr); Not exactly sure how to tell if specific octets are blank or 0. In my case, making sure iNonBlankOctets is never less than the total number of octets is sufficient validation so if any octets are blank, then there's an error.

              D 1 Reply Last reply
              0
              • M Member_16326708

                iNonBlankOctets = ::SendMessage(hWnd, IPM_GETADDRESS, 0, (LPARAM)&dwIPAddr); Not exactly sure how to tell if specific octets are blank or 0. In my case, making sure iNonBlankOctets is never less than the total number of octets is sufficient validation so if any octets are blank, then there's an error.

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

                Member 16326708 wrote:

                In my case, making sure iNonBlankOctets is never less than the total number of octets...

                The return value of IPM_GETADDRESS is a DWORD that is broken up into 4 pieces, one for each of the four octets. There is no count. A possibly better option would be to call GetWindowText() on the CIPAddressCtrl's control. Getting the string representation of the IP address would allow you to parse and validate the octets. You would still get 0 for empty ones, though.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                M 1 Reply Last reply
                0
                • D David Crow

                  Member 16326708 wrote:

                  In my case, making sure iNonBlankOctets is never less than the total number of octets...

                  The return value of IPM_GETADDRESS is a DWORD that is broken up into 4 pieces, one for each of the four octets. There is no count. A possibly better option would be to call GetWindowText() on the CIPAddressCtrl's control. Getting the string representation of the IP address would allow you to parse and validate the octets. You would still get 0 for empty ones, though.

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  M Offline
                  M Offline
                  Member_16326708
                  wrote on last edited by
                  #8

                  IPM_GETADDRESS message (Commctrl.h) - Win32 apps | Microsoft Learn[^] "Return value Returns the number of nonblank fields."

                  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