📄 mdibackground.cpp
字号:
// MdiBackground.cpp : implementation file
//
#include "stdafx.h"
#include "MdiBackground.h"
#include "resource.h" // For access to our bitmap image
#include "MainFrm.h" // For access to the m_MdiBackStyle member
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMdiBackground
CMdiBackground::CMdiBackground()
{
VERIFY( m_bitmap.LoadBitmap( IDB_CLOUDS ) );
}
CMdiBackground::~CMdiBackground()
{
}
BEGIN_MESSAGE_MAP(CMdiBackground, CWnd)
//{{AFX_MSG_MAP(CMdiBackground)
ON_WM_ERASEBKGND()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMdiBackground message handlers
BOOL CMdiBackground::OnEraseBkgnd(CDC* pDC)
{
// Get a pointer to our main frame window
// (to access the m_MdiBackStyle member variable)
CMainFrame* pMainFrame = static_cast< CMainFrame* >( GetParentFrame() );
ASSERT_KINDOF( CMainFrame, pMainFrame );
switch( pMainFrame->m_MdiBackStyle )
{
default:
ASSERT( FALSE ); // Should never get here
return TRUE;
case CMainFrame::NORMAL:
// Draw the standard MDI background
CWnd::OnEraseBkgnd( pDC );
break;
case CMainFrame::CUSTOM:
{
// 1 - Draw the standard MDI background
CWnd::OnEraseBkgnd( pDC );
// 2 - Now draw a yellow rectangle (centered)
CRect rect;
GetClientRect( &rect );
CBrush brYellow( RGB( 255, 255, 0 ) );
CBrush* pOldBrush = pDC->SelectObject( &brYellow );
pDC->PatBlt( rect.left + rect.Width() / 4,
rect.top + rect.Height() / 4,
rect.Width() / 2,
rect.Height() / 2,
PATCOPY );
pDC->SelectObject( pOldBrush );
// 3 - Finally draw the coordinates of the window's corners
pDC->SetTextColor( RGB( 255, 255, 255 ) );
pDC->SetBkMode( TRANSPARENT );
CString s;
// 3a - Upper-left
pDC->SetTextAlign( TA_TOP | TA_LEFT );
s.Format( "( %ld, %ld )", rect.left, rect.top );
pDC->TextOut( rect.left, rect.top, s );
// 3b - Bottom-left
pDC->SetTextAlign( TA_BOTTOM | TA_LEFT );
s.Format( "( %ld, %ld )", rect.left, rect.bottom );
pDC->TextOut( rect.left, rect.bottom, s );
// 3c - Upper-right
pDC->SetTextAlign( TA_TOP | TA_RIGHT );
s.Format( "( %ld, %ld )", rect.right, rect.top );
pDC->TextOut( rect.right, rect.top, s );
// 3d - Bottom-right
pDC->SetTextAlign( TA_BOTTOM | TA_RIGHT );
s.Format( "( %ld, %ld )", rect.right, rect.bottom );
pDC->TextOut( rect.right, rect.bottom, s );
break;
}
case CMainFrame::BITMAP:
{
// 1 - Create a memory DC and select our bitmap into it
CDC dcMem;
dcMem.CreateCompatibleDC( pDC );
CBitmap* pOldBitmap = dcMem.SelectObject( &m_bitmap );
// 2 - Retrieve the size of our bitmap...
BITMAP bmp;
m_bitmap.GetObject( sizeof( bmp ), &bmp );
// 3 - ... and the size of our window's client area
CRect rect;
GetClientRect( &rect );
// 4 - Fill the window's client area with our bitmap
pDC->StretchBlt( rect.left, rect.top,
rect.Width(), rect.Height(),
&dcMem,
0, 0, bmp.bmWidth, bmp.bmHeight,
SRCCOPY );
dcMem.SelectObject( pOldBitmap );
break;
}
}
return TRUE; // Background was erased
}
void CMdiBackground::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
Invalidate( TRUE );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -