Getting CEdit box on a Dialog 
Author Message
 Getting CEdit box on a Dialog

Hello,

   I am having trouble getting the CEdit box on my dialog window which I
created with MSVC++6.0 Visual Studio Interface.
What I want to do is get a particular diglog item and change the
password character property for the edit box.  I am using this edit box
for multiple things, so I need to make property changes on the fly.

.
.
.
 CEdit editBox;

  editBox.GetDlgItem(IDC_EDIT_BOX);
  editBox.SetPasswordChar('.');
.
.
.

When I do the above, I get the assertion error in GetDlgItem():
ASSERT(::IsWindow(m_hWnd));

Why isn't CEdit also a CWnd object since it inherits from the parent
CWnd?
How would I access my CEdit box and apply changes to it after it has
already been created?

Thank you very much
JM



Fri, 14 Feb 2003 03:00:00 GMT  
 Getting CEdit box on a Dialog

Hi!

The easiest way (and arguably the best way) would be to use ClassWizard to add a member control
variable of the CEdit class to the CDialog. Then you can use it to work with the edit control
anytime after the call to CDialog::OnInitDialog and before the dialogbox is destroyed. Like

CMyDialog::SomeFunction()
{
    m_edit.SetPasswordChar(0);

Quote:
}

But to do it the way you are trying, you need to call GetDlgItem thru the CDialog derived class --
the CEdit is an Item of the Dialog. So...

CMyDialog::SomeFunction()
{
    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_BOX);

    if (pEdit)
        pEdit->SetPasswordChar(0);

Quote:
}

Remember, that GetDlgItem returns a possibly temporary pointer to a CWnd, so the cast is necessary.

The reason you are getting the assert is because when you do this...

Quote:
> CEdit editBox;

You are instantiating a local (I gather) CEdit object, but not calling any method to create the
underlying HWND, or the value in m_hWnd. And the way almost all of the CEdit member functions work
is that they wrap a SendMessage(m_hWnd, EM_XXX, ...) call. You can not send a message to a window
that hasn't been created.

When you do this...

Quote:
>  editBox.GetDlgItem(IDC_EDIT_BOX);

You are accomplishing nothing. The control IDC_EDIT_BOX is not an Item of the editBox, it is an item
of the dialog.

HTH,

Jeff...

--
Please post all follow-ups to the newsgroup only.

Quote:

>Hello,

>   I am having trouble getting the CEdit box on my dialog window which I
>created with MSVC++6.0 Visual Studio Interface.
>What I want to do is get a particular diglog item and change the
>password character property for the edit box.  I am using this edit box
>for multiple things, so I need to make property changes on the fly.

>.
>.
>.
> CEdit editBox;

>  editBox.GetDlgItem(IDC_EDIT_BOX);
>  editBox.SetPasswordChar('.');
>.
>.
>.

>When I do the above, I get the assertion error in GetDlgItem():
>ASSERT(::IsWindow(m_hWnd));

>Why isn't CEdit also a CWnd object since it inherits from the parent
>CWnd?
>How would I access my CEdit box and apply changes to it after it has
>already been created?

>Thank you very much
>JM



Fri, 14 Feb 2003 03:00:00 GMT  
 Getting CEdit box on a Dialog
Jeff,
   Actually, all I had to do was this:   CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_BOX);
   and that allowed me a pointer to access the edit box and change its properties on the fly.

Thanks for the help!

Quote:

> Hi!

> The easiest way (and arguably the best way) would be to use ClassWizard to add a member control
> variable of the CEdit class to the CDialog. Then you can use it to work with the edit control
> anytime after the call to CDialog::OnInitDialog and before the dialogbox is destroyed. Like

> CMyDialog::SomeFunction()
> {
>     m_edit.SetPasswordChar(0);
> }

> But to do it the way you are trying, you need to call GetDlgItem thru the CDialog derived class --
> the CEdit is an Item of the Dialog. So...

> CMyDialog::SomeFunction()
> {
>     CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_BOX);

>     if (pEdit)
>         pEdit->SetPasswordChar(0);
> }

> Remember, that GetDlgItem returns a possibly temporary pointer to a CWnd, so the cast is necessary.

> The reason you are getting the assert is because when you do this...

> > CEdit editBox;

> You are instantiating a local (I gather) CEdit object, but not calling any method to create the
> underlying HWND, or the value in m_hWnd. And the way almost all of the CEdit member functions work
> is that they wrap a SendMessage(m_hWnd, EM_XXX, ...) call. You can not send a message to a window
> that hasn't been created.

> When you do this...

> >  editBox.GetDlgItem(IDC_EDIT_BOX);

