Results 1 to 4 of 4

Thread: What's wrong here??

  1. #1

    Thread Starter
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161
    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...

    Code:
    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?
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    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.

  3. #3

    Thread Starter
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161
    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)
    Code:
    GetWindowRect(&wRect);
    AfxMessageBox(wRect.right);
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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:
    Code:
    MessageBox(pcNumberAsString, "wRect.right", MB_OK);
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width