CIPAddressCtrl

CIPAddressCtrl

Post by Anon » Wed, 24 Sep 2003 14:50:05


My edit box repeatedly displays "4" when it should be displaying an IP
address like string. Why isn't my code working? Any suggestion
welcome.

void CIPGetAddressDlg::OnRunme()
{
// TODO: Add your control notification handler code here
DWORD DwordAddress=0;
char CharAddress[100];
CIPAddressCtrl *ipaddressctrl = (CIPAddressCtrl *)
GetDlgItem(IDC_IPADDRESSCTRL);
CEdit *edit = (CEdit *) GetDlgItem(IDC_EDIT);
DwordAddress = ipaddressctrl->GetAddress(DwordAddress);
sprintf(CharAddress,"%d",DwordAddress);
edit->SetWindowText(CharAddress);
}


Thank you.
 
 
 

CIPAddressCtrl

Post by David Crow » Wed, 24 Sep 2003 23:43:39

Since DwordAddress is a 32-bit variable, the "%d" used in the sprintf() call
is incorrect. Make the CharAddress variable a CString instead of a char.
Replace the sprintf() call with CString::Format() instead. Note also that
the return value of GetAddress() is the number of non-blank fields!

 
 
 

CIPAddressCtrl

Post by SmNtY3JhZn » Thu, 26 Feb 2004 06:31:08

Hi
I'm trying to implement the IP Address control in a VC++ dialog, and I'm having trouble working out the correct parameters for the CIPAddressCtrl::Create initializer. Here's the definition

BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID )

I'm mostly scratching my head about the RECT reference. Which RECT is it referring to and where do I get it from? Also, is pParentWnd referring to the dialog (i.e. this->GetActiveWnd())

Thanks
J
 
 
 

CIPAddressCtrl

Post by Tim » Thu, 26 Feb 2004 06:43:16


// in OnInitDialog ...
CRect rect;

rect.SetRect(0, 0, 100, 100); // coordinates on this dialogue in pixels:
you decide where.

bOK = Create(dwStyle, // your style bits. EG WS_CHILD |
WS_VISIBLE
rect,
this, // CWnd* - this dialog
in your case.
ID_IPCONTROL // Your ID for the control
);


Why not just put it on the dialog resource and let CDialog create it for
you?

- Tim




I'm having trouble working out the correct parameters for the
CIPAddressCtrl::Create initializer. Here's the definition:
nID );
is it referring to and where do I get it from? Also, is pParentWnd
referring to the dialog (i.e. this->GetActiveWnd())?
 
 
 

CIPAddressCtrl

Post by David Crow » Thu, 26 Feb 2004 06:49:50

Do you really need to create the control dynamically? In any case, the
second parameter to Create() is the dimension of the control you want to
create. Plug some numbers in there (e.g., CRect(5, 5, 200, 50)) to get a
feel for what it takes. Be advised that hard-wiring numbers like that is
generally frowned upon, but it certainly never hurts to experiment.



I'm having trouble working out the correct parameters for the
CIPAddressCtrl::Create initializer. Here's the definition:
nID );
is it referring to and where do I get it from? Also, is pParentWnd
referring to the dialog (i.e. this->GetActiveWnd())?
 
 
 

CIPAddressCtrl

Post by SmNtY3JhZn » Thu, 26 Feb 2004 07:11:06


Do you really need to create the control dynamically? In any case, th

No, in fact I did begin by adding it to the dialog resource and creating a member variable. However, when I try to use the control, I get a debug assertion. Specifically, I call SetAddress(192,168,0,100) for a simple test in InitDialog. The Assertion is

{ ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, IPM_SETADDRESS, 0, (LPARAM) MAKEIPADDRESS(nField0, nField1, nField2, nField3));

Stepping through, I find that m_hWnd is 0x0, so I assumed I needed to perform the second step of construction per the remarks in the documentation. Maybe a bad assumption, sorry. Why would I get this assertion otherwise

Thanks
 
 
 

CIPAddressCtrl

Post by Trevo » Thu, 26 Feb 2004 07:32:12


case, the
creating a member variable. However, when I try to use the control, I get a
debug assertion. Specifically, I call SetAddress(192,168,0,100) for a
simple test in InitDialog. The Assertion is:
(LPARAM) MAKEIPADDRESS(nField0, nField1, nField2, nField3)); }
perform the second step of construction per the remarks in the
documentation. Maybe a bad assumption, sorry. Why would I get this
assertion otherwise?
J,

You are getting the assertion because the control is not created at that
time OR you need to call the function to initialize common control library
(either way it is not created). I think MFC automatically calls this
function for you so I am leaning towards the first scenario. Try setting
the IP address in CMainFrame::Create rather than wherever you are doing it
now.
 
 
 

CIPAddressCtrl

Post by David Crow » Thu, 26 Feb 2004 22:34:15

With a dialog-based application, there is no frame.
 
 
 

CIPAddressCtrl

Post by David Crow » Thu, 26 Feb 2004 22:40:42

You need to call SetAddress() *after* calling CDialog::OnInitDialog().




case, the
creating a member variable. However, when I try to use the control, I get a
debug assertion. Specifically, I call SetAddress(192,168,0,100) for a
simple test in InitDialog. The Assertion is:
(LPARAM) MAKEIPADDRESS(nField0, nField1, nField2, nField3)); }
perform the second step of construction per the remarks in the
documentation. Maybe a bad assumption, sorry. Why would I get this
assertion otherwise?
 
 
 

CIPAddressCtrl

Post by Mark » Wed, 27 Jul 2005 15:36:17

I'm having problems creating an IP Address Ctrl using a dialog template.
Does any one know how I can do this without calling Create.
I seem to be able to create Edit boxes and similar from a dialog template
without explicitly needing to call create.


Mark
 
 
 

CIPAddressCtrl

Post by David Lown » Wed, 27 Jul 2005 16:00:54

>I'm having problems creating an IP Address Ctrl using a dialog template.

Problems? What sort of problems?


You can do the same with the IP address control.

If you use the VS dialog editor and place one on a dialog, does it
show up with the dialog test mode?

Are you calling InitCommonControlsEx and specifying the
ICC_INTERNET_CLASSES controls?

Dave
--
MVP VC++ FAQ: http://www.yqcomputer.com/
 
 
 

CIPAddressCtrl

Post by Jeff Partc » Wed, 27 Jul 2005 16:05:48


The only thing I can see that Create might be doing is an indirect call to
InitCommonControlsEx/ICC_INTERNET_CLASSES.
--
Jeff Partch [VC++ MVP]