티스토리 툴바



이 함수는 일정개수 이상, 일정사이즈 이상의 메모리를 사용할 경우 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);
저작자 표시
Posted by 띠깜

댓글을 달아 주세요

  1. 띠깜 2011/12/07 11:36  댓글주소  수정/삭제  댓글쓰기

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