이 함수는 일정개수 이상, 일정사이즈 이상의 메모리를 사용할 경우 FALSE를 리턴하는 경우가 있습니다.
이에 대한 다른방법입니다.
MFC 버전
HBITMAP MakeDIBSection(CDC& dc, int width, int height)
{
BITMAPINFO bmi;
LPVOID pBits;
HBITMAP hBitmap;
memset(&bmi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = height;
bmi.bmiHeader.biPlanes = 1;
hBitmap = ::CreateDIBSection(dc.GetSafeHdc(), &bmi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
return hBitmap;
}
Win32 Api 버전
HBITMAP MakeDIBSection(HDC dc, int width, int height)
{
BITMAPINFO bmi;
LPVOID pBits;
HBITMAP hBitmap;
memset(&bmi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = height;
bmi.bmiHeader.biPlanes = 1;
hBitmap = ::CreateDIBSection(dc, &bmi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
return hBitmap;
}
예제)
CBitmap tmpBmp;
CDC *pDC = GetDC();
CDC srcDC;
srcDC.CreateCompatibleDC(pDC);
tmpBmp.m_hObject = MakeDIBSection(srcDC, cx, cy);//or
ReleaseDC(pDC);
'프로그래밍 팁 > etc' 카테고리의 다른 글
| CreateCompatibleBitmap 주의사항 (1) | 2011/12/03 |
|---|---|
| 다이얼로그 구멍내기 (0) | 2011/11/25 |
| 비스타에서 권한무시 메세지 전송방법 (0) | 2011/10/12 |
| [드래그 & 드롭]어플 -> 바탕화면 (0) | 2011/10/11 |
| CreateEvent를 활용한 WaitForSingleObject (0) | 2011/10/05 |
| 바로가기 복사하기 (0) | 2011/07/26 |



댓글을 달아 주세요
파일 패스에 주로 사용하나 일반 문자열에도 적용될 것 같네요.
HDC hDC;
hDC = ::GetDC(hOutputCaption);
PathCompactPath(hDC,(LPSTR)(LPCTSTR)path,300);
::ReleaseDC(hOutputCaption,hDC);
SSetWindowText(hOutputCaption,path);