Thread: Lots of bitmaps

  1. #1
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273

    Lots of bitmaps

    Hi. I am really new to this kind of programming, windows programming I mean.

    Anyway, I made a program yesterday which is an empty window and has a bitmap in it. When the user moves the keys around, the picture moves along with them. Now, here's the problem:

    I want it so that there would be two pictures in the program, and that they could both move. The moving thing should be fine, but i don't know how to put two pictures in the screen, well I do, but I don't know how to see both the picture on on the same window. If I put in a second picture the way I put in the first one, the first one dissappears, and I can't se it. I reckon it must be something to do with the function deleting the entire contents, and then re-printing them, but I really don't know. I have done lots of MSDN searching and whatnot, but i can't see anything that could help. I think it's commented enough ... I hope.

    Anyways, here's the code (attached), and if anyone can help me, it would be greatly appreciated!!
    Last edited by twomers; 08-03-2006 at 03:24 PM.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    MFC or pure Win32?

    For MFC you need to override the OnPaint() and create a memory DC along with a memory CBitmap.

    Code:
    void SomeWindow::OnPaint(void)
    {
      CPaintDC dc(this);
    
      CDC memDC;
      memDC.CreateCompatibleDC(&dc);
    
      CRect rect;
      GetClientRect(&rect);
    
      CBitmap memBitmap;
      memBitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
    
      CBitmap *pPrevBitmap=memDC.SelectObject(&memBitmap);
    
      //Draw to memDC now
      ....
      ....
    
      //Blit final result to dc
    
      dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
    
      memDC.SelectObject(pPrevBitmap);
    }
    This is the equivalent of double buffering in MFC code. Check the code because the SelectObject's don't look quite right. If you leak GDI objects here, those lines are the culprit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing bitmaps efficiently
    By scwizzo in forum Windows Programming
    Replies: 28
    Last Post: 06-30-2009, 08:25 PM
  2. DX9 Not Displaying Bitmaps
    By Sentral in forum Game Programming
    Replies: 9
    Last Post: 01-31-2006, 05:35 AM
  3. MFC: Multiple clicks shows multiple bitmaps - how?
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-20-2004, 07:25 PM
  4. using standard bitmaps in the toolbar editor
    By Kibble in forum Windows Programming
    Replies: 0
    Last Post: 12-23-2002, 08:43 PM
  5. Bitmaps (without api support)
    By master5001 in forum Windows Programming
    Replies: 11
    Last Post: 07-14-2002, 11:31 AM