bdialog.cpp
来自「一个长度信息管理系统。主要包含了界面编程和对文件操作。」· C++ 代码 · 共 129 行
CPP
129 行
//***********************************************************************************
// Class = CBDialog
// File = BDialog.cpp
// Date = 2003.02.24
// Ver = 03-02-24
// Author = Loomman
// E-mail = loomman@hotmail.com
// Comment = This class is used to make a bmp file as the background of a dialog:)
//
// Based on the Visual C++ dlg bmp background component.Have fun programming:)
// 1998-2003 Loomman Software, All Rights Reserved.
//**********************************************************************************
// BDialog.cpp : implementation file
//
#include "stdafx.h"
#include "BDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBDialog dialog
CBDialog::CBDialog(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
: CDialog(nIDTemplate, pParent)
{
//{{AFX_DATA_INIT(CBDialog)
// NOTE: the ClassWizard will add member initialization here
m_style=StyleTile;
//}}AFX_DATA_INIT
}
BEGIN_MESSAGE_MAP(CBDialog, CDialog)
//{{AFX_MSG_MAP(CBDialog)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBDialog message handlers
BOOL CBDialog::OnEraseBkgnd(CDC* pDC)
{
CDialog::OnEraseBkgnd(pDC);
if(!m_bitmap.m_hObject)
return true;
CRect rect;
GetClientRect(&rect);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dc.SelectObject(&m_bitmap);
int bmw, bmh ;
BITMAP bmap;
m_bitmap.GetBitmap(&bmap);
bmw = bmap.bmWidth;
bmh = bmap.bmHeight;
int xo=0, yo=0;
if(m_style == StyleTile)
{
for (yo = 0; yo < rect.Height(); yo += bmh)
{
for (xo = 0; xo < rect.Width(); xo += bmw)
{
pDC->BitBlt (xo, yo, rect.Width(),
rect.Height(), &dc,
0, 0, SRCCOPY);
}
}
}
if(m_style == StyleCenter)
{
if(bmw < rect.Width())
xo = (rect.Width() - bmw)/2;
else
xo=0;
if(bmh < rect.Height())
yo = (rect.Height()-bmh)/2;
else
yo=0;
pDC->BitBlt (xo, yo, rect.Width(),
rect.Height(), &dc,
0, 0, SRCCOPY);
}
if(m_style == StyleStretch)
{
pDC->StretchBlt(xo, yo, rect.Width(),
rect.Height(), &dc,
0, 0,bmw,bmh, SRCCOPY);
}
dc.SelectObject(pOldBitmap);
return true;
}
void CBDialog::SetBitmapStyle(int style)
{
if((style==StyleTile)||
(style==StyleCenter)||
(style==StyleStretch))
{
m_style = style;
}
}
int CBDialog::SetBitmap(UINT nIDResource)
{
if(m_bitmap.LoadBitmap(nIDResource))
return 0;
else
return 1;//error
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?