曾经看过这样的一个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.
// 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.
解决方案 »
- 如何将图片的边缘位置加上一个撕边效果?
- 急!控件中默认字体显示的问题
- 关于StrPCopy的问题
- 请问用Delphi自带的MediaPlayer控件可以播放MPEG2格式的MPG文件吗?
- delphi-bde-sql2000,怎么发布?哪有intallshield for delphi?我的盘里没有,我下的intallshield没有for delphi的选项,完美解决者再开贴
- 如何调用chm格式得帮助文件?
- 承蒙一年来大家的照应!祝大家新年快乐,羊年大发,合家欢乐,万事如意,工作顺利!
- 读取文本文件数据的问题。暴急!!给分120
- 如何实现多个库的访问,用SQL,我只建过多表查询,却不知道是否可以进行跨库查询?请各位帮忙!
- 怎样求这样的弧长?`
- 熟悉Oracle中CLOB类型的同志请进!
- 示例数据库IBLocal的密码是什么?
这里建立的输入框:
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);
明白了一点,刚才也看了一些关于这个API的说明。其中有一段关于得到IP地址的看不懂㈢获取IP值(IPM_GETADDRESS)
var ip: Integer;
...
SendMessage(ipEdit,IPM_GETADDRESS,0,Integer(@ip));我看了ip这个变量,是一串很长的数字,怎么把这个数字变成标准的IP格式,如123.34.56.89
var
i: integer;
begin
i:= $FF;
Result:= IP and (i shl (4-idx));
end;或的第一个地址
GetAddress(1,2385723462);
#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));
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
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;