主题:填写IP地址问题
flyskylf
[专家分:0] 发布于 2005-10-01 10:18:00
我想用一个Edit或MaskEdit填写IP地址不知如何设置
回复列表 (共3个回复)
沙发
christ115 [专家分:1580] 发布于 2005-10-01 13:11:00
最好使用windows的控件,此控件cb中没有封装,具体方法见MSDN
Using IP Address Controls
This section describes how to implement an IP address control in your application.
Initializing an IP Address Control
To use an IP address control, call InitCommonControlsEx with the ICC_INTERNET_CLASSES flag set in the dwICC member of the INITCOMMONCONTROLSEX structure.
Creating an IP Address Control
Use the CreateWindow or the CreateWindowEx API to create an IP address control. The class name for the control is WC_IPADDRESS, which is defined in Commctrl.h. No IP address control-specific styles exist; however, because this is a child control, use the WS_CHILD style as a minimum.
板凳
flyskylf [专家分:0] 发布于 2005-10-03 14:28:00
看了不明白,能不能说清楚点
谢谢
3 楼
christ115 [专家分:1580] 发布于 2005-10-05 10:39:00
举个例子
1 建一个TForm 名字为Form1,对应文件为Unit1.cpp和Unit1.h
在Unit1.h文件里类TForm1的private域声明两个私有变量
INITCOMMONCONTROLSEX InitCtrls;
HWND hIPCtrls;
2 在Form1的OnCreate事件函数里写下如下代码
// Initial
InitCtrls.dwICC = ICC_INTERNET_CLASSES;
InitCommonControlsEx(&InitCtrls);
// Create IP Control
hIPCtrls = CreateWindow(WC_IPADDRESS, NULL, WS_CHILD, 100, 100, 150, 25,
this->Handle, NULL, NULL, NULL);
// Show Control
ShowWindow(hIPCtrls, SW_SHOW);
// 其中150和50分别为宽和高,前面两个为left和top坐标
3 上述两步完成后运行程序即可看到IP控件,hIPCtrls为此控件的句柄,对它的其他操作请参照MSDN,下面只列出最常用的消息
Messages
IPM_CLEARADDRESS 清除信息
IPM_GETADDRESS 得到控件内ip地址
IPM_ISBLANK 是否为空
IPM_SETADDRESS 设置ip地址
IPM_SETFOCUS 设置焦点
IPM_SETRANGE 设置范围
我来回复