Thread: Passing a HBITMAP by reference??

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    76

    Passing a HBITMAP by reference??

    Hi I have got a few different classes which each draw a different thign to the screen so I decided to wrap them all in one sing Game wrapper class. Now for a member I have created a HBITMAP. Now I was planning to pass that bitmap by reference to the other classes let them draw onto it and the bitblt it to the screen. The only problem is any drawing that the other classes do. Does not appear on the screen. I was just wondering if it was even possible to use this approach

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    first of all, there is no need to pass it by reference. An HBITMAP is a handle to a bitmap and that handle value is not going to change

    you may certainly use that approach by selecting it into a memory dc and then selecting it back out when you're done drawing on it.

    but you may be better served by passing an HDC around instead of an HBITMAP
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Sounds like you are talking about the difference between a "shallow copy" and a "deep copy", or in other words, a copy of the handle or a copy of what the handle represents.

    If your application is single threaded then all your classes could reference a single HBITMAP instance for performing BitBlt()'s. However, if you do this with multiple memory DC instances, then be sure de-select the HBITMAP out of the memory DC before selecting it into another memory DC. This may be why only one of your classes are successfully drawing.

    gg

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    true. If you fail to select it out of a dc you will have problems because an HBITMAP can only be selected into one DC at a time.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    Are okay I think I understand, but my program is starting to confuse me. What happens if the I just create a hdc as a member instead and reference that, because I get excatly the same results. As soon as the first object gets updated it just gets replaced by whiteness.

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I think we have to see some code. Are you painting on the WM_PAINT notification? If not, you might get your output overwritten.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Zip up your source code and post it. Someone will take a look at it.

    gg

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    Yeah sure. All I have got now is the version that has a HDC as a member varible. I don't have the one with the HBITMAP member anymore.
    main.cpp. Equals the windows class and the winmain function.
    Game.h Container class which actually controls how the game runs
    TBLinkedList.h & TbNode.h These basically hold the classes and implementation for a linked list that holds a series of tri blocks.

    TriBlock.h Hold a class that consists of three blocks
    Block.h Basic block that gets drawn.

    Before I put everythin into a HDC or bitmap. It flickered but ir ran perfectly. I still have a copy of this if you need it at any time. Many thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM