Board index » cppbuilder » Windows IP Address Entry Component

Windows IP Address Entry Component


2004-02-05 11:15:12 AM
cppbuilder26
Hi Folks,
I would like to know if there is a decent IP Address Entry components.
Preferably one based on the Microsoft IP Address component.
I have downloaded a couple of freeware Wrappers for the Microsoft component
but they don't work the way I want. The biggest problem I have with the
downloaded components is that the right & left arrow keys move the focus to
another control rather than another part of the IP number.
Has anyone had experience with using IP address edit on BCB forms?
Thanks,
Robert Wheadon
 
 

Re:Windows IP Address Entry Component

"Robert Wheadon" < XXXX@XXXXX.COM >wrote in message
Quote
I would like to know if there is a decent IP Address Entry
components. Preferably one based on the Microsoft IP
Address component.
Quick and dirty - just write your own component:
class TIPAddressEdit : public TWinControl
{
private:
DWORD dwIpSave;
AnsiString __fastcall GetIP();
void __fastcall SetIP(const AnsiString Value);
AnsiString __fastcall IPToString(DWORD dwIp);
DWORD __fastcall StringToIP(const AnsiString Value);
bool _fastcall GetIsEmpty();
protected:
void __fastcall CreateParams(TCreateParams &Params);
void __fastcall CreateWnd();
void __fastcall DestroyWnd();
void __fastcall WMGetDlgCode(TMessage &Message);
public:
__fastcall TIPAddressEdit(TComponent *Owner);
__property AnsiString IP = {read=GetIP, write=SetIP};
__property bool IsEmpty = {read=GetIsEmpty};
#pragma warn -inl // "Functions containing ... are not expanded inline
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_GETDLGCODE, TMessage, WMGetDlgCode);
END_MESSAGE_MAP(TWinControl)
#pragma warn .inl
};
__fastcall TIPAddressEdit::TIPAddressEdit(TComponent *Owner)
: TWinControl(Owner), dwIpSave(0)
{
INITCOMMONCONTROLSEX icc = {sizeof(INITCOMMONCONTROLSEX),
ICC_INTERNET_CLASSES};
if( !InitCommonControlsEx(&icc) )
throw Exception("Count not initialize the CommCtrl Library: " +
SysErrorMessage(GetLastError()));
ControlStyle = ControlStyle << csClickEvents << csSetCaption <<
csDoubleClicks << csFixedHeight;
if( !NewStyleControls )
ControlStyle = ControlStyle << csFramed;
}
void __fastcall TIPAddressEdit::CreateParams(TCreateParams &Params)
{
TWinControl::CreateParams(Params);
CreateSubClass(Params, WC_IPADDRESS);
Params.Style = WS_CHILD | WS_TABSTOP | WS_VISIBLE;
if( NewStyleControls && Ctl3D )
{
Params.Style &= ~WS_BORDER;
Params.ExStyle |= WS_EX_CLIENTEDGE;
}
Params.WindowClass.style &= ~(CS_HREDRAW | CS_VREDRAW);
}
void __fastcall TIPAddressEdit::CreateWnd()
{
TWinControl::CreateWnd();
if( dwIpSave != 0 )
SendMessage(Handle, IPM_SETADDRESS, (WPARAM)0,
(LPARAM)&dwIpSave);
}
void __fastcall TIPAddressEdit::DestroyWnd()
{
if( HandleAllocated() )
SendMessage(Handle, IPM_GETADDRESS, (WPARAM)0,
(LPARAM)&dwIpSave);
else
dwIpSave = 0;
TWinControl::DestroyWnd();
}
AnsiString __fastcall TIPAddressEdit::IPToString(DWORD dwIp)
{
struct in_addr addr = {0};
addr.s_addr = htonl(dwIp);
return inet_ntoa(addr);
}
DWORD __fastcall TIPAddressEdit::StringToIP(const AnsiString Value)
{
return ntohl(inet_addr(Value.c_str()));
}
AnsiString __fastcall TIPAddressEdit::GetIP()
{
DWORD dwIp = 0;
SendMessage(Handle, IPM_GETADDRESS, (WPARAM)0, (LPARAM)&dwIp);
return IPToString(dwIp);
}
void __fastcall TIPAddressEdit::SetIP(const AnsiString Value)
{
SendMessage(Handle, IPM_SETADDRESS, (WPARAM)0,
(LPARAM)StringToIP(Value));
}
bool _fastcall TIPAddressEdit::GetIsEmpty()
{
if( HandleAllocated() )
return SendMessage(Handle, IPM_ISBLANK, 0, 0);
return true;
}
void __fastcall TIPAddressEdit::WMGetDlgCode(TMessage &Message)
{
TWinControl::Dispatch(&Message);
Message.Result |= DLGC_WANTARROWS;
}
Quote
I have downloaded a couple of freeware Wrappers for the
Microsoft component but they don't work the way I want. The
biggest problem I have with the downloaded components is that
the right & left arrow keys move the focus to another control
rather than another part of the IP number.
They are probably not set up to ask the OS to send arrow keystrokes to the
edit control first. That takes extra setup.
Gambit
 

Re:Windows IP Address Entry Component

Thanks for that. Big help.
I've compiled it and it seems to work OK. I'm going to add some more
features to it.
One thing I noticed is that the font on my compiler gets bigger & goes bold
for some reason. What's the story? Have you seen this before?
- Rob
 

{smallsort}

Re:Windows IP Address Entry Component

"Robert Wheadon" < XXXX@XXXXX.COM >wrote in message
Quote
One thing I noticed is that the font on my compiler gets bigger
& goes bold for some reason. What's the story? Have you
seen this before?
Yes, I have noticed that as well. It tends to happen for me when I place
the edit control on a form that is dynamically instantiated at runtime more
then once. If I instantiate the form only once, or make the form
auto-created and simply hide it when not in use, everything works ok. I do
not have an explanation for it. An OS bug is the only thing I can think of
right now, unless there are undocumented messages that the control needs to
handle that I am unaware of.
Gambit