Re: Problem Creating numerous edit control's in custom control

From: Bill Thompson (billt61_at_rgv.rr.com)
Date: 08/18/04


Date: Tue, 17 Aug 2004 23:34:39 -0500


"Johan Rosengren" <johan.rosengren@telia.com> wrote in message
news:eNDCh2DhEHA.644@tk2msftngp13.phx.gbl...
> Bill,
>
> Creating once, then moving/hiding, seems to be a far better method.
SetFont
> should by itself not be any problem.
>
> Johan Rosengren
> Abstrakt Mekanik AB
>
> "Bill Thompson" <billt61@rgv.rr.com> a écrit dans le message de
> news:u64qD8AhEHA.636@TK2MSFTNGP12.phx.gbl...
> > Hello,
> >
> > I'm creating yet another custom grid control. I process the
> > ON_WM_LBUTTONDOWN message to determine the row/col of the grid, and
create
> > an edit control on the fly which is placed in the correct position in
the
> > grid. When the user clicks in another location on the grid, I delete
the
> > current edit control, and create a new control in the appropriate place.
> >
> > Everything is working fine, except that as time goes on, and more and
more
> > edit controls are created and deleted, the performance degrades. The
> > performance problem seems to be entirely related to creating edit
> controls;
> > if I simply scroll the grid it works fine.
> >
> > I suspect I'm not destroying the edit control correctly. The creation
> code
> > looks like this:
> >
> > m_EditControl = new CGridEdit();
> >
> > bool Created = (m_EditControl->Create(WS_VISIBLE | ES_AUTOHSCROLL,
> > EditRect, this,
> > IDC_MYEDITCTRL) != 0);
> > m_EditControl->SetFont(m_EditFont, FALSE);
> > // m_OrigData is a CString containing the cell contents
> > m_EditControl->SetWindowText(m_OrigData);
> > // CurPos is an input parameter
> > m_EditControl->SetSel(CurPos, CurPos);
> > m_EditControl->SetParent(this);
> > m_EditControl->SetFocus();
> >
> > NOTE: IDC_MYEDITCONTROL = 1003, and is defined in resource.h
> >
> > the deletion code looks like this:
> >
> > m_EditControl->SendMessage(WM_CLOSE);
> > // m_EditControl->DestroyWindow();
> > delete m_EditControl;
> > m_EditControl = NULL;
> >
> > I used to use DestroyWindow, changed to WM_CLOSE with no improvement.
Am
> I
> > getting into trouble because of the SetFont() in the creation process?
> >
> > I am considering working around this problem by creating the edit
control
> > once and using MoveWindow to position it on subsequent invocations. I
> > presume I can use something like ShowWindow(SW_HIDE) and
> ShowWindow(SW_SHOW)
> > to disable it.
> >
> > Thanks,
> >
> > Bill Thompson
> >
> >
>
Thanks Johan. FYI, after really studying WM_PAINT and WM_ERASEBKGND I went
though and really optimized the OnPaint procedure to draw as little as
possible. I also used the one time instantiation of the edit control.
Unfortunately, the problem remained. I rebooted the computer, and have
since been unable to reproduce the problem. I guess my VC 6.0 Windows ME
development environment leaves something to be desired.