get IP address from Net Address Control (Resolved)
-
Windows 7, VS 2008, MFC, Dialog, c++ I would like to use a control of type Net Address control to provide a method for the user to enter an IP address. Here is the closest I can get:
void CTCP_Client_ConsumerDlg::OnBnClickedButton1()
{NC\_ADDRESS y; PNC\_ADDRESS a = &y; a->pAddrInfo = 0; a->PortNumber = 0; a->PrefixLength = 0; HRESULT x; DWORD ip\_address = 0; x = c\_net\_work\_address\_edit\_box.GetAddress( a ); ip\_address = c\_net\_work\_address\_edit\_box.GetAddress( a );
}
Item: c_net_work_address_edit_box was created by right clicking on the address control and creating a control variable. When I type in: 192.168.2.3 the expected value is not present. Also: The edit box does not provide the dots between the four parts of the IP address. I have seen that used many places, but want to implement in my code now. Edit: Answer: Look in section Dialog Editor of the dialog toolbox to find IP Address Control. I don't know what the Network Address Control is for but I lack sufficient knowledge to get it working for my needs.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
Windows 7, VS 2008, MFC, Dialog, c++ I would like to use a control of type Net Address control to provide a method for the user to enter an IP address. Here is the closest I can get:
void CTCP_Client_ConsumerDlg::OnBnClickedButton1()
{NC\_ADDRESS y; PNC\_ADDRESS a = &y; a->pAddrInfo = 0; a->PortNumber = 0; a->PrefixLength = 0; HRESULT x; DWORD ip\_address = 0; x = c\_net\_work\_address\_edit\_box.GetAddress( a ); ip\_address = c\_net\_work\_address\_edit\_box.GetAddress( a );
}
Item: c_net_work_address_edit_box was created by right clicking on the address control and creating a control variable. When I type in: 192.168.2.3 the expected value is not present. Also: The edit box does not provide the dots between the four parts of the IP address. I have seen that used many places, but want to implement in my code now. Edit: Answer: Look in section Dialog Editor of the dialog toolbox to find IP Address Control. I don't know what the Network Address Control is for but I lack sufficient knowledge to get it working for my needs.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
I am not doing well with this. There must be something that I have completely missed and just cannot see. Here is my latest effort.
void CTCP_Client_ConsumerDlg::OnBnClickedButton1()
{
NC_ADDRESS nc_address;
PNC_ADDRESS p_nc_address = &nc_address;
p_nc_address->pAddrInfo = 0;
p_nc_address->PortNumber = 0;
p_nc_address->PrefixLength = 0;HRESULT hr; DWORD ip\_address = 0; DWORD &rip\_address = ip\_address; hr = c\_net\_work\_address\_edit\_box.GetAddress( p\_nc\_address ); ip\_address = c\_net\_work\_address\_edit\_box.GetAddress( p\_nc\_address ); int count = c\_net\_work\_address\_edit\_box.GetAddress( rip\_address );
}
I dropped a Network Address Control on the MFC dialog, then right clicked and added variable c_net_work_address_edit_box. The page you suggested has:
int GetAddress(
BYTE& nField0,
BYTE& nField1,
BYTE& nField2,
BYTE& nField3
);
int GetAddress(
DWORD& dwAddress
);Which I see is the same as my last attempt. But the compiler complains:
Quote:
error C2664: 'CNetAddressCtrl::GetAddress' : cannot convert parameter 1 from 'DWORD' to 'PNC_ADDRESS'
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
I am not doing well with this. There must be something that I have completely missed and just cannot see. Here is my latest effort.
void CTCP_Client_ConsumerDlg::OnBnClickedButton1()
{
NC_ADDRESS nc_address;
PNC_ADDRESS p_nc_address = &nc_address;
p_nc_address->pAddrInfo = 0;
p_nc_address->PortNumber = 0;
p_nc_address->PrefixLength = 0;HRESULT hr; DWORD ip\_address = 0; DWORD &rip\_address = ip\_address; hr = c\_net\_work\_address\_edit\_box.GetAddress( p\_nc\_address ); ip\_address = c\_net\_work\_address\_edit\_box.GetAddress( p\_nc\_address ); int count = c\_net\_work\_address\_edit\_box.GetAddress( rip\_address );
}
I dropped a Network Address Control on the MFC dialog, then right clicked and added variable c_net_work_address_edit_box. The page you suggested has:
int GetAddress(
BYTE& nField0,
BYTE& nField1,
BYTE& nField2,
BYTE& nField3
);
int GetAddress(
DWORD& dwAddress
);Which I see is the same as my last attempt. But the compiler complains:
Quote:
error C2664: 'CNetAddressCtrl::GetAddress' : cannot convert parameter 1 from 'DWORD' to 'PNC_ADDRESS'
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
Having thought about this some more, I think there is an easier way. You should really be using the
UpdateData
[^] function to exchange information between the class variables and the dialog box. You just need to initialise the variable (if necessary) before callingDoModal
on the dialog. Then you (i.e. the user) fill in the values in your various boxes and click OK, and the data is transferred into the variables. If you want interim values saved by pressing some other button, then you need to callUpdateData(TRUE)
in that button's click handler. You may also need to modify the data exchange routines for some complex controls, so check the documentation for the control you are using. -
Having thought about this some more, I think there is an easier way. You should really be using the
UpdateData
[^] function to exchange information between the class variables and the dialog box. You just need to initialise the variable (if necessary) before callingDoModal
on the dialog. Then you (i.e. the user) fill in the values in your various boxes and click OK, and the data is transferred into the variables. If you want interim values saved by pressing some other button, then you need to callUpdateData(TRUE)
in that button's click handler. You may also need to modify the data exchange routines for some complex controls, so check the documentation for the control you are using.I am not understanding the reply.
Quote:
Having thought about this some more, I think there is an easier way. You should really be using the UpdateData[^] function to exchange information between the class variables and the dialog box. You just need to initialise the variable (if necessary) before calling DoModal on the dialog.
The new project is an MFC dialog and the net address control has been dropped on to the dialog. Why would I be calling DoModal? Maybe I'm barking up the wrong tree. I have seen and used many apps where I enter an IP address that display a small window with four fields of up to three digits, each field separated by dots. How is that display created and put in the dialog?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
I am not understanding the reply.
Quote:
Having thought about this some more, I think there is an easier way. You should really be using the UpdateData[^] function to exchange information between the class variables and the dialog box. You just need to initialise the variable (if necessary) before calling DoModal on the dialog.
The new project is an MFC dialog and the net address control has been dropped on to the dialog. Why would I be calling DoModal? Maybe I'm barking up the wrong tree. I have seen and used many apps where I enter an IP address that display a small window with four fields of up to three digits, each field separated by dots. How is that display created and put in the dialog?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
bkelly13 wrote:
Why would I be calling DoModal?
If it's an MFC dialog then that is effectively how it is run. The dialog is displayed on the screen, the user fills in the data and presses OK. At this point the code in the
OnOK
override captures the data from the dialog window and saves it in the class object's variables by a call toUpdateData(true)
. I think you would be better with theCIPAddressCtrl
Class[^], which is added to the dialog in the same way, as far as I am aware. -
bkelly13 wrote:
Why would I be calling DoModal?
If it's an MFC dialog then that is effectively how it is run. The dialog is displayed on the screen, the user fills in the data and presses OK. At this point the code in the
OnOK
override captures the data from the dialog window and saves it in the class object's variables by a call toUpdateData(true)
. I think you would be better with theCIPAddressCtrl
Class[^], which is added to the dialog in the same way, as far as I am aware.Quote:
If it's an MFC dialog then that is effectively how it is run.
When I drop a control onto a dialog, there has never been a need to call DoModal for that control. I tried dropping the Net Address Control onto the dialog and it did not work out well. EDIT After spending a couple of hours on this I managed to get the "IP Address Control" to display in the dialog tool box. Its under the Dialog Editor section of the toolbox. Now that I can drop that on to the dialog, my extended question about manually creating the dialog is no longer needed. (That would be the long reply that I am deleting and replacing with this.) Now that the dialog is there, adding a variable and getting the address is no trouble. So thank you for your patience.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com