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

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


Painting on the background of the MainFrame window

David Lantsman -- davidlan@luckynet.co.il
Monday, February 10, 1997

Environment: Visual C++ 4.0 Windows 95

Hello,

Is it possible to paint of the background of an MDI Main Frame
window (CMDIFrameWnd) without having any of the child windows
opened? How can I do it?

Thank you in advance,
	David Lantsman

==================================
Lantiv, David Lantsman

http://www.luckynet.co.il/~davidlan
davidlan@luckynet.co.il
==================================




Charlie Jursch -- cjursch@pacbell.net
Monday, February 10, 1997

[Mini-digest: 4 responses]

David,

There is a great book to get your hands on published by The Waite Group
called Visual C++ How-To.  On page 259 you will find an example of all of
the steps you need to follow.  If you can't get a copy of the book, e-mail
me and I will send you code examples.


Charlie

At 05:32 AM 2/10/97 +0200, you wrote:
>Environment: Visual C++ 4.0 Windows 95
>
>Hello,
>
>Is it possible to paint of the background of an MDI Main Frame
>window (CMDIFrameWnd) without having any of the child windows
>opened? How can I do it?
>
>Thank you in advance,
>	David Lantsman
>
>==================================
>Lantiv, David Lantsman
>
>http://www.luckynet.co.il/~davidlan
>davidlan@luckynet.co.il
>==================================
>
>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Charlie Jursch              "Be kind to your web-footed
Patotech Software, Inc.      friends for a duck may be
1-800-PATOTECH               somebody's mother."
mailto:cjursch@pacbell.net    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-----From: David Little 


Yes, it is possible and really easy, but it is kind of tricky.  You have =
to derive your own CWnd-derived class that handles OnEraseBackground and =
OnSize, then subclass the client window in OnCreateClient in CMainFrame. =
 I have this written, and if you would like a copy, (or anybody), let me =
know and I will send it to you.

David Little
dlittle@equinoxcorp.com

----------
From: 	David Lantsman[SMTP:davidlan@luckynet.co.il]
Sent: 	Sunday, February 09, 1997 9:32 PM
To: 	mfc-l@netcom.com
Subject: 	Painting on the background of the MainFrame window

Environment: Visual C++ 4.0 Windows 95

Hello,

Is it possible to paint of the background of an MDI Main Frame
window (CMDIFrameWnd) without having any of the child windows
opened? How can I do it?

Thank you in advance,
	David Lantsman

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
Lantiv, David Lantsman

http://www.luckynet.co.il/~davidlan
davidlan@luckynet.co.il
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D


-----From: cugr1@gd.swissptt.ch (Cunningham Graham, IT347)


You need to sublass the mdi client window (m_hhWndMDIClient) in   =
CMainFrame::CreateClient() with your own mdi client window which will   =
then handle the WM_ERASEBKGND message. There is an article on this on the   =
=
msdn =22Painting the MDI client area=22 but if you dont have this I will dig=
   =
out the code


 ----------
Von:  David Lantsman=5BSMTP:davidlan=40luckynet.co.il=5D
Gesendet:  Montag, 10. Februar 1997 04:32
An:  mfc-l=40netcom.com
Betreff:  Painting on the background of the MainFrame window

Environment: Visual C++ 4.0 Windows 95

Hello,

Is it possible to paint of the background of an MDI Main Frame
window (CMDIFrameWnd) without having any of the child windows
opened? How can I do it?

Thank you in advance,
 David Lantsman

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Lantiv, David Lantsman

http://www.luckynet.co.il/=7Edavidlan
davidlan=40luckynet.co.il
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


-----From: "Dmitry A. Dulepov" 

        [Mailer: "Groupware E-Mail". Version 1.03.000]

