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.

Recommended Answers

All 4 Replies

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.

i transfered my code to OnDraw but nothing comes out

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 ...
 }

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.