> You are accomplishing nothing. The control IDC_EDIT_BOX is not an Item of the editBox, it is an item
> of the dialog.

> HTH,

> Jeff...

> --
> Please post all follow-ups to the newsgroup only.


> >Hello,

> >   I am having trouble getting the CEdit box on my dialog window which I
> >created with MSVC++6.0 Visual Studio Interface.
> >What I want to do is get a particular diglog item and change the
> >password character property for the edit box.  I am using this edit box
> >for multiple things, so I need to make property changes on the fly.

> >.
> >.
> >.
> > CEdit editBox;

> >  editBox.GetDlgItem(IDC_EDIT_BOX);
> >  editBox.SetPasswordChar('.');
> >.
> >.
> >.

> >When I do the above, I get the assertion error in GetDlgItem():
> >ASSERT(::IsWindow(m_hWnd));

> >Why isn't CEdit also a CWnd object since it inherits from the parent
> >CWnd?
> >How would I access my CEdit box and apply changes to it after it has
> >already been created?

> >Thank you very much
> >JM



Sat, 15 Feb 2003 03:00:00 GMT  
 Getting CEdit box on a Dialog
Even better would be to have class wizard add a control variable.

Yours, Nikolaus

Quote:
> Jeff,
>    Actually, all I had to do was this:   CEdit* pEdit =

(CEdit*)GetDlgItem(IDC_EDIT_BOX);
Quote:
>    and that allowed me a pointer to access the edit box and change its

properties on the fly.
Quote:

> Thanks for the help!


> > Hi!

> > The easiest way (and arguably the best way) would be to use ClassWizard

to add a member control
Quote:
> > variable of the CEdit class to the CDialog. Then you can use it to work

with the edit control
Quote:
> > anytime after the call to CDialog::OnInitDialog and before the dialogbox
is destroyed. Like

> > CMyDialog::SomeFunction()
> > {
> >     m_edit.SetPasswordChar(0);
> > }

> > But to do it the way you are trying, you need to call GetDlgItem thru

the CDialog derived class --
Quote:
> > the CEdit is an Item of the Dialog. So...

> > CMyDialog::SomeFunction()
> > {
> >     CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_BOX);

> >     if (pEdit)
> >         pEdit->SetPasswordChar(0);
> > }

> > Remember, that GetDlgItem returns a possibly temporary pointer to a

CWnd, so the cast is necessary.
Quote:

> > The reason you are getting the assert is because when you do this...

> > > CEdit editBox;

> > You are instantiating a local (I gather) CEdit object, but not calling

any method to create the
Quote:
> > underlying HWND, or the value in m_hWnd. And the way almost all of the

CEdit member functions work
Quote:
> > is that they wrap a SendMessage(m_hWnd, EM_XXX, ...) call. You can not

send a message to a window
Quote:
> > that hasn't been created.

> > When you do this...

> > >  editBox.GetDlgItem(IDC_EDIT_BOX);

> > You are accomplishing nothing. The control IDC_EDIT_BOX is not an Item

of the editBox, it is an item
Quote:
> > of the dialog.

> > HTH,

> > Jeff...

> > --
> > Please post all follow-ups to the newsgroup only.


> > >Hello,

> > >   I am having trouble getting the CEdit box on my dialog window which
I
> > >created with MSVC++6.0 Visual Studio Interface.
> > >What I want to do is get a particular diglog item and change the
> > >password character property for the edit box.  I am using this edit box
> > >for multiple things, so I need to make property changes on the fly.

> > >.
> > >.
> > >.
> > > CEdit editBox;

> > >  editBox.GetDlgItem(IDC_EDIT_BOX);
> > >  editBox.SetPasswordChar('.');
> > >.
> > >.
> > >.

> > >When I do the above, I get the assertion error in GetDlgItem():
> > >ASSERT(::IsWindow(m_hWnd));

> > >Why isn't CEdit also a CWnd object since it inherits from the parent
> > >CWnd?
> > >How would I access my CEdit box and apply changes to it after it has
> > >already been created?

> > >Thank you very much
> > >JM



Sat, 15 Feb 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CEdit box ** CEdit box ** CEdit box

2. Modal dialog boxes and CEdits

3. Problem with CEdit control in a dialog box

4. CEdit w/ ES_PASWORD in a dialog box in XP

5. CEdit in Dialog Box

6. CEdit in dialog box and OnContextMenu()

7. Question about CEdit inside dialog box

8. CEdit* attach to Edit ctrl in dialog box?

9. CEdit problem on dialog box.

10. CEdit problem in a modal dialog box?

11. Insert Tab Characters in CEdit Control in a pop up dialog box

12. CEdit on modeless dialog box

 

 
Powered by phpBB® Forum Software