📄 zgraphddb.cpp
字号:
#include "zGraphDDB.h"
//##ModelId=3FFA652B0068
zGraphDDB::zGraphDDB()
{
m_hBitmap = NULL;
m_hMemDC = NULL;
m_hOldBmp = NULL;
}
//##ModelId=3FFA652B007C
zGraphDDB::~zGraphDDB()
{
ReleaseDDB();
}
//##ModelId=3FFA68A502B7
void zGraphDDB::ReleaseDDB()
{
if ( m_hMemDC )
{
SelectObject(m_hMemDC, m_hOldBmp);
DeleteObject(m_hMemDC);
m_hMemDC = NULL;
}
if ( m_hBitmap )
{
DeleteObject(m_hBitmap);
m_hBitmap = NULL;
}
m_hOldBmp = NULL;
}
//##ModelId=3FFA68BF028C
bool zGraphDDB::Prepare(int &width, int &height)
{
BITMAP bmp;
if ( ! GetObject(m_hBitmap, sizeof(bmp), & bmp) )
return false;
width = bmp.bmWidth;
height = bmp.bmHeight;
if ( m_hMemDC==NULL ) // ensure memdc is created
{
HDC hDC = GetDC(NULL);
m_hMemDC = CreateCompatibleDC(hDC);
ReleaseDC(NULL, hDC);
m_hOldBmp = (HBITMAP) SelectObject(m_hMemDC, m_hBitmap);
}
return true;
}
//##ModelId=3FFA68ED01CA
HBITMAP zGraphDDB::GetBitmap() const
{
return m_hBitmap;
}
//##ModelId=3FFA690B00B5
bool zGraphDDB::CreateDDB(int width, int height, HDC hdc)
{
return 1;
}
//##ModelId=3FFA694B00CB
bool zGraphDDB::Attach(HBITMAP hBmp)
{
if ( hBmp==NULL )
return FALSE;
if ( m_hOldBmp ) // deselected m_hBitmap
{
SelectObject(m_hMemDC, m_hOldBmp);
m_hOldBmp = NULL;
}
if ( m_hBitmap ) // delete current bitmap
DeleteObject(m_hBitmap);
m_hBitmap = hBmp; // replace with new one
if ( m_hMemDC ) // select if has memory DC
{
m_hOldBmp = (HBITMAP) SelectObject(m_hMemDC, m_hBitmap);
return m_hOldBmp != NULL;
}
else
return TRUE;
}
//##ModelId=3FFA696502F9
bool zGraphDDB::LoadBitmap(HINSTANCE hInst, int id)
{
return Attach(::LoadBitmap(hInst,MAKEINTRESOURCE(id)));
}
//##ModelId=3FFA69970391
bool zGraphDDB::Draw(HDC hDC, int x0, int y0, int w, int h, DWORD rop, int opt)
{
int bmpwidth, bmpheight;
if ( ! Prepare(bmpwidth, bmpheight) )
return FALSE;
switch ( opt )
{
case draw_normal:
return BitBlt(hDC, x0, y0, bmpwidth, bmpheight, m_hMemDC, 0, 0, rop);
case draw_center:
return BitBlt(hDC, x0 + (w-bmpwidth)/2, y0 + ( h-bmpheight)/2,
bmpwidth, bmpheight, m_hMemDC, 0, 0, rop);
break;
case draw_tile:
{
for (int j=0; j<h; j+= bmpheight)
for (int i=0; i<w; i+= bmpwidth)
if ( ! BitBlt(hDC, x0+i, y0+j, bmpwidth, bmpheight, m_hMemDC, 0, 0, rop) )
return FALSE;
return TRUE;
}
break;
case draw_stretch:
return StretchBlt(hDC, x0, y0, w, h, m_hMemDC, 0, 0, bmpwidth, bmpheight, rop);
case draw_stretchprop:
{
int ww = w;
int hh = h;
if ( w * bmpheight < h * bmpwidth ) // w/bmWidth is the mimimum scale
hh = bmpheight * w / bmpwidth;
else
ww = bmpwidth * h / bmpheight;
// propertional scaling and centering
return StretchBlt(hDC, x0 + (w-ww)/2, y0 + (h-hh)/2, ww, hh, m_hMemDC, 0, 0, bmpwidth, bmpheight, rop);
}
default:
return FALSE;
}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -