0
void CMod7aView::OnPaint() 
{
	CClientDC dc(this);

    
 
 if(hBmp!=NULL)
 {
	 CBitmap bmp;
	 bmp.Attach(hBmp);
 
   CDC bmDC;
   bmDC.CreateCompatibleDC(&dc);
   CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
   BITMAP  bi;
   bmp.GetBitmap(&bi);
   dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
   bmDC.SelectObject(pOldbmp);

   

  
}

how do you make your image persistant? everytime iload a bitmap after I move the main window the image disappears.

pls help me.

2
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by Covinus
0

you need to use a CPaintDC (not a CClientDC) in a handler for OnPaint (WM_PAINT requires calls to BeginPaint/EndPaint). it would be much better (and easier) if you override the virtual function CView::OnDraw( CDC* ) and write your code for painting the view there (and not implement OnPaint yourself). let the framework do all the work including creating the right device context and then call your override for OnDraw.

0

you also need to

a. remove your handler for OnPaint()
b. use the device context that is passed as an arg to OnDraw

  ... :: OnDraw( CDC* pDC )
 {
       pDC->whatever ...
 }

Edited by pyTony: fixed formatting

0

my bitmap is persistent on the window. Thanks a million. now my problem is to rotate it. im gonna do some googling for now. thanks again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.