>        [From: David Lantsman
>
>Is it possible to paint of the background of an MDI Main Frame
>window (CMDIFrameWnd) without having any of the child windows
>opened? How can I do it?
>

You will have to override CMDIFrameWnd::CreateClient(). "Background of an MDI Main Frame" is really a window of "MDIChild" class. Create this window in your CreateClient() just like standard implementation does, create a CYourWnd and attach it to created MDI client. Add OnPaint() handler to CYourWnd and draw what do you want...


Dmitry A. Dulepov
Samsung Electronics Co., Ltd.
Russian Research Center
Phone: +7 (095) 213-9207
Fax: +7 (095) 213-9196
E-mail: dima@src.samsung.ru
====================================




Mike Marshall -- marshall@milner.com
Tuesday, February 11, 1997

[Mini-digest: 2 responses]

It seems this question comes up about once a month on this list or on the
newsgroups.  There was an article in MSDN (its probably in the "archive"
CD with the new MSDN) called (I think) "Customizing the MDI Client area".
It was written for 16 bit, but it's almost exactly the same for 32 bit.

[Moderator's note: Really?  I actually don't remember it coming up here
before.  I must be a newbie... ;-]

This gist of the article is that you subclass the MDI client window and handle the
WM_ERASEBKGND message to customize your MDI client area.  Remember, the 
MDI client window is a _different_ window than the main frame window.  What you see
behind MDI windows is not the client area of the main frame window, but the MDI client
window.

They also provided a sample called TANGRAM with code on how to do this.  If you want
any more information, e-mail me and I'll try to find the article which describes the
process in detail.  For starters, here's what you do:

1. Create a new class in class wizard (call it CMDIClientWnd or something like that),
     with the base class just being a generic CWnd.
2.  In you main frame window's OnCreateClient, subclass the m_hMDIClientWnd member
     of the main frame window to your new CMDIClientWnd (create a CMDIClientWnd member
     of you main window class to make this easier).
3. Create an OnEraseBkgnd handler for you CMDIClientWnd class that paints the background
    accordingly..

Mike

----------
From:  David Lantsman[SMTP:davidlan@luckynet.co.il]
Sent:  Sunday, February 09, 1997 9:33 PM
To:  mfc-l@netcom.com
Subject:  Painting on the background of the MainFrame window

Environment: Visual C++ 4.0 Windows 95

Hello,

Is it possible to paint of the background of an MDI Main Frame
window (CMDIFrameWnd) without having any of the child windows
opened? How can I do it?

Thank you in advance,
	David Lantsman

==================================
Lantiv, David Lantsman

http://www.luckynet.co.il/~davidlan
davidlan@luckynet.co.il
==================================


-----From: Joe Willcoxson 

--=====================_855704779==_
Content-Type: text/plain; charset="us-ascii"

At 05:32 AM 2/10/97 +0200, you wrote:
>Environment: Visual C++ 4.0 Windows 95
>
>Hello,
>
>Is it possible to paint of the background of an MDI Main Frame
>window (CMDIFrameWnd) without having any of the child windows
>opened? How can I do it?

I'll respond with what you should do, not what you can do.  What you
probably should do is subclass the MDICLIENT window that the MDI frame
owns.  You then can override its processing for WM_PAINT or
WM_ERASEBACKGROUND.  Attached are some files that subclass the MDICLIENT
and draw a bitmap in the center of the window.

--=====================_855704779==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="Mainfrm.cpp"

// MAINFRM.CPP

// Viper Graphics source files copyright 1993-1996 by Joe Willcoxson
// These source files may not be copied except by permission of the author
// No warranty or guarrantee of fitness can be made to these files
// These files may not be sold or included in any type of commercial or non-commercial distribution


// mainfrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "vgmfc.h"

#include "mainfrm.h"

#include "mdiclien.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
      
#define new DEBUG_NEW      
      
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_SYSCOLORCHANGE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// arrays of IDs used to initialize control bars

// toolbar buttons - IDs are command buttons
static UINT BASED_CODE buttons[] =
{
	// same order as in the bitmap 'toolbar.bmp'
	ID_FILE_NEW,
	ID_FILE_OPEN,
	ID_FILE_SAVE,
		ID_SEPARATOR,
	ID_EDIT_CUT,
	ID_EDIT_COPY,
	ID_EDIT_PASTE,
		ID_SEPARATOR,
	ID_FILE_PRINT,
	ID_APP_ABOUT,
		ID_SEPARATOR,
	ID_VIEW_DATAWINDOW,
	ID_VIEW_GRAPHWINDOW,
	ID_SEPARATOR,
	ID_GRAPH_ADDTEXT,
	ID_GRAPH_ADDXAXIS,
	ID_GRAPH_ADDYAXIS,
	ID_GRAPH_ADDDATASET
};

static UINT BASED_CODE indicators[] =
{
	ID_SEPARATOR,			// status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_pWndMDIClient = new CMDIClientWnd(IDC_SPLASHD);
}

CMainFrame::~CMainFrame()
{
	delete m_pWndMDIClient;
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!m_wndToolBar.Create(this) ||
		!m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
		!m_wndToolBar.SetButtons(buttons,
		  sizeof(buttons)/sizeof(UINT)))
	{
		TRACE("Failed to create toolbar\n");
		return -1;		// fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE("Failed to create status bar\n");
		return -1;		// fail to create
	}
	
	m_pWndMDIClient->SubclassWindow(m_hWndMDIClient);

	return 0;
}


/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

void CMainFrame::OnSysColorChange()
{
	CMDIFrameWnd::OnSysColorChange();
	
//	Ctl3dColorChange();
	
}


// Copyright 1993-1996 by Joe Willcoxson
// E-mail:  chinajoe@aol.com
// URL:  http://users.aol.com/chinajoe
// MAINFRM.CPP


--=====================_855704779==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="Mainfrm.h"

// MAINFRM.H

// Viper Graphics source files copyright 1993-1996 by Joe Willcoxson
// These source files may not be copied except by permission of the author
// No warranty or guarrantee of fitness can be made to these files
// These files may not be sold or included in any type of commercial or non-commercial distribution


// mainfrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

class CMDIClientWnd;

class CMainFrame : public CMDIFrameWnd
{
	DECLARE_DYNAMIC(CMainFrame)
public:
	CMainFrame();

// Attributes
public:

// Operations
public:

// Implementation
public:
	virtual ~CMainFrame();
#ifdef _DEBUG
	virtual	void AssertValid() const;
	virtual	void Dump(CDumpContext& dc) const;
#endif


protected:	// control bar embedded members
	CStatusBar	m_wndStatusBar;
	CToolBar	m_wndToolBar;
	CMDIClientWnd* m_pWndMDIClient;

// Generated message map functions
protected:
	//{{AFX_MSG(CMainFrame)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSysColorChange();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

// Copyright 1993-1996 by Joe Willcoxson
// E-mail:  chinajoe@aol.com
// URL:  http://users.aol.com/chinajoe
// MAINFRM.H


--=====================_855704779==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="Mdiclien.cpp"

// MDICLIEN.CPP

// Viper Graphics source files copyright 1993-1996 by Joe Willcoxson
// These source files may not be copied except by permission of the author
// No warranty or guarrantee of fitness can be made to these files
// These files may not be sold or included in any type of commercial or non-commercial distribution


// mdiclien.cpp : implementation file
//

#include "stdafx.h"
#include "vgmfc.h"
#include "mdiclien.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

#define new DEBUG_NEW

/////////////////////////////////////////////////////////////////////////////
// CMDIClientWnd

CMDIClientWnd::CMDIClientWnd(UINT bitmapID)
{
	m_Bitmap.LoadBitmap(bitmapID);
	ASSERT(m_Bitmap.GetSafeHandle());
}

CMDIClientWnd::~CMDIClientWnd()
{
}

BEGIN_MESSAGE_MAP(CMDIClientWnd, CWnd)
	//{{AFX_MSG_MAP(CMDIClientWnd)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMDIClientWnd message handlers

WNDPROC* CMDIClientWnd::GetSuperWndProcAddr()
{
 	static WNDPROC addr = 0;
 	return &addr;
}


void CMDIClientWnd::OnPaint()
{
	BITMAP BitInfo;
	CRect R;
	GetClientRect(&R);
	CDC MemDC;

	CPaintDC dc(this); // device context for painting
	
	MemDC.CreateCompatibleDC(&dc);
	m_Bitmap.GetObject(sizeof(BitInfo), &BitInfo);
	CBitmap* oldBitmap = MemDC.SelectObject(&m_Bitmap);   // swap BMs
	R.left = R.right / 2 - BitInfo.bmWidth / 2;
	R.top = R.bottom / 2 - BitInfo.bmHeight / 2;
	if (R.left < 0)
		R.left = 0;
	if (R.top < 0)
		R.top = 0;
	dc.BitBlt(R.left, R.top, BitInfo.bmWidth, BitInfo.bmHeight,
         &MemDC, 0, 0, SRCCOPY);
   MemDC.SelectObject(oldBitmap);
}

BOOL CMDIClientWnd::SubclassWindow(HWND hWnd)
{
	if (!CWnd::SubclassWindow(hWnd))
		return FALSE;
#ifndef WIN32		
	WORD oldStyle = GetClassWord(hWnd, GCW_STYLE);
	oldStyle |= (CS_HREDRAW | CS_VREDRAW);
	SetClassWord(hWnd, GCW_STYLE, oldStyle);
#else
	LONG oldStyle = GetClassLong(hWnd, GCL_STYLE);
	oldStyle |= (CS_HREDRAW | CS_VREDRAW);
	SetClassWord(hWnd, GCL_STYLE, oldStyle);
#endif
	return TRUE;
}

BOOL CMDIClientWnd::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	
	CRect R;
	GetClientRect(&R);
	CBrush brush;
	brush.CreateSolidBrush(RGB(192,192, 192));
	pDC->FillRect(&R, &brush);
	 
