第一次真正意义上的用VC++实现的一个完整的Win32程序—俄罗斯方块

第一次真正意义上的用VC++实现的一个完整的Win32程序。
//Block.h
//-------------------------------------------------------------------------------------------------
/*
定义每个方块的结构
*/

#if !defined _BLOCK_H_
#define _BLOCK_H_
#define BLOCK_VERSION &H01000000 //主版本号、辅版本、附加版本、附加2
#define BLOCK_SIZE 6 //存储到文件时占用的字节数
#define BLOCK_HEADER_SIZE 8 //存储文件头信息的大小
struct _Block
{//注意:这些字段对于存储文件来说是有先后之分的。
 unsigned int ID:8;
 unsigned int NextID:8;
 int Width:4;
 int Height:4;
 int OffsetY:4;
 int OffsetX:4;
 unsigned int Elements; //方块的各位是否为实体
};

typedef _Block BLOCK;
#endif
//-------------------------------------------------------------------------------------------------
//CustomGDI.h
//-------------------------------------------------------------------------------------------------
#pragma once
#include "windows.h"
//#include "d3d9.h"

#define BORDER_STYLE_NONE 0
#define BORDER_STYLE_FLAT 1
//为简单起见,目前只提供FLAT
//#define BORDER_STYLE_FIXED3D 2
//#define BORDER_STYLE_INNER3D 4
#define BORDER_STYLE_DEFAULT BORDER_STYLE_NONE

#define INNER_STYLE_EMPTY 0
#define INNER_STYLE_SOLID 1
#define INNER_STYLE_DEFAULT INNER_STYLE_EMPTY

#define TRANSPARENT_COLOR RGB(0,0,0)
#define BACKGROUND_DEFAULT_COLOR RGB(0,0,0)

typedef int INNER_STYLE;
typedef int BORDER_STYLE;
typedef DWORD GDI_COLOR;

class CCustomGDI
{
public:
 //CCustomGDI(void);
 CCustomGDI(HWND hWnd);
 ~CCustomGDI(void);
 void TextOut(int x, int y,const char* lpString, int cbString);
 void Drawbox(PRECT prect, BORDER_STYLE bstyle=BORDER_STYLE_DEFAULT, INNER_STYLE istyle=INNER_STYLE_DEFAULT);
 void Drawbox(int x, int y, int height, int width, BORDER_STYLE bstyle=BORDER_STYLE_DEFAULT, INNER_STYLE istyle=INNER_STYLE_DEFAULT);
 void DrawPic(int x, int y, int height, int width, const char* file);
 void DrawPic(PRECT prect, const char* file);
 void Clear(void);
 void Clear(PRECT prect);
 void Clear(GDI_COLOR color);
 void Clear(PRECT prect, GDI_COLOR color);
 void Clear(int x, int y, int height, int width, GDI_COLOR color);
 void SetBkColor(GDI_COLOR color); //设置背景色
 void SetColor(GDI_COLOR color);  //设置前景色
 void Set3DColor(GDI_COLOR ul_color, GDI_COLOR rb_color); //设置绘制3D时左上角与右下角的颜色
 void SetBorderColor(GDI_COLOR color);
 void SetBorderSize(int size);
protected:
 //LPDIRECT3D9 m_pD3D;
 //LPDIRECT3DDEVICE9 m_pd3dDevice;
 //HDC m_hdc;
 HWND m_hwnd;
 //HBRUSH m_hbrBkgnd;
 GDI_COLOR m_background;
 int m_bordersize;
 GDI_COLOR m_bordercolor;
 GDI_COLOR m_color;
};
//-------------------------------------------------------------------------------------------------
//CustomGDI.cpp
//-------------------------------------------------------------------------------------------------
#include "./customgdi.h"
//
//CCustomGDI::CCustomGDI(void)
//{
//}
//
CCustomGDI::CCustomGDI(HWND hWnd)
{
 //初始化图形设备
 m_hwnd=hWnd;
 //m_hdc=GetDC(hWnd);

 m_background=BACKGROUND_DEFAULT_COLOR;
 m_bordersize=1;
 m_bordercolor=RGB(0x80,0x80,0x80); //gray
 m_color=RGB(0xFF,0xFF,0xFF); //white
}

CCustomGDI::~CCustomGDI(void)
{
 //ReleaseDC(m_hwnd, m_hdc);
}

void CCustomGDI::TextOut(int x, int y,const char* lpString, int cbString)
{
 HDC hdc=GetDC(m_hwnd);
 ::TextOut(hdc,x,y,lpString,cbString);
 ReleaseDC(m_hwnd,hdc);
}

void CCustomGDI::Drawbox(PRECT prect, BORDER_STYLE bstyle, INNER_STYLE istyle)
{
 HBRUSH hbr;
 HDC hdc;

 hdc=GetDC(m_hwnd);

 RECT rect;
 rect.top=prect->top;
 rect.bottom=prect->bottom;
 rect.left=prect->left;
 rect.right=prect->right;

 if(bstyle==BORDER_STYLE_FLAT)
 {
  //如果为BORDER_STYLE_FLAT
  hbr=CreateSolidBrush(m_bordercolor);
  
  FrameRect(hdc, &rect, hbr); //这里不知道如何画线,呵呵。

  DeleteObject(hbr);

  rect.left+=m_bordersize;
  rect.right-=m_bordersize;
  rect.top+=m_bordersize;
  rect.bottom-=m_bordersize;

 }

 if(istyle==INNER_STYLE_SOLID) {
  hbr=CreateSolidBrush(m_color);
  FillRect(hdc, &rect, hbr);
  DeleteObject(hbr);
 }

 ReleaseDC(m_hwnd,hdc);
}

void CCustomGDI::Drawbox(int x, int y, int height, int width, BORDER_STYLE bstyle, INNER_STYLE istyle)
{
 RECT rect;
 rect.top=y;
 rect.left=x;
 rect.bottom=y+height-1;
 rect.right=x+width-1;
 Drawbox(&rect,bstyle,istyle);
}

void CCustomGDI::DrawPic(int x, int y, int height, int width, const char* file)
{
}

void CCustomGDI::DrawPic(PRECT prect, const char* file)
{
}

void CCustomGDI::Clear(void)
{
 //清除屏幕
 RECT rect;
 GetClientRect(m_hwnd,&rect);
 Clear(&rect, m_background);
}

void CCustomGDI::Clear(PRECT prect)
{
 Clear(prect, m_background);
}

void CCustomGDI::Clear(GDI_COLOR color)
{
 RECT rect;
 GetClientRect(m_hwnd,&rect);
 Clear(&rect, color);
}

void CCustomGDI::Clear(PRECT prect, GDI_COLOR color)
{
 HDC hdc;
 hdc=GetDC(m_hwnd);

 HBRUSH hbr=CreateSolidBrush(color);
 FillRect(hdc, prect, hbr);
 DeleteObject(hbr);

 ReleaseDC(m_hwnd,hdc);
}

void CCustomGDI::Clear(int x, int y, int height, int width, GDI_COLOR color)
{
 RECT rect;
 rect.left=x;
 rect.top=y;
 rect.right=x+height-1;
 rect.bottom=y+width-1;
 Clear(&rect,color);
}

void CCustomGDI::SetBkColor(GDI_COLOR color)
{
 m_background=color;
}

void CCustomGDI::SetColor(GDI_COLOR color)
{
 m_color=color;
}

void CCustomGDI::Set3DColor(GDI_COLOR ul_color, GDI_COLOR rb_color)
{
}

void CCustomGDI::SetBorderSize(int size)
{
}

void CCustomGDI::SetBorderColor(GDI_COLOR color)
{
}
//--------------------------------------------------------------------------------------------------
//Els.h
//-------------------------------------------------------------------------------------------------
#include <windows.h>
//#include <d3d9.h>
#include <stdio.h>
#include <direct.h>
#include <time.h>
#include "Block.h"
#include "CustomGDI.h"

#define PLAYAREA_HEIGHT 24
#define PLAYAREA_WIDTH 12
#define PLAYAREA_EMPTY_COLOR R

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值