|
-
June 23rd, 1999, 02:55 PM
#1
c++
Im just wondering if anyone can tell me what API or function I would use to load a bitmap into a DC using Borland C++ 4.52, I don't own visual c++ but I figured someone would know.. thanks.
-Dave
-
June 23rd, 1999, 03:38 PM
#2
Re: c++
This is all Win32 API This code loads a bitmap from a file into a HBITMAP then into a DC and then Stretches it to fit the window of a control in your dialog that you are displaying it to.
Hope it helps.
HDC hPhotoWndDC;
HDC hCompatDC;
HWND hPhotoWnd;
m_hCurrentBmp = (HBITMAP)::LoadImageW(NULL, bstrFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (m_hCurrentBmp != NULL)
{
hPhotoWnd = ::GetDlgItem(hWnd, uCtrl);
if (hPhotoWnd != NULL)
{
hPhotoWndDC = ::GetDC(hPhotoWnd);
if (hPhotoWndDC != NULL)
{
hCompatDC = ::CreateCompatibleDC(hPhotoWndDC);
if (hCompatDC != NULL)
{
RECT rect;
::GetClientRect(hPhotoWnd, &rect);
HBITMAP oldBitmap = (HBITMAP)::SelectObject(hCompatDC, m_hCurrentBmp);
BITMAP bm;
::GetObject( m_hCurrentBmp, sizeof( bm ), &bm );
::StretchBlt(hPhotoWndDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hCompatDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
::SelectObject(hCompatDC, oldBitmap);
::ReleaseDC(hPhotoWnd, hCompatDC);
hr = S_OK;
}
::ReleaseDC(hPhotoWnd, hPhotoWndDC);
}
}
}
-
June 23rd, 1999, 03:46 PM
#3
Re: c++
// This should give you a clue how to do it
bool BitmapToDC(char *szImage)
{
// Try loading the image.
HBITMAP hbm = (HBITMAP)LoadImage(NULL, szImage, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if (hbm == NULL)
return false;
HDC hdcImage = CreateCompatibleDC(NULL);
SelectObject(hdcImage, hbm);
// if you need to draw the image on some window use GetDC and BitBlt (and ReleaseDC)
if (hdc)
DeleteDC(hdc);
if (hbm)
DeleteObject(hbm);
return true;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|