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

📄 hdc.c

📁 lgui_0.3.0.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
CreatePen(	int iPenStyle, 	int iWidth, 	COLORREF crColor){	PEN* pPen;	pPen=(PEN*)malloc(sizeof(PEN));	if(!pPen)		return NULL;	pPen->iGdiType	=GDI_PEN;	if(iPenStyle==0)		pPen->iPenStyle=PS_SOLID;	else				pPen->iPenStyle	=iPenStyle;	pPen->iPenWidth	=iWidth;	pPen->crPenColor=crColor;	return (HPEN)pPen;}HBRUSH GUIAPI CreateSolidBrush(	COLORREF crColor){	BRUSH* pBrush;	pBrush=(BRUSH*)malloc(sizeof(BRUSH));	if(!pBrush)		return NULL;	pBrush->iGdiType	=GDI_BRUSH;	pBrush->iBrushStyle	=BS_SOLID;	pBrush->crBrushColor=crColor;	return (HBRUSH)pBrush;}HBRUSH GUIAPI CreateHatchBrush(	int iStyle, 	COLORREF crColor){	BRUSH* pBrush;	pBrush=(BRUSH*)malloc(sizeof(BRUSH));	if(!pBrush)		return NULL;	pBrush->iGdiType	=GDI_BRUSH;	pBrush->iBrushStyle	=BS_HATCHED;	pBrush->iHatchStyle	=iStyle;	pBrush->crBrushColor=crColor;		return (HBRUSH)pBrush;}HBRUSH GUIAPI CreateAgainstBrush(){	BRUSH* pBrush;	pBrush=(BRUSH*)malloc(sizeof(BRUSH));	if(!pBrush)		return NULL;	pBrush->iGdiType	=GDI_BRUSH;	pBrush->iBrushStyle	=BS_AGAINST;		return (HBRUSH)pBrush;}BOOL IsNullBrush(HDC hDC){	BRUSH* pBrush;	pBrush = (BRUSH*)(hDC->hBrush);	if(pBrush->iBrushStyle == BS_NULL)		return true;	else		return false;}BOOL  IsSolidBrush(HDC hDC){	BRUSH* pBrush;	pBrush = (BRUSH*)(hDC->hBrush);	if(pBrush->iBrushStyle == BS_SOLID)		return true;	else		return false;}COLORREF GetSolidBrushColor(	HDC hDC){	BRUSH* pBrush;	pBrush = (BRUSH*)(hDC->hBrush);	return pBrush->crBrushColor;}int GUIAPI ReleaseDC(	HWND hWnd, 	HDC hDC){	if(!hDC)		return -1;	if(hDC->hPen)		free(hDC->hPen);	if(hDC->hBrush)		free(hDC->hBrush);	if(hDC->hFont)		free(hDC->hFont);	if(((BITMAP*)(hDC->hBitmap))->bmBits)		free(((BITMAP*)(hDC->hBitmap))->bmBits);	if(hDC->hBitmap)		free(hDC->hBitmap);	if(hDC->pData)		free(hDC->pData);		free(hDC);	return 0;}BOOL GUIAPI SelectObject(	HDC hDC,	HGDIOBJ hGdiObj){	int iType;	iType= *((int*)hGdiObj);	switch (iType){	case GDI_PEN:		memcpy((void*)(hDC->hPen),(void*)hGdiObj,sizeof(PEN));		return true;	case GDI_BRUSH:		memcpy((void*)(hDC->hBrush),(void*)hGdiObj,sizeof(BRUSH));		return true;	case GDI_FONT:		memcpy((void*)(hDC->hFont),(void*)hGdiObj,sizeof(FONT));		return true;	case GDI_BITMAP:		if(hDC->iType!=DC_TYPE_MEM)			return false;		if(hDC->pData){			if(				((BITMAP*)hGdiObj)->bmHeight * ((BITMAP*)hGdiObj)->bmWidth !=				((BITMAP*)(hDC->hBitmap))->bmHeight *((BITMAP*)(hDC->hBitmap))->bmWidth				){				free(hDC->pData);				hDC->pData=malloc(((BITMAP*)(hGdiObj))->bmWidth *					              ((BITMAP*)(hGdiObj))->bmHeight *								  _lGUI_iBytesDataType);				if(!(hDC->pData)){					return false;				}			}		}		else{			hDC->pData=malloc(((BITMAP*)(hGdiObj))->bmWidth *				              ((BITMAP*)(hGdiObj))->bmHeight *							  _lGUI_iBytesDataType);			if(!(hDC->pData))				return false;		}		memcpy(hDC->hBitmap,			   hGdiObj,sizeof(BITMAP));		memcpy(hDC->pData,			(void*)(((BITMAP*)hGdiObj)->bmBits),			((BITMAP*)hGdiObj)->bmWidth * ((BITMAP*)hGdiObj)->bmHeight * _lGUI_iBytesDataType);		return true;	case GDI_RES:		break;	}	return false;}void GUIAPI DeleteObject(	HGDIOBJ hGdiObj){	BITMAP* pBitmap;	if(*((int*)hGdiObj)==GDI_BITMAP){		pBitmap=(BITMAP*)hGdiObj;		if(pBitmap->bmBits)			free(pBitmap->bmBits);	}	free(hGdiObj);}HDC GUIAPI CreateCompatibleDC(	HDC hDCRefer){	HDC hDC;	PWindowsTree pWin;	BITMAP *pBitmap;	hDC=(HDC)malloc(sizeof(DC));	if(!hDC)		return NULL;	memset(hDC,0,sizeof(DC));	pBitmap=malloc(sizeof(BITMAP));	if(!pBitmap)		return NULL;	memset(pBitmap,0,sizeof(BITMAP));	////////////////////////////////////////////////	hDC->iType=DC_TYPE_MEM;		////////////////////////////////////////////////	if(hDCRefer){		hDC->iCoordType = hDCRefer->iCoordType;			hDC->isTextBkTrans	=hDCRefer->isTextBkTrans;		hDC->crTextBkColor	=hDCRefer->crTextBkColor;		hDC->crTextColor	=hDCRefer->crTextColor;		pWin=(PWindowsTree)(hDCRefer->hWnd);		pBitmap->bmWidth=pWin->rect.right-pWin->rect.left + 1;		pBitmap->bmHeight=pWin->rect.bottom-pWin->rect.top + 1;		hDC->pData=malloc(pBitmap->bmWidth * pBitmap->bmHeight * _lGUI_iBytesDataType);		if(!(hDC->pData)){			free(pBitmap);			return NULL;		}		hDC->hPen=(HPEN)malloc(sizeof(PEN));		if(!(hDC->hPen)){			free(pBitmap);			free(hDC->pData);			return NULL;		}		hDC->hBrush=(HBRUSH)malloc(sizeof(BRUSH));		if(!(hDC->hBrush)){			free(pBitmap);			free(hDC->hPen);			free(hDC->pData);			return NULL;		}		hDC->hFont=(HFONT)malloc(sizeof(FONT));		if(!(hDC->hFont)){			free(pBitmap);			free(hDC->hPen);			free(hDC->hBrush);			free(hDC->pData);			return NULL;		}		memcpy((void*)(hDC->hPen),(void*)(hDCRefer->hPen),sizeof(PEN));		memcpy((void*)(hDC->hBrush),(void*)(hDCRefer->hBrush),sizeof(BRUSH));		memcpy((void*)(hDC->hFont),(void*)(hDCRefer->hFont),sizeof(FONT));		hDC->hBitmap=(HBITMAP)pBitmap;		hDC->hWnd = hDCRefer->hWnd;	}	else{		hDC->isTextBkTrans	=true;		hDC->crTextBkColor	=RGB(0xff, 0xff, 0xff);		hDC->crTextColor	=RGB(0x00, 0x00, 0x00);		pBitmap->bmWidth=SCREEN_WIDTH;		pBitmap->bmHeight=SCREEN_HEIGHT;		hDC->pData=malloc(pBitmap->bmWidth * pBitmap->bmHeight * _lGUI_iBytesDataType);		if(!(hDC->pData)){			free(pBitmap);			return NULL;		}		hDC->hPen	=(HPEN)(GetStockObject(BLACK_PEN));		hDC->hBrush	=(HBRUSH)(GetStockObject(NULL_BRUSH));		hDC->hFont	=(HFONT)(GetStockObject(SYS_DEFAULT_FONT));		hDC->hBitmap=(HBITMAP)pBitmap;		hDC->hWnd	= _lGUI_pWindowsTree;	}	return hDC;}HBITMAP GUIAPI CreateBitmap(	char* pFile){	FILE* fp;	BITMAP* pBitmap;	BMPFILEHEADER fileHeader;	BMPINFOHEADER infoHeader;	fp=fopen(pFile,"rb");	if(!fp)		return NULL;	pBitmap=(BITMAP*)malloc(sizeof(BITMAP));	if(!pBitmap)		return NULL;	memset(pBitmap,0,sizeof(BITMAP));	pBitmap->iGdiType=GDI_BITMAP;	pBitmap->bmType=0;	fseek(fp,0x12,0);	fread(&(infoHeader.biWidth),sizeof(infoHeader.biWidth),1,fp);	fread(&(infoHeader.biHeight),sizeof(infoHeader.biHeight),1,fp);		//fread(&fileHeader,sizeof(BMPFILEHEADER),1,fp);	//fread(&infoHeader,sizeof(BMPINFOHEADER),1,fp);	pBitmap->bmWidth=infoHeader.biWidth;	pBitmap->bmHeight=infoHeader.biHeight;	//pBitmap->bmPlanes=infoHeader.biPlanes;	//pBitmap->bmBitsPixel=infoHeader.biBitCount;	pBitmap->bmBits=(unsigned char*)malloc(pBitmap->bmWidth*pBitmap->bmHeight*_lGUI_iBytesDataType);	if(!(pBitmap->bmBits)){		free(pBitmap);		fclose(fp);		return NULL;	}	if(!ReadBmpToBuf(fp,pBitmap->bmWidth,pBitmap->bmHeight,pBitmap->bmBits)){		free(pBitmap->bmBits);		free(pBitmap);		fclose(fp);		return NULL;	}	fclose(fp);	return (HBITMAP)pBitmap;}void PutSavedBoxOnDC(	HDC hDC,	int x, 	int y, 	int nWidth, 	int nHeight, 	PCOLORREF pSavedBox){	int i,j;	COLORREF crColor;	for(i=0; i<nWidth; i++){		for(j=0; j<nHeight; j++){			crColor = *(pSavedBox + i*nWidth + j);			SetPixel(hDC,x+i,y+j,crColor);		}	}}

⌨️ 快捷键说明

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