Thanks again for the reply.
Alright, it looks better now, and I checked quite a few of the return values, and everything looks good... but when the background is displayed its completely red, and turns white after about a minute. I don't know what that is about since the bitmap is loaded once and doesn't change.
The one thing I know isn't right is the width and height, but the ratio looks correct... so I think theres a conversion I need for that. I think I still might be using Render wrong though, because the example I looked at has it setup like:
Code:
gpPicture->Render(pDC->m_hDC,
ptUL.x,
ptUL.y,
nWidth,
-nHeight,
0,
hmHeight,
hmWidth,
-hmHeight,
&rc);
The &rc can be NULL, but they use odd positioning, and the - before height doesn't even seem valid.
I looked at msdn and mine looks correct...
any idea, or as to what I should debug further?
Code:
HBITMAP loadResourcePicture(int resid) {
// variables
HBITMAP hBitmap;
HBITMAP hDefaultBmp;
DWORD dwFileSize;
LPPICTURE gpPicture;
LPVOID lpPicData;
LPVOID pvData;
LPSTREAM pstm;
HRSRC hrlp;
HGLOBAL hGlobal;
HDC hdc;
HDC hMem;
HINSTANCE hInst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
long width;
long height;
// find resource
hrlp = FindResource(hInst, MAKEINTRESOURCE(resid), RT_RCDATA);
// make sure it found something
if (hrlp != NULL) {
dwFileSize = SizeofResource(hInst, hrlp);
hGlobal = LoadResource(hInst, hrlp);
// something was loaded
if (hGlobal != 0) {
lpPicData = LockResource(hGlobal);
pvData = NULL;
hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
pvData = GlobalLock(hGlobal);
CopyMemory(pvData, lpPicData, dwFileSize);
GlobalUnlock(hGlobal);
// create stream and load picture from it
CreateStreamOnHGlobal(hGlobal, TRUE, &pstm); // returns s_ok
OleLoadPicture(pstm, 0, FALSE, IID_IPicture, (LPVOID*)&gpPicture); // returns s_ok
pstm->Release();
// get picture
hdc = GetDC(hwnd);
hMem = CreateCompatibleDC(hdc);
gpPicture->get_Width(&width); // returns around 40000 compared to 1500
gpPicture->get_Height(&height); // returns around 12000 compared to 464
width = 1500;
height = 464;
gpPicture->Render(hMem, 0, 0, width, height, 0, height, width, -1*height, NULL); // returns s_ok
//hBitmap = CreateCompatibleBitmap(hMem, width, height);
hDefaultBmp = CreateCompatibleBitmap(hMem, width, height);
hBitmap = (HBITMAP)SelectObject(hMem, hDefaultBmp); // for now
//hBitmap = (HBITMAP)GetCurrentObject(hMem, OBJ_BITMAP);
ReleaseDC(hwnd, hdc);
// release picture
gpPicture->Release();
// delete dcs
DeleteDC(hdc);
DeleteDC(hMem);
// return
return hBitmap;
}
}
MessageBox(hwnd, "Fail", NULL, MB_OK);
}
EDIT: Render should be fixed, and still nothing. I drew a rectangle to hMem right after the render, and still nothing. So I am guessing the HBITMAP is not being returned correctly...