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

📄 gdi.c

📁 可能有用,是关于c++的是因为要下个软件所以随便传了一个,抱歉了.刚学c++还不会弄什么,以后一定一定传好的东西.
💻 C
字号:
#include "gdi.h"
#include <windows.h>
#include <malloc.h>
#include <string.h>

struct gdi_object {
	HWND wnd;
	HDC dc;
	BITMAPINFO bi;
	RGBQUAD pal[2];
};

static void gdi_flip(pixel *ptr,int pitch,void *object,int x,int y)
{
	struct gdi_object *obj=(struct gdi_object *)object;
	SetDIBitsToDevice(obj->dc,
		x,y,CANVAS_BLOCK_WIDTH,CANVAS_BLOCK_HEIGHT,
		x,0,
		0,CANVAS_BLOCK_HEIGHT,
		ptr-x,&(obj->bi),DIB_RGB_COLORS
	);
}

void gdi_create(struct gdi *g,void *wnd,int w,int h)
{
	struct gdi_object *obj;
	BITMAPINFOHEADER *bh;
	g->pitch=(w*sizeof(pixel)+3)&(~3);
	g->flip=gdi_flip;
	g->buffer=(pixel*)malloc(h*g->pitch);
	g->object=obj=(struct gdi_object *)malloc(sizeof(struct gdi_object));
	g->width=w;
	g->height=h;
	obj->wnd=(HWND)wnd;
	obj->dc=GetDC(obj->wnd);
	bh=&(obj->bi.bmiHeader);
	memset(bh,0,sizeof(*bh));
	bh->biSize=sizeof(*bh);
	bh->biWidth=g->pitch/sizeof(pixel);
	bh->biHeight=-CANVAS_BLOCK_HEIGHT;
	bh->biPlanes=1;
	bh->biBitCount=sizeof(pixel)*8;
	bh->biCompression=BI_BITFIELDS;
	*(int*)(obj->bi.bmiColors+0)=0xf800;
	*(int*)(obj->bi.bmiColors+1)=0x7e0;
	*(int*)(obj->bi.bmiColors+2)=0x1f;
}

void gdi_release(struct gdi *g)
{
	struct gdi_object *obj=(struct gdi_object *)g->object;
	ReleaseDC(obj->wnd,obj->dc);
	free(g->buffer);
	free(g->object);	
}

⌨️ 快捷键说明

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