CWindowDC dc(this);
HDC hdc=dc.GetSafeHdc();
using namespace Gdiplus;
Graphics graphics(hdc);
graphics.SetSmoothingMode(SmoothingModeHighQuality);
Pen newPen(Color(0,200,255),5);
graphics.DrawLine(&newPen, 50, N1, x2, y2);
ps:析构函数中什么也没有。
RE:
GetDC/GetSafeHdc需要调用ReleaseDC来释放: ::ReleaseDC(m_hWnd,hdc);
gdi+的资源new要对应delete(gdi的资源createxxx对应DeleteObject)
Pen = new Pen(Color(0,200,255),5);
delete Pen;
Pen = NULL;
-----------------------------------------------
CDC *pDC = GetDlgItem(IDC_WAVEFORM)->GetDC(); HDC hdc = pDC->GetSafeHdc(); if(!ReleaseDC(pDC) )//成功 { printf("1 error code:%d\n",GetLastError()); } if(!DeleteObject(hdc)) { printf("2 error code:%d\n",GetLastError());//失败 返回:6 }
请问在这里 pDC和hdc 都需要释放吗?还是只释放pDC,应该怎么去理解?
RE:
ReleaseDC(pDC)就行了,在Release(pDC)的过程中,会DeleteObject掉和pDC相关联的HDC的。
http://bbs.csdn.net/topics/390921040
http://bbs.csdn.net/topics/340265147
时间: 2024-12-17 09:45:19