MFC CIPAddressCtrl - How to detect blank field (octet)?
-
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.
-
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.
-
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
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.
-
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.
DWORD dwIPAddr; iNonBlankOctets = ::SendMessage(hWnd, IPM_GETADDRESS, 0, (LPARAM)&dwIPAddr); This worked for me.
-
DWORD dwIPAddr; iNonBlankOctets = ::SendMessage(hWnd, IPM_GETADDRESS, 0, (LPARAM)&dwIPAddr); This worked for me.
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
-
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
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.
-
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.
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 aDWORD
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 callGetWindowText()
on theCIPAddressCtrl
'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
-
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 aDWORD
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 callGetWindowText()
on theCIPAddressCtrl
'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
IPM_GETADDRESS message (Commctrl.h) - Win32 apps | Microsoft Learn[^] "Return value Returns the number of nonblank fields."