曾经看过这样的一个IP输入框,非常漂亮,但是看不懂代码,不知道怎么把这个框放到自己的程序中去(代码中根本就看不到输入框,但是运行的时候就会出现,我是一头雾水呀),还是怎么得到IP edit框的IP地址,代码如下,请各位老师讲解!// email [email protected]
// Copyright 1999 Fire and Safety International
//
// This source is freeware.
// Do with it as you like. I offer no warranty or guarantee. Enjoy.unit IPAddDialogEditor;interfaceuses Windows,SysUtils,Classes,Graphics,Forms,Controls,StdCtrls,Buttons,ExtCtrls,
     ComCtrls,Commctrl;type
  TIPEditDialog = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Bevel1: TBevel;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure OKBtnClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CancelBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    ipEdit:HWND;
    ipAddress:integer;
  end;var
  IPEditDialog: TIPEditDialog;implementation{$R *.DFM}procedure TIPEditDialog.FormCreate(Sender: TObject);
begin
 ipAddress:=MAKEIPADDRESS(196,197,198,199);           //just testing
 InitCommonControl(ICC_INTERNET_CLASSES);
 ipEdit:=CreateWindow(WC_IPADDRESS,nil,WS_CHILD or WS_VISIBLE,91,88,130,23,self.Handle,0,
                      hInstance,nil);
end;procedure TIPEditDialog.OKBtnClick(Sender: TObject);
begin
 SendMessage(ipEdit,IPM_GETADDRESS,0,longint(@ipAddress));
 if ipAddress = 0 then
  begin
   beep;
   SendMessage(ipEdit,IPM_SETFOCUS,0,0);                //select the first field
   modalResult:=mrNone;
  end
 else
  Close;
end;procedure TIPEditDialog.FormShow(Sender: TObject);
begin
 SendMessage(ipEdit,IPM_SETADDRESS,0,ipAddress);        //show the current address
 SendMessage(ipEdit,IPM_SETFOCUS,0,0);                  //select the first field
end;procedure TIPEditDialog.CancelBtnClick(Sender: TObject);
begin
 Close;
end;end.

解决方案 »

  1.   

    很基本的使用API方法。
    这里建立的输入框:
    ipEdit:=CreateWindow(WC_IPADDRESS,nil,WS_CHILD or WS_VISIBLE,91,88,130,23,self.Handle,0,
                          hInstance,nil);
    看一下Windows 的API,这里建立了一个系统注册的类。
    WC_IPADDRESS就是Ip地址输入框,还可以是其他类型:
      WC_LISTVIEW = 'SysListView32';
      WC_TREEVIEW = 'SysTreeView32';
      WC_COMBOBOXEX = 'ComboBoxEx32';
      WC_TABCONTROL = 'SysTabControl32';
      WC_IPADDRESS         = 'SysIPAddress32';
    ...HWND CreateWindow(    LPCTSTR lpClassName, // pointer to registered class name
        LPCTSTR lpWindowName, // pointer to window name
        DWORD dwStyle, // window style
        int x, // horizontal position of window
        int y, // vertical position of window
        int nWidth, // window width
        int nHeight, // window height
        HWND hWndParent, // handle to parent or owner window
        HMENU hMenu, // handle to menu or child-window identifier
        HANDLE hInstance, // handle to application instance
        LPVOID lpParam  // pointer to window-creation data
       );这里把已经初始化的地址发设置地址消息给ipEdit,IpEdit就得到了ipAddress的内容。
    SendMessage(ipEdit,IPM_SETADDRESS,0,ipAddress);
      

  2.   

    谢谢 gzmhero(hihihi)
    明白了一点,刚才也看了一些关于这个API的说明。其中有一段关于得到IP地址的看不懂㈢获取IP值(IPM_GETADDRESS)
    var ip: Integer;
    ...
    SendMessage(ipEdit,IPM_GETADDRESS,0,Integer(@ip));我看了ip这个变量,是一串很长的数字,怎么把这个数字变成标准的IP格式,如123.34.56.89
      

  3.   

    這個IP控件是一個windows的原生控件,就像button等這樣的按鈕,得到ip格式,可能是他自身提供的功能
      

  4.   

    function GetAddress(idx:Byte; IP:Integer): Byte;
    var
      i: integer;
    begin
      i:= $FF;
      Result:= IP and (i shl (4-idx));
    end;或的第一个地址
    GetAddress(1,2385723462);
      

  5.   

    5-idx自己试试看吧!手头没有Delphi
      

  6.   

    MAKEIPADDRESS是一个Win32宏,定义在commctrl.h头文件中,它用来合成一个32位的IP值:
    #define MAKEIPADDRESS(b1,b2,b3,b4)((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))转换成串:
     Edit1.text:=IntToStr(FIRST_IPADDRESS(ip))+'.'
                +IntToStr(SECOND_IPADDRESS(ip))+'.'
                +IntToStr(THIRD_IPADDRESS(ip))+'.'
                +IntToStr(FOURTH_IPADDRESS(ip));
      

  7.   

    消息常量            消息值         作用                                      参数及返回值
    IPM_CLEARADDRESS    WM_USER+100    清除IP控件中的IP串                        参数无
    IPM_SETADDRESS      WM_USER+101    设置IP控件的IP串                          Lparam为32位的IP值
    IPM_GETADDRESS      WM_USER+102    获取IP控件中的IP串所对应的IP值(32位整数)  Lparam为一个指向Integer变量的指针。返回值等于IP控件中非控的字段数目;获取到的IP值存放在lparam 所指向的Integer变量中。  
    IPM_SETRANGE        WM_USER+103    设置IP控件4个部分的其中一个的IP取值范围   Wparam指明要设置取值范围的部分;lparam的低16位字为该字段的范围:高字节为上限,低字节为下限。
    IPM_SETFOCUS        WM_USER+104    设输入焦点                                Wparam指明哪个部分获取焦点
    IPM_ISBLANK         WM_USER+105    IP串是否为空                              参数无。返回值:若为空,返回非0;不为空,返回0
      

  8.   

    D中,是定义在CommCtrlfunction MAKEIPADDRESS(b1, b2, b3, b4: DWORD): LPARAM;
    begin
      Result := (b1 shl 24) + (b2 shl 16) + (b3 shl 8) + b4;
    end;function FIRST_IPADDRESS(x: DWORD): DWORD;
    begin
      Result := (x shr 24) and $FF;
    end;function SECOND_IPADDRESS(x: DWORD): DWORD;
    begin
      Result := (x shr 16) and $FF;
    end;function THIRD_IPADDRESS(x: DWORD): DWORD;
    begin
      Result := (x shr 8) and $FF;
    end;function FOURTH_IPADDRESS(x: DWORD): DWORD;
    begin
      Result := x and $FF;
    end;
      

  9.   

    delphi中IP地址控件哪里下载呢?