CWnd child window inside a CView
Pedro Vicente -- vicente@hidro1.ist.utl.pt
Saturday, April 13, 1996
Hi, thanks
Yes, I think it must be something like that. The problem here
is that I want also to acess some document data BEFORE the
child windows of the view are created (in order to size them).
I tried your suggestion of OnCreate but it does not work. The
debugger shows that when OnCreate of both the view and the
views childs the doc is not yet initialized (well, it is
but I must put the data initialized on the NewDocument's doc).
(is this getting confusing ? :=) )
Anyway , the only solution I found was to put the creation of
the view's childs inside the OnDraw ( ! ) with a INI flag.
Perhaps I'm missing something here but it works !
Here is the code:
I have two Cwnd chlids inside the view. Here is one of them: it
creates a bitmap on a timer basis. I must access the doc data on Init.
class CCaMalha : public CWnd
{
...
};
void CCaMalha::OnPaint()
{
CPaintDC dc(this); // device context for painting
if ( INI ) {
Init();
INI = 0;
}
LoadBitmapa( dc.m_hDC );
}
void CCaMalha::Init()
{
CCaDocument* pDoc = GetDoc();
Comp = pDoc->Comp;
Larg = pDoc->Larg;
CriarBitmapa();
}
//////////////////////////////////////////////////////////////////////
Now inside the view I declare the two CWnd childs:
class CCaView : public CCaBaseView
{
protected:
BOOL INI;
//janelas filhas
CCaMalha *Malha;
CCaLegend *Legenda;
...
};
void CCaView::OnDraw(CDC* pDC)
{
//Show();
if ( INI ) {
int SP = 2;
CCaDocument* pDoc = (CCaDocument*)GetDocument();
int C = pDoc->Comp;
int L = pDoc->Larg;
int LL = pDoc->Actual.Estados * 30;
Malha->Create( CRect( SP, SP, C, L ), this );
Legenda->Create( CRect( SP + C, SP, SP + C + 80, LL ), this );
INI = 0;
}
}
////////////////////////////////////////////////
and finally the doc
CCaDocument::CCaDocument()
{
RUN = FALSE; //menu inicial
Automato = 0;
}
BOOL CCaDocument::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
Colunas = 40;
Linhas = 40;
Lado = AjustarLadoCa( Colunas );
Comp = Colunas * Lado;
Larg = Linhas * Lado;
strcpy( RuleName, "LIFE" ); //caso de Clear
Automato = new TLife( Colunas, Linhas );
Automato->ContarEstados();
Actual.Estado = 1;
Actual.Estados = Automato->Estados; //depende de cada automato
return TRUE;
}
Pedro Vicente
-----------------------
Pedro Vicente
Take a look at the MARETEC home page :
http://hidro1.ist.utl.pt
----------
From: DrLaz@aol.com[SMTP:DrLaz@aol.com]
Sent: quinta-feira, 11 de abril de 1996 20:43
To: Pedro Vicente
Subject: Re: CWnd child window inside a CView
On 11 Apr 1996 01:20:22 GMT, you wrote:
>Hello
>I am trying to display several child windows inside a CView.
where does your code fail?
I usually put the child creation in the OnCreate Handler, not in
overriding the Create method. Perhaps the problem is that the child is
being created before the HWND in CWnd::Create, so you might try
calling that FIRST in your create and then creating the child.
andy
Niels Ull Jacobsen -- nuj@kruger.dk
Tuesday, April 16, 1996
At 17:48 13-04-96 +-200, you wrote:
>Hi, thanks
>
>Yes, I think it must be something like that. The problem here
>is that I want also to acess some document data BEFORE the=20
>child windows of the view are created (in order to size them).
>
>I tried your suggestion of OnCreate but it does not work. The
>debugger shows that when OnCreate of both the view and the=20
>views childs the doc is not yet initialized (well, it is
>but I must put the data initialized on the NewDocument's doc).=20
>(is this getting confusing ? :=3D) )
Try OnInitialUpdate() - the document and the document pointer should be
initialised at that time.
Niels Ull Jacobsen, Kr=FCger A/S (nuj@kruger.dk)
Everything stated herein is THE OFFICIAL POLICY of the entire Kruger grou=
p
and should be taken as legally binding in every respect. Pigs will grow
wings and fly.
| Вернуться в корень Архива
|