BOOL ShowFonts(int iWidth,int iHeight,HDC hdc,BYTE* pByte,POINT pt,int iMulty)
{
HBITMAP hBitmap;
BOOL BitBltSuccess;
HDC hdcMem;
DWORD dwError;
HDC hDC=NULL;
int iD;
//根据pByte 创建ddb
hBitmap=CreateBitmap(iWidth,iHeight,1,1,pByte);
dwError=GetLastError();
{
一、 int crColor =SetPixel(hdc,1,1,RGB(255,0,0));
int dwError=GetLastError();
dwError=dwError;
}
//创建位图兼容设备句柄,并把位图选入
iD=SaveDC(hDC);
hdcMem=CreateCompatibleDC(hdc);
{
二、 int crColor =SetPixel(hdc,1,1,RGB(255,0,0));
int dwError=GetLastError();
dwError=dwError;
}
SelectObject(hdcMem,hBitmap); //显示字体位图
BitBltSuccess=StretchBlt(hdc,pt.x,pt.y,iMulty*iWidth,iMulty*iHeight,hdcMem,0,0,iWidth,iHeight,NOTSRCCOPY);
DeleteDC(hdcMem);
RestoreDC(hDC,iD);
{
int crColor =SetPixel(hdc,1,1,RGB(255,0,0));
int dwError=GetLastError();
dwError=dwError;
}
//
return BitBltSuccess;
}
{
HBITMAP hBitmap;
BOOL BitBltSuccess;
HDC hdcMem;
DWORD dwError;
HDC hDC=NULL;
int iD;
//根据pByte 创建ddb
hBitmap=CreateBitmap(iWidth,iHeight,1,1,pByte);
dwError=GetLastError();
{
一、 int crColor =SetPixel(hdc,1,1,RGB(255,0,0));
int dwError=GetLastError();
dwError=dwError;
}
//创建位图兼容设备句柄,并把位图选入
iD=SaveDC(hDC);
hdcMem=CreateCompatibleDC(hdc);
{
二、 int crColor =SetPixel(hdc,1,1,RGB(255,0,0));
int dwError=GetLastError();
dwError=dwError;
}
SelectObject(hdcMem,hBitmap); //显示字体位图
BitBltSuccess=StretchBlt(hdc,pt.x,pt.y,iMulty*iWidth,iMulty*iHeight,hdcMem,0,0,iWidth,iHeight,NOTSRCCOPY);
DeleteDC(hdcMem);
RestoreDC(hDC,iD);
{
int crColor =SetPixel(hdc,1,1,RGB(255,0,0));
int dwError=GetLastError();
dwError=dwError;
}
//
return BitBltSuccess;
}
将:
iD=SaveDC(hDC);
hdcMem=CreateCompatibleDC(hdc);
放在后面还有问题吗?
二处的代码在创建了内存兼容DC之后调用,此时内存兼容DC中默认的位图是1x1的单色位图,可能这是造成错误的原因。要判断CreateCompatibleDC()是否成功,直接判断返回的hdcMem是否为NULL就可以了。
BOOL ShowFonts(int iWidth,int iHeight,HDC hdc,BYTE* pByte,POINT pt,int iMulty)
{
HBITMAP hBitmap;
BOOL BitBltSuccess;
HDC hdcMem;
DWORD dwError;
HDC hDC=NULL;
int iD;
//根据pByte 创建ddb
hBitmap=CreateBitmap(iWidth,iHeight,1,1,pByte);
if (!hBitmap)
{
dwError=GetLastError();
return FALSE;
}
//创建位图兼容设备句柄,并把位图选入
//iD=SaveDC(hDC);//这个函数调用是干什么的知道吗?放在这里毫无用处。
hdcMem=CreateCompatibleDC(hdc);
if (!hdcMem)
{
DeleteObject(hBitmap);
dwError = GetLastError();
return FALSE;
}
HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcMem,hBitmap); //要保存原来的位图。 //显示字体位图
BitBltSuccess=StretchBlt(hdc,pt.x,pt.y,iMulty*iWidth,iMulty*iHeight,hdcMem,0,0,iWidth,iHeight,NOTSRCCOPY);
SelectObject(hdcMem, hOldBmp); //要恢复原来的位图
DeleteDC(hdcMem);
DeleteObject(hBitmap); //位图资源也要释放。
//RestoreDC(hDC,iD);
// {
// int crColor =SetPixel(hdc,1,1,RGB(255,0,0));
// int dwError=GetLastError();
// dwError=dwError;
// }
//
return BitBltSuccess;
}
-->
return TRUE;