	return 0; 
	//return CWnd::OnEraseBkgnd(pDC);
}

// Copyright 1993-1996 by Joe Willcoxson
// E-mail:  chinajoe@aol.com
// URL:  http://users.aol.com/chinajoe
// MDICLIEN.CPP


--=====================_855704779==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="Mdiclien.h"

// MDICLIEN.H

// Viper Graphics source files copyright 1993-1996 by Joe Willcoxson
// These source files may not be copied except by permission of the author
// No warranty or guarrantee of fitness can be made to these files
// These files may not be sold or included in any type of commercial or non-commercial distribution


// mdiclien.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CMDIClientWnd window

class CMDIClientWnd : public CWnd
{
// Construction
public:
	CMDIClientWnd(UINT bitmapID);

// Attributes
public:

// Operations
public:

	BOOL SubclassWindow(HWND hWnd);

// Implementation
public:
	virtual ~CMDIClientWnd();

protected:
	// Generated message map functions
	//{{AFX_MSG(CMDIClientWnd)
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
	
	WNDPROC* GetSuperWndProcAddr();
	CBitmap m_Bitmap;
};

/////////////////////////////////////////////////////////////////////////////

// Copyright 1993-1996 by Joe Willcoxson
// E-mail:  chinajoe@aol.com
// URL:  http://users.aol.com/chinajoe
// MDICLIEN.H


--=====================_855704779==_
Content-Type: text/plain; charset="us-ascii"


--
Gloria in excelsius Deo
Joe Willcoxson (joew@statsoft.com), Senior Software Engineer
Visit us: http://www.statsoft.com, Visit me: http://users.aol.com/chinajoe
#define STD_DISCLAIMER "I speak only for myself"
__cplusplus spoken here;
--=====================_855704779==_--





Alexander Grigoriev -- alegr@aha.ru
Tuesday, February 11, 1997

subclass MDIClient window and override OnEraseBkgnd.

----------
> From: David Lantsman 
> To: mfc-l@netcom.com
> Subject: Painting on the background of the MainFrame window
> Date: 10 ЖЕЧТБМС 1997 З. 6:32
> 
> Environment: Visual C++ 4.0 Windows 95
> 
> Hello,
> 
> Is it possible to paint of the background of an MDI Main Frame
> window (CMDIFrameWnd) without having any of the child windows
> opened? How can I do it?
> 
> Thank you in advance,
> 	David Lantsman
> 
> ==================================
> Lantiv, David Lantsman
> 
> http://www.luckynet.co.il/~davidlan
> davidlan@luckynet.co.il
> ==================================
> 




Become an MFC-L member | Вернуться в корень Архива |