GDI资源泄漏问题……些谢谢~~~~~~~~~~~~~~~~~~~~ [所有相关帖子]
//现在来说基本上是:创建内存DC。
创建字体,
选择字体创建位图
选择位图然后是删除
可是为什么还会有运行一会儿就出现了参数无效87。
??? HFONT font;
HFONT hOldFont; HDC memdc = ::CreateCompatibleDC(NULL);
int nFontSize= pFont->xFont->GetCxFont();
nFontSize *= 1.45; //字体比例放大倍数……
LOGFONT logFont;
logFont.lfHeight = nFontSize;
logFont.lfWidth = 0;
logFont.lfWeight = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = 500;
logFont.lfItalic = FALSE;
logFont.lfUnderline = FALSE;
logFont.lfStrikeOut = FALSE;
logFont.lfCharSet = GB2312_CHARSET;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfQuality = 0; logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; strcpy(logFont.lfFaceName,"宋体"); font = ::CreateFontIndirect(&logFont); // define the out text size.
SIZE outSize;
outSize.cx = lpRect->right - lpRect->left;
outSize.cy = lpRect->bottom - lpRect->top;
outSize.cx &= 0xFFFC;
// 输入到 dc 上的矩形范围
RECT rect;
rect.left = 0;
rect.top = 0;
rect.bottom = outSize.cy;
rect.right = outSize.cx;
// define the bitmap.
HBITMAP hBitmap;
HBITMAP hOldBitmap; // create the memory dc . used to save the bitmap.
hOldFont = (HFONT)::SelectObject( memdc, font );
::SetTextColor( memdc, fntColor );
// create the DIB section needs.
BITMAPINFO bmi;
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = outSize.cx;
bmi.bmiHeader.biHeight = -outSize.cy;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = m_pGraphDevice->GetPixelWidth();
bmi.bmiHeader.biCompression = BI_RGB;
// create the DIB section so control the bits myself.
hBitmap = ::CreateDIBSection( memdc, &bmi, DIB_RGB_COLORS,
(void* *) &bits, NULL, 0 ); if(bits == NULL)
{
int err = GetLastError();
CString str;
str.Format("%d",err);
AfxMessageBox(str);
return FALSE;
}
// set font / bit / color
// define the dc RECT, not lpRect of the parameter. hOldBitmap = (HBITMAP)::SelectObject( memdc, hBitmap );
::SelectObject(memdc,hOldBitmap);
if(!::DeleteObject(hBitmap))
{
AfxMessageBox("delete hBitmap false ");
} ::SelectObject(memdc,hOldFont);
if(!::DeleteObject(font))
{
AfxMessageBox("delete hFont false");
}
if(0==::DeleteDC(memdc))//::ReleaseDC(hWnd,memdc))
{
AfxMessageBox("memdc false");
}
//现在来说基本上是:创建内存DC。
创建字体,
选择字体创建位图
选择位图然后是删除
可是为什么还会有运行一会儿就出现了参数无效87。
??? HFONT font;
HFONT hOldFont; HDC memdc = ::CreateCompatibleDC(NULL);
int nFontSize= pFont->xFont->GetCxFont();
nFontSize *= 1.45; //字体比例放大倍数……
LOGFONT logFont;
logFont.lfHeight = nFontSize;
logFont.lfWidth = 0;
logFont.lfWeight = 0;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = 500;
logFont.lfItalic = FALSE;
logFont.lfUnderline = FALSE;
logFont.lfStrikeOut = FALSE;
logFont.lfCharSet = GB2312_CHARSET;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfQuality = 0; logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; strcpy(logFont.lfFaceName,"宋体"); font = ::CreateFontIndirect(&logFont); // define the out text size.
SIZE outSize;
outSize.cx = lpRect->right - lpRect->left;
outSize.cy = lpRect->bottom - lpRect->top;
outSize.cx &= 0xFFFC;
// 输入到 dc 上的矩形范围
RECT rect;
rect.left = 0;
rect.top = 0;
rect.bottom = outSize.cy;
rect.right = outSize.cx;
// define the bitmap.
HBITMAP hBitmap;
HBITMAP hOldBitmap; // create the memory dc . used to save the bitmap.
hOldFont = (HFONT)::SelectObject( memdc, font );
::SetTextColor( memdc, fntColor );
// create the DIB section needs.
BITMAPINFO bmi;
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = outSize.cx;
bmi.bmiHeader.biHeight = -outSize.cy;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = m_pGraphDevice->GetPixelWidth();
bmi.bmiHeader.biCompression = BI_RGB;
// create the DIB section so control the bits myself.
hBitmap = ::CreateDIBSection( memdc, &bmi, DIB_RGB_COLORS,
(void* *) &bits, NULL, 0 ); if(bits == NULL)
{
int err = GetLastError();
CString str;
str.Format("%d",err);
AfxMessageBox(str);
return FALSE;
}
// set font / bit / color
// define the dc RECT, not lpRect of the parameter. hOldBitmap = (HBITMAP)::SelectObject( memdc, hBitmap );
::SelectObject(memdc,hOldBitmap);
if(!::DeleteObject(hBitmap))
{
AfxMessageBox("delete hBitmap false ");
} ::SelectObject(memdc,hOldFont);
if(!::DeleteObject(font))
{
AfxMessageBox("delete hFont false");
}
if(0==::DeleteDC(memdc))//::ReleaseDC(hWnd,memdc))
{
AfxMessageBox("memdc false");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货