Re: CView and bitmap problem
Your problem depends on alot of things like the value in m_data.m_RECT,
org.x and org.y, width, height. Are you sure you are drawing things into the
bitmap correctly. It is kind of hard to point you in the wrong direction.
If you are saying that one time OnDraw does things correctly and later it
screws up, then you need to find out what happens to the relevant variables
between the runs find and screws up.
In general you seem to be doing things correctly, you at least have the
concept down. All you have to do is do some debugging. I know setting is
breakpoint in OnDraw is difficult (not that difficult if you have two
monitors), but you can use TRACE statements and even ASSERTs to verify your
data is what you expect it to be.
Just out of curiosity, why are you not using CBitmap?
Have you tried this?
CRect Rect;
GetClientRect(&Rect);
pDC->StretchBlt(0, 0, Rect.Width(), Rect.Height, &memDC, 0, 0, bm.bmWidth,
bm.bmHeight, SRCCOPY);
AliR.
"Scoots" <linkingfire@msn.com> wrote in message
news:9a7e8bf3-38f4-4cfc-bd52-c6a94f2edf47@y33g2000prg.googlegroups.com...
Okay, I honestly have researched this problem and haven't found an
answer. Please do not immediately dismiss this as a "put drawing code
in WM_PAINT", read it through.
I have an MDI architecture in which I've overridden the OnDraw() of
the view. I handle my drawing from there (also with an overridden
OnPrepareDC()). My drawing of rectangles and lines, and arcs, and all
that works well. I can even draw bitmaps.
However, when a window ocludes the bitmap, it is not refreshed, even
though the OnDraw() calls the draw code for my bitmap. I've traced it
and it DOES execute the following code:
// Get logical coordinates
BITMAP bm;
::GetObject( m_hbitmap, sizeof( bm ), &bm );
CPoint org(0,0);
pDC->LPtoDP(&org);
// Create a memory DC compatible with the destination DC
CDC memDC;
memDC.CreateCompatibleDC( pDC );
memDC.SetMapMode( pDC->GetMapMode() );
HBITMAP hBmOld = (HBITMAP)::SelectObject( memDC.m_hDC, m_hbitmap );
pDC->StretchBlt((int)m_data.m_RECT.left, (int)m_data.m_RECT.top,
width, height, &memDC, org.x, org.y, (int)bm.bmWidth, (int)
bm.bmHeight, SRCCOPY);
::SelectObject( memDC.m_hDC, hBmOld );
memDC.DeleteDC();
But nothing appears. No bitmap. The other objects, such as
rectangles, etc, don't have this problem, they get redrawn correctly,
and yes, they're all drawn at the same time, using the same
transformation matrixes, etc. If I resize the view (with the cursor),
it reappears. Again, the same code was used that wasn't showing it a
moment ago. I also get this disappearing bitmap if I minimize and
restore the application.
I can confirm that my draw code displays the bitmap properly the first
time and anytime the window is resized (and I do NOT have the onsize
overridden). It also draws correctly if I invalidate the bitmap
rectangle anytime I draw it (with true for the erase parameter) (yes,
that's just a test, and a proof of concept. Obviously not
desirable). So my code can draw it, but what could be causing the
bitmap drawing to be not drawing anything anytime the bitmap is
covered, and then uncovered?
I'm not sure where to look on this one, so I'll have to ask for your
patience and I'll post what I can regarding the application. Sorry if
this is frequently asked, but I've found that all the answers I could
find were either "draw it again in the OnDraw/OnPaint" or "make sure
you detach it from the CBitmap", and it's neither of those.
Thanks for your patience and your help, both on this issue and prior
issues.
~Scoots