📄 directface.cpp
字号:
// DirectFace.cpp: implementation of the CDirectFace class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "LastProject.h"
#include "DirectFace.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDirectFace::CDirectFace()
{
m_lpDDraw7 = NULL;
m_lpPSur = NULL;
for(int i=0;i<4;i++) m_lpLayer[i] = NULL;
m_FramePen.CreatePen(PS_SOLID,3,RGB(0,170,0));
m_flash.LoadBitmap(IDB_FLASH);
m_RedPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
m_GreenPen.CreatePen(PS_SOLID,1,RGB(0,255,0));
m_YellowPen.CreatePen(PS_SOLID,1,RGB(255,255,0));
m_RedBarPen.CreatePen(PS_SOLID,1,RGB(170,0,0));
m_GreenBarPen.CreatePen(PS_SOLID,1,RGB(0,170,0));
m_YellowBarPen.CreatePen(PS_SOLID,1,RGB(150,170,0));
m_RedBarBrush.CreateSolidBrush(RGB(170,0,0));
m_GreenBarBrush.CreateSolidBrush(RGB(0,170,0));
m_YellowBarBrush.CreateSolidBrush(RGB(170,170,0));
m_GrayPen.CreatePen(PS_SOLID,1,RGB(170,170,170));
m_WhitePen.CreatePen(PS_SOLID,1,RGB(255,255,255));
m_XFont.CreateFont(
12, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"宋体");
m_YFont.CreateFont(
12, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"宋体");
m_TitleFont.CreateFont(
12, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"宋体");
}
CDirectFace::~CDirectFace()
{
for(int i=0;i<4;i++)
{
if(m_lpLayer[i]!=NULL) m_lpLayer[i]->Release();
}
if(m_lpPSur!=NULL) m_lpPSur->Release();
if(m_lpDDraw7!=NULL) m_lpDDraw7->Release();
}
BOOL CDirectFace::Create(HWND hWnd,CRect rect)
{
m_rect = rect;
//创建DirectDraw对象
if (FAILED(DirectDrawCreateEx(NULL,(VOID**)&m_lpDDraw7,IID_IDirectDraw7,NULL)))
{
::MessageBox(hWnd,"Fail To Create DirectDraw Object","Error",MB_ICONERROR);
return FALSE;
}
if (FAILED(m_lpDDraw7->SetCooperativeLevel(hWnd,DDSCL_NORMAL|DDSCL_NOWINDOWCHANGES)))
{
::MessageBox(hWnd,"Fail To Set CooperativeLevel","Error",MB_ICONERROR);
return FALSE;
}
ZeroMemory(&m_desc,sizeof(m_desc));
m_desc.dwSize = sizeof(m_desc);
m_desc.dwFlags = DDSD_CAPS;
m_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
if (FAILED(m_lpDDraw7->CreateSurface(&m_desc,&m_lpPSur,NULL)))
{
::MessageBox(hWnd,"Fail To Create Primary Surface","Error",MB_ICONERROR);
return -1;
}
ZeroMemory(&m_desc,sizeof(m_desc));
m_desc.dwSize = sizeof(m_desc);
m_desc.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
m_desc.dwHeight = rect.Height();
m_desc.dwWidth = rect.Width();
m_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_SYSTEMMEMORY;
//设置颜色键
m_key.dwColorSpaceHighValue = 0;
m_key.dwColorSpaceLowValue = 0;
for(int nLayerindex=0;nLayerindex<4;nLayerindex++)
{
if(FAILED(m_lpDDraw7->CreateSurface(&m_desc,&m_lpLayer[nLayerindex],NULL)))
{
::MessageBox(hWnd,"Fail To Create Off Screen Surface","Error",MB_ICONERROR);
return FALSE;
}
m_lpLayer[nLayerindex]->SetColorKey(DDCKEY_SRCBLT,&m_key);
}
return TRUE;
}
void CDirectFace::DrawFrame()
{
//画边框
HDC layer = NULL;
m_lpLayer[1]->GetDC(&layer);
CDC *pDC = CDC::FromHandle(layer);
pDC->SelectObject(::GetStockObject(BLACK_BRUSH));
pDC->SelectObject(&m_FramePen);
pDC->Rectangle(0,0,m_rect.Width(),m_rect.Height());
m_lpLayer[1]->ReleaseDC(layer);
m_lpLayer[2]->GetDC(&layer);
pDC = CDC::FromHandle(layer);
CDC MemDC;
BITMAP bm;
MemDC.CreateCompatibleDC(NULL);
pDC->FillSolidRect(0,0,m_rect.Width(),m_rect.Height(),RGB(0,0,0));
MemDC.SelectObject(m_flash);
m_flash.GetObject(sizeof(BITMAP),&bm);
pDC->BitBlt((m_rect.Width()-bm.bmWidth)/2,(m_rect.Height()-bm.bmHeight)/2,bm.bmWidth,bm.bmHeight,
&MemDC,0,0,SRCCOPY);
m_lpLayer[2]->ReleaseDC(layer);
m_lpLayer[0]->BltFast(0,0,m_lpLayer[1],CRect(0,0,m_rect.Width(),m_rect.Height()),DDBLTFAST_WAIT);
m_lpLayer[0]->BltFast(0,0,m_lpLayer[2],CRect(0,0,m_rect.Width(),m_rect.Height()),DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
m_lpPSur->BltFast(m_rect.left,m_rect.top,m_lpLayer[0],CRect(0,0,m_rect.Width(),m_rect.Height()),DDBLTFAST_WAIT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -