PDA

Click to See Complete Forum and Search --> : What's wrong here??


Razzle
Sep 11th, 2000, 04:17 PM
my app always performs an illegal operation and crashes. I'm sure I know WHERE to find the mistake but I don't know how to fix it...


void CChildView::OnPaint()
{
CPaintDC dc(this);
LPRECT wRect;
CBitmap Bitmap;

Bitmap.LoadBitmap(MAKEINTRESOURCE(IDB_BITMAP2));
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
CBitmap * pOldBitmap = MemDC.SelectObject(&Bitmap);
GetWindowRect(wRect);

dc.BitBlt(300, 200,100, 100, &MemDC, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
Bitmap.DeleteObject();
}

I think it's the GetWindowRect function
any suggestions?

CthulhuDragon
Sep 11th, 2000, 04:22 PM
GetWindowRect is looking for a pointer to a preexisting rect. Not just an empty pointer. You are failing becuase the function is trying to write to nonexistent memory. Try
RECT wRect;

GetWindowRect(&wRect);

May need some tweaking. No compiler can't check.

Razzle
Sep 11th, 2000, 04:42 PM
Thanks!!
I'm still a newbie at VC++ so I didn't know...

I think this is working now but how can I read out wRect's values?
I tried this but it quit with an error(Debug Assertion failed)

GetWindowRect(&wRect);
AfxMessageBox(wRect.right);

parksie
Sep 12th, 2000, 12:25 PM
You can't use it like that...it's expecting a string of some kind. You'd need to use the itoa function. It's in the documentation, but I can't remember the details right now. Then, you'd need to use:

MessageBox(pcNumberAsString, "wRect.right", MB_OK);