Use the built-in IP address edit box in C ++ Builder

Source: Internet
Author: User

Use the built-in IP address edit box in C ++ Builder.


1. In the BCB project, use the IP address box in the form.
First reference the header file, and then declare the variable.

[Cpp]
# Include "SysIPAddress. hpp"
 
TSysIPAddress32 * ipaddr;
 

2. Create the control in the FormCreate event and specify the location:

[Cpp]
Ipaddr = new TSysIPAddress32 (this );
Ipaddr-> Parent = this;
Ipaddr-> Left = 5;
Ipaddr-> Top = 5;

3. Use Controls:

[Cpp]
Int nIP;
AnsiString ss;
 
Ipaddr-> Enabled = false;
 
If (ipaddr-> IsEmpty) ShowMessage ("is the IP address empty? ");
 
// Obtain the IP address
Edit1-> Text = ipaddr-> Text;
 
NIP = ipaddr-> IPAddr;
Ss. sprintf ("| 0x % X", nIP );
Edit1-> Text = Edit1-> Text + ss;
 
Ipaddr-> ClearIP ();
 
NIP = MAKEIPADDRESS (192,168 );
Ipaddr-> IPAddr = nIP;
 
Ipaddr-> Enabled = true;

4. After use, release the control in the FormClose event:

[Cpp]
Delete ipaddr;

 

5. TSysIPAddress32 encapsulation code:
[Cpp]
//-------------------------------------------------------------
// SysIPAddress. hpp
//-------------------------------------------------------------
# Ifndef TSYSIPADDRESS32H
# Define TSYSIPADDRESS32H
 
# Include <vcl. h>
# Include <windows. h>
 
Class TSysIPAddress32: public TWinControl
{
Public:
_ Property Text;
_ Property Font;
_ Property Enabled;
_ Property TabStop;
_ Property Handle;
// _ Property Color = {default = 0x292929 };
_ Property bool IsEmpty = {read = _ isEmpty };
_ Property int IPAddr = {read = _ getIP, write = _ setIP };
 
Void ClearIP (void ){
// Clear the IP control content IPM_CLEARADDRESS
SendMessage (Handle, IPM_CLEARADDRESS, 0, 0 );
}
 
_ Fastcall TSysIPAddress32 (Classes: TComponent * AOwner)
: TWinControl (AOwner)
{
Length = 150;
Height = 22;
Visible = true;
TabStop = true;
};
Protected:
Void _ fastcall CreateParams (Controls: TCreateParams & Params)
{
TWinControl: CreateParams (Params );
CreateSubClass (Params, "SysIPAddress32 ");
Params. Style | = WS_TABSTOP;
}
Private:
Bool _ isEmpty (void ){
Bool bret = false;
If (SendMessage (Handle, IPM_ISBLANK, 0, 0 ))
{
Bret = true;
}
Return bret;
}
 
Int _ getIP (void ){
Int nIP;
// Obtain the IP value's 32-bit integer value (IPM_GETADDRESS)
SendMessage (Handle, IPM_GETADDRESS, 0, int (& nIP ));
Return nIP;
}
 
Void _ setIP (int _ ip ){
// Set IPM_SETADDRESS
// NIP = MAKEIPADDRESS (192,168 );
SendMessage (Handle, IPM_SETADDRESS, 0, _ ip );
}

};
 
# Endif
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.