⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientframe.cpp

📁 visual c++ 实例编程
💻 CPP
字号:
// ClientFrame.cpp : implementation file
//
//
// Adjustments: Albert 'The Mad Butcher!' van Peppen, 17 Dec, 1999
//		Looks better than the original version ;)
//		Added functions to Get/Set Centered/Tiled/Stretched/Transparant images
//

#include "stdafx.h"
#include "resource.h"
#include "ClientFrame.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

WNDPROC CClientFrame::pfnSuper = NULL;

/////////////////////////////////////////////////////////////////////////////
// CClientFrame

IMPLEMENT_DYNCREATE(CClientFrame, CWnd)

CClientFrame::CClientFrame()
{
	m_cHelper.GetBitmapAndPalette(IDB_BMP_D4W, m_bitmap, m_palette);
	m_bTiled = FALSE;
	m_bCentered = FALSE;
	m_bFitToClient = TRUE;
	m_bTransparent = FALSE;
}

CClientFrame::~CClientFrame()
{
}

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

/////////////////////////////////////////////////////////////////////////////
// CClientFrame message handlers

void CClientFrame::SetImageTransparent(BOOL bTransparent /* = TRUE */)
{
	m_bTransparent = bTransparent;
	Invalidate();		// Invalidate entire window
	OnPaint();			// And force a repaint of the rectangle with the image
}

BOOL CClientFrame::IsImageTransparent()
{
	return m_bTransparent;
}

void CClientFrame::SetImageCentered(BOOL bCentered /* = TRUE */)
{
	m_bCentered = bCentered;
	m_bTiled = FALSE;
	m_bFitToClient = FALSE;		// Always FALSE

	Invalidate();		// Invalidate entire window
	OnPaint();			// And force a repaint of the rectangle with the image
}

BOOL CClientFrame::IsImageCentered()
{
	return m_bCentered;
}

void CClientFrame::SetImageTiled(BOOL bTiled /* = TRUE */)
{
	m_bCentered = FALSE;
	m_bTiled = bTiled;
	m_bFitToClient = FALSE;		// Always FALSE

	Invalidate();		// Invalidate entire window
	OnPaint();			// And force a repaint of the rectangle with the image
}

BOOL CClientFrame::IsImageTiled()
{
	return m_bTiled;
}

void CClientFrame::SetImageFitToClient(BOOL bStretched /* = TRUE */)
{
	m_bCentered = FALSE;
	m_bTiled = FALSE;		// Always FALSE
	m_bFitToClient = bStretched;

	Invalidate();		// Invalidate entire window
	OnPaint();			// And force a repaint of the rectangle with the image
}

BOOL CClientFrame::IsImageFitToClient()
{
	return m_bFitToClient;
}

BOOL CClientFrame::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	return TRUE;
}

WNDPROC* CClientFrame::GetSuperWndProcAddr()
{
	return &pfnSuper;
}

void CClientFrame::OnPaint()
{
	// Do not call CWnd::OnPaint() for painting messages
	InvalidateRect(&m_cHelper.GetOldRect());
	CRect newrect;
	GetClientRect(&newrect);
	//CDC *dc=GetDC();
	//dc->DPtoLP(newrect);
	//ReleaseDC(dc);
	BITMAP bm;
	m_bitmap.GetBitmap(&bm);
	if (m_bCentered) {
		newrect = CRect(newrect.Width()/2-bm.bmWidth/2,
							 newrect.Height()/2-bm.bmHeight/2,
							 newrect.Width()/2-bm.bmWidth/2 + bm.bmWidth,
							 newrect.Height()/2-bm.bmHeight/2+ bm.bmHeight);
	}
	InvalidateRect(&newrect);

	CPaintDC dc(this); // device context for painting
	//dc.SelectClipRgn(NULL);
	m_cHelper.DrawTheBackground(this,&dc,&m_palette,&m_bitmap, m_bCentered, m_bFitToClient, m_bTransparent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -