15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Child windows in MDI child

rick cameron -- rick_cameron@msn.com
Monday, March 25, 1996

Hi, Pedro

An OWL program and an MFC program take different approaches
to creating child windows.

In OWL, you declare a pointer member in the parent window class,
and allocate the child window object in the constructor of the parent
window, using 'new'. OWL takes care of actually creating the Windows windows
for both parent and child.

e.g.

class TParent : public TWindow
{
  ...
  protected:
    TChild *child;
  ...
};

TParent::TParent (...)
{
  ...
  child = new TChild (this, ...);
  ...
}

In MFC, you declare an instance of the child class as a member variable of the 

parent class. In the Create (or OnCreate) member function of the parent class
you call the Create member of the child.

e.g.

class CParent : public CWnd
{
  ...
  protected:
    CChild child;
  ...
};

BOOL CParent::Create (...)
{
  ...
  if (!child.Create (this, ...))
    return FALSE;
  ...
}

If you change over to doing things this way, you may get better results.

You should use CMDIChildWnd as the base class for your MDI child frame.

If (most of) the child windows really do behave like toolbars, you may want to 
consider
deriving them from CControlBar; then MFC will take care of geometry management 
(i.e.
rearranging the child windows when the MDI child frame changes size).

In any case, calling MoveWindow inside a WM_PAINT message is (to put it 
mildly) rather unusual
and a recipe for disaster: if moving the child window leads to a need to 
repaint the parent 
(which is currently processing its WM_PAINT), you will get undesired redraw 
behaviour.

As a rule, I try to restrict what my code does in handling WM_PAINT to simply 
repainting the
requested portion of this window; any other behaviour I handle in some other 
message.

Hope this helps!

- rick
----------
From: 	owner-mfc-l@netcom.com on behalf of Pedro Vicente
Sent: 	March 25, 1996 0:29
To: 	'mfc list mfc-l@netcom.com'
Subject: 	FW: Child windows in MDI child


Environment: VC++ 4.0 / Win 95

Hi
I am a Windows programmer for some years now but
I ' ve been tied up only to Borland. I started learning MFC some 
time ago. What I am doing now is converting some of my old OWL 1.0 
programs to MFC 4.0. 

I am trying to display several child windows inside a MDI child
window (in MFC). 

I used this approach in an old OWL program I did,
a graphical interface for displaying data (I work in
oceanography) . A version of this application, called MODBWin, is available
in www on
http://modb.oce.ulg.ac.be//
or
http://modb.oce.ulg.ac.be/ModbWin.html
(My adress is changed, it is now :
http://hidro1.ist.utl.pt/people/maretec/mare1.htm
or
http://hidro1.ist.utl.pt/people/maretec/vicente/vicente_p.htm
(sorry, pages mostly in Portuguese)

so you can get an idea of what the program is. The program
displays several things in a MDI child window : a map, a legend, 
some tools, and some numeric info . * All * these
things are OWL child windows (whose parent is the MDI child).

The code looks something like this:

//****************************************************************************
*****

//--------------------------- TMyChildWindow -----------------------------

class TMyChildWindow: public TWindow
{
 protected:
  PTBar ToolBar;
  PTBar ToolBarPoli;
  PTBar ToolBarSoma;  //these are several chil windows to display info

 public:
  TMyChildWindow( PTWindowsObject AParent, LPSTR ATitle );
  virtual void Paint( HDC DC, PAINTSTRUCT& PS );
  virtual void MoveWindows();
   TState State;
 };

TMyChildWindow::TMyChildWindow( PTWindowsObject AParent, LPSTR ATitle )
  : TWindow( AParent, ATitle )
{
 Attr.Style = Attr.Style | WS_MAXIMIZE;
 State.DrawTool = NULL;
 State.hBitMap = 0; // change data between windows
 ToolBar = new TToolBar( this, &State );
 ToolBarPoli = new TToolBarPoli( this, &State );

 ...
}

void TMyChildWindow::Paint( HDC, PAINTSTRUCT& )
{
 MoveWindows();
}

void TMyChildWindow::MoveWindows()
{
  MoveWindow( State.Mapa->HWindow,
  SP, SP,
  CM, LM, TRUE );
... //etc
}

//****************************************************************************
*****

What I do is to initialize several Toolbars (which are 
child windows) inside the MDI child and to use the ::MoveWindow
function inside a Paint method to display them. The child windows
all have a Paint method of their own , so all my stull gets
nicely into the screen. This 
works fine.

Now I am trying to convert the OWL code to MFC. I did the following:

//****************************************************************************
*****

//this is the child that is to be displayed inside the MDI child

class CMapWindow: public CFrameWnd
{
 public:
  CMapWindow();
  afx_msg void OnPaint();
//other stuff
 };

void CMapWindow::OnPaint()
{
 //draw something
}

/////////////////////// now for the MDI child ///////////////////////////////

class CHelloWnd : public CMDIChildWnd
{
 public:
  CHelloWnd();
   CMapWindow *pCMapWindow;  //pointer to the chil window
    afx_msg void OnPaint();
	
};

BOOL CHelloWnd::Create(LPCTSTR szTitle, LONG style /* = 0 */,
	const RECT& rect /* = rectDefault */,
	CMDIFrameWnd* parent /* = NULL */)
{
 pCMapWindow = new CMapWindow;
 pCMapWindow->Create( this );
//create the child window

 return CMDIChildWnd::Create(lpszHelloClass, szTitle, style, rect, parent);
}

void CHelloWnd::OnPaint()
{
 ::MoveWindow( pCMapWindow->m_hWnd, 10, 10, 100, 100, TRUE ); 
}

//display it. BUT THIS DOES WORK, it does not display anything

Can anyone give some hints on this ? Thanks in advance.

Pedro Vicente











Pedro Vicente -- vicente@hidro1.ist.utl.pt
Wednesday, April 03, 1996

Hi Rick

Thanks for the advice. I bought Kruglinsky's book on VC++ and
I am on MFC now.

Anyway , I still have some doubts about rearranjing the child windows
inside a MDI child. The aproach I did to solve this was not to define 
several childs but instead paint several things on the MDI child
client dc.

The disavantadge is that I loose flexibility on the control
of the program.

What I do now is this

void CHidroView::Show()
{
	CClientDC dc(this);
	Mapa->Mostra( dc.m_hDC, m_hWnd, pDoc->transfer );
	Grafico->Mostra( dc.m_hDC, m_hWnd, pDoc->transfer );
}

The Mapa and Grafico are objects that were OWL windows before.  

Pedro Vicente

----------
From: 	rick cameron[SMTP:rick_cameron@msn.com]
Sent: 	terca-feira, 26 de marco de 1996 0:20
To: 	mfc-l@netcom.com
Subject: 	RE: Child windows in MDI child

Hi, Pedro

An OWL program and an MFC program take different approaches
to creating child windows.

In OWL, you declare a pointer member in the parent window class,
and allocate the child window object in the constructor of the parent
window, using 'new'. OWL takes care of actually creating the Windows windows
for both parent and child.

e.g.

class TParent : public TWindow
{
  ...
  protected:
    TChild *child;
  ...
};

TParent::TParent (...)
{
  ...
  child = new TChild (this, ...);
  ...
}

In MFC, you declare an instance of the child class as a member variable of the 

parent class. In the Create (or OnCreate) member function of the parent class
you call the Create member of the child.

e.g.

class CParent : public CWnd
{
  ...
  protected:
    CChild child;
  ...
};

BOOL CParent::Create (...)
{
  ...
  if (!child.Create (this, ...))
    return FALSE;
  ...
}

If you change over to doing things this way, you may get better results.

You should use CMDIChildWnd as the base class for your MDI child frame.

If (most of) the child windows really do behave like toolbars, you may want to 
consider
deriving them from CControlBar; then MFC will take care of geometry management 
(i.e.
rearranging the child windows when the MDI child frame changes size).

In any case, calling MoveWindow inside a WM_PAINT message is (to put it 
mildly) rather unusual
and a recipe for disaster: if moving the child window leads to a need to 
repaint the parent 
(which is currently processing its WM_PAINT), you will get undesired redraw 
behaviour.

As a rule, I try to restrict what my code does in handling WM_PAINT to simply 
repainting the
requested portion of this window; any other behaviour I handle in some other 
message.

Hope this helps!

- rick
----------
From: 	owner-mfc-l@netcom.com on behalf of Pedro Vicente
Sent: 	March 25, 1996 0:29
To: 	'mfc list mfc-l@netcom.com'
Subject: 	FW: Child windows in MDI child


Environment: VC++ 4.0 / Win 95

Hi
I am a Windows programmer for some years now but
I ' ve been tied up only to Borland. I started learning MFC some 
time ago. What I am doing now is converting some of my old OWL 1.0 
programs to MFC 4.0. 

I am trying to display several child windows inside a MDI child
window (in MFC). 

I used this approach in an old OWL program I did,
a graphical interface for displaying data (I work in
oceanography) . A version of this application, called MODBWin, is available
in www on
http://modb.oce.ulg.ac.be//
or
http://modb.oce.ulg.ac.be/ModbWin.html
(My adress is changed, it is now :
http://hidro1.ist.utl.pt/people/maretec/mare1.htm
or
http://hidro1.ist.utl.pt/people/maretec/vicente/vicente_p.htm
(sorry, pages mostly in Portuguese)

so you can get an idea of what the program is. The program
displays several things in a MDI child window : a map, a legend, 
some tools, and some numeric info . * All * these
things are OWL child windows (whose parent is the MDI child).

The code looks something like this:

//****************************************************************************
*****

//--------------------------- TMyChildWindow -----------------------------

class TMyChildWindow: public TWindow
{
 protected:
  PTBar ToolBar;
  PTBar ToolBarPoli;
  PTBar ToolBarSoma;  //these are several chil windows to display info

 public:
  TMyChildWindow( PTWindowsObject AParent, LPSTR ATitle );
  virtual void Paint( HDC DC, PAINTSTRUCT& PS );
  virtual void MoveWindows();
   TState State;
 };

TMyChildWindow::TMyChildWindow( PTWindowsObject AParent, LPSTR ATitle )
  : TWindow( AParent, ATitle )
{
 Attr.Style = Attr.Style | WS_MAXIMIZE;
 State.DrawTool = NULL;
 State.hBitMap = 0; // change data between windows
 ToolBar = new TToolBar( this, &State );
 ToolBarPoli = new TToolBarPoli( this, &State );

 ...
}

void TMyChildWindow::Paint( HDC, PAINTSTRUCT& )
{
 MoveWindows();
}

void TMyChildWindow::MoveWindows()
{
  MoveWindow( State.Mapa->HWindow,
  SP, SP,
  CM, LM, TRUE );
... //etc
}

//****************************************************************************
*****

What I do is to initialize several Toolbars (which are 
child windows) inside the MDI child and to use the ::MoveWindow
function inside a Paint method to display them. The child windows
all have a Paint method of their own , so all my stull gets
nicely into the screen. This 
works fine.

Now I am trying to convert the OWL code to MFC. I did the following:

//****************************************************************************
*****

//this is the child that is to be displayed inside the MDI child

class CMapWindow: public CFrameWnd
{
 public:
  CMapWindow();
  afx_msg void OnPaint();
//other stuff
 };

void CMapWindow::OnPaint()
{
 //draw something
}

/////////////////////// now for the MDI child ///////////////////////////////

class CHelloWnd : public CMDIChildWnd
{
 public:
  CHelloWnd();
   CMapWindow *pCMapWindow;  //pointer to the chil window
    afx_msg void OnPaint();
	
};

BOOL CHelloWnd::Create(LPCTSTR szTitle, LONG style /* = 0 */,
	const RECT& rect /* = rectDefault */,
	CMDIFrameWnd* parent /* = NULL */)
{
 pCMapWindow = new CMapWindow;
 pCMapWindow->Create( this );
//create the child window

 return CMDIChildWnd::Create(lpszHelloClass, szTitle, style, rect, parent);
}

void CHelloWnd::OnPaint()
{
 ::MoveWindow( pCMapWindow->m_hWnd, 10, 10, 100, 100, TRUE ); 
}

//display it. BUT THIS DOES WORK, it does not display anything

Can anyone give some hints on this ? Thanks in advance.

Pedro Vicente










begin 600 WINMAIL.DAT
M>)\^(B@5`0:0" `$```````!``$``0>0!@`(````Y 0```````#H``$-@ 0`
M`@````$``0`!!) &``P!```!````# ````,``# #````"P`/#@`````"`?\/
M`0```#\`````````@2L?I+ZC$!F=;@#=`0]4`@````!M9F,M;$!N971C;VTN
M8V]M`%--5% `;69C+6Q ;F5T8V]M+F-O;0``'@`", $````%````4TU44 ``
M```>``,P`0```!$```!M9F,M;$!N971C;VTN8V]M``````,`%0P!`````P#^
M#P8````>``$P`0```!,````G;69C+6Q ;F5T8V]M+F-O;2<```(!"S !````
M%@```%--5% Z349#+4Q 3D540T]-+D-/30````,``#D`````"P! .@$````"
M`?8/`0````0````````#/RP!"( '`!@```!)4$TN36EC`' ``0```!\```!213H@0VAI;&0@=VEN
M9&]WM`P`'$)03```>``@0
M`0```&4```!(25))0TM42$%.2U-&3U)42$5!1%9)0T5)0D]51TA42U)51TQ)
M3E-+65-"3T]+3TY60RLK04Y$24%-3TY-1D-.3U=!3EE705DL25-424Q,2$%6
M15-/345$3U5"5%-!0D]55%)%``````(!"1 !````;@X``&H.```7(0``3%I&
M=?B70&/_``H!#P(5`J@%ZP*#`% "\@D"`&-H"L!S970R-P8`!L,"@S(#Q0(`
M<')"<1'B7=A>2"^+!VA$\ #$ ,@$8!V
M'1"6W"H5C'H )\+D%0&1C(7TH8BE 
M[UDN)#!(XM-A#U3;4D5F4$,E
M^B<1\R]?35TS-D]G&D509AKP_R+03!,ACDG3-G5'LP.1(0+[;O8!D&LR`@W0
M2:$MT2B@_RBT!Y *A2F!!0`D\",@)7';)>LA?4ENDR+0>0A@*P'W,&!(@B>0
M<#H03+$%P > _P;007%I438S2($MT29$,%'Y*G!S+ J%;W,C0$30,T"_*?(E
MS$BU=V8U(4,Q=4D`OP6Q-@9W\PJ%)D0BT'4`D.4E<2,,<,%!W]&90<"0P'H#>8QPP@B0[?DL0+HH@B9=;4&4)@#J)ETL05&AT*O\E
MXSWFB@I&,#WF&]:'E#KPO8>&*(HA.V^*#"7D/2$P_P?1C#4]@R+0D'*-#T8/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