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. ATL / WTL / STL
  4. get IP address from Net Address Control (Resolved)

get IP address from Net Address Control (Resolved)

Scheduled Pinned Locked Moved ATL / WTL / STL
c++visual-studiocomsysadmin
7 Posts 2 Posters 9 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.
  • B Offline
    B Offline
    bkelly13
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • B bkelly13

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See http://msdn.microsoft.com/en-us/library/596yzwbb.aspx[^].

      B 1 Reply Last reply
      0
      • L Lost User

        See http://msdn.microsoft.com/en-us/library/596yzwbb.aspx[^].

        B Offline
        B Offline
        bkelly13
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • B bkelly13

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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. 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 call UpdateData(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.

          B 1 Reply Last reply
          0
          • L Lost User

            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. 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 call UpdateData(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.

            B Offline
            B Offline
            bkelly13
            wrote on last edited by
            #5

            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

            L 1 Reply Last reply
            0
            • B bkelly13

              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

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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 to UpdateData(true). I think you would be better with the CIPAddressCtrl Class[^], which is added to the dialog in the same way, as far as I am aware.

              B 1 Reply Last reply
              0
              • L Lost User

                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 to UpdateData(true). I think you would be better with the CIPAddressCtrl Class[^], which is added to the dialog in the same way, as far as I am aware.

                B Offline
                B Offline
                bkelly13
                wrote on last edited by
                #7

                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

                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