IP address control tips
Keywords: IP address control
First, how to respond to EN_CHANGE events
The notification message for IPN_FIELDCHANGED is provided in the control, which occurs when the control is changed, generally can meet the needs. However, sometimes, we hope that whenever a value is changed, you want to know the currently entered address, which can be judged in time, and IPN_FieldChanged messages obviously cannot provide this support.
From MSDN, you can know that although the control is not an edit box control, it will send En_Change notification when the value of a domain in the control is changed (SENT WHEN ANY FIELD IN THE IP Address Control Changes. Like the en_change notification From A Standard Edit Control, this Notification is Received After The Screen Has Been Updated. (Note: from MSDN)). Therefore, we can respond to EN_CHANGE events in the parent window of the control. In fact, although the IP address control is not an edit box control, but in this control, the edit box is also as its sub-window, and the ID of this edit box control can be obtained via SPY . After getting this ID, add an en_change message mapping in the parent window:
AFX_MSG void onchangeEditxxx ();
ON_EN_CHANGE (1135, ONCHANGEEDITXX)
Void cxxx :: OnChangeEditxxx ()
{
...
}
Among them, 1135 of ON_EN_CHANGE is the ID of the edit box window of the control obtained with SPY . Thus, the parent window can receive a notification of the value of the value of a certain domain of the control at any time.
Second, how to set a network segment in the program
IP address control class CIPADDRESSCTRL provides SetAddress to set the value of each domain in the control. This method can set an IP address, but when you want to set a network segment, do not want to use a mask (for example, want to set a 100.6 network Segment, and the latter two cannot be filled in 0. Otherwise, it will represent an address, not a network segment), which cannot meet this demand.
By Spy discovery, the edit box window of the IP address control is not one, but 4, that is, each domain is a word window (not knowing how to add the same ID in one control). Therefore, the four sub-windows can be set separately to achieve this purpose. The following is the code:
Void setipaddrctrladdress (cipaddressctrl * pctrl, // the pointer of ip address ctrl
Byte nfield0, // the field 0 value from a packed ip address
Byte nfield1, // the field 1 value from a packed ip address
Byte nfield2, // the field 2 value from a packed ip address
Byte nfield3, // the field 3 value from a packed ip address
Byte nfieldcount) // The Total Fields
{
IF (pctrl == null)
Return;
PCTRL-> clearAddress (); if (nfieldcount == 0)
{
Return;
}
Else IF (nfieldcount> = 4)
{
PCTRL-> Setaddress (nfield0, nfield1, nfield2, nfield3);
Return;
}
INT nbit = 3;
BYTE BYBIT [4];
Bybit [0] = NFIELD0;
Bybit [1] = NFIELD1;
Bybit [2] = nfield2;
Bybit [3] = nfield3;
HWND HCHILD = :: getWindow (pctrl-> m_hwnd, gw_child);
While (hchild)
{
IF (nbit { TCHAR SZBIT [4] = {0}; _SNTPRINTF (SZbit, Sizeof (Szbit), _T ("% D"), Bybit [Nbit]); :: setwindowtext (hchild, szbit); } Hchild = :: getWindow (hchild, gw_hwndnext); Nbit -; } }