Thread: Draw bitmaps

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    Draw bitmaps

    hello there

    (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_BG), IMAGE_BITMAP, x, y, NULL);
    This piece of code does not seem to work as it should...
    I need to draw a bitmap which is saved as source but the LoadImage() does not want to allow me that...

    The only thing what works for me is

    (HBITMAP)LoadImage(hInstance, TEXT("*.bmp"), IMAGE_BITMAP, x, y, LR_LOADFROMFILE);
    But that is not what I am for...

    What shall I try else?

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    If you are loading from a resource you need to use the function that operates on those. If you are loading an image from an external source then you need to use LoadImage as you have shown.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Quote Originally Posted by Bubba View Post
    If you are loading from a resource you need to use the function that operates on those. If you are loading an image from an external source then you need to use LoadImage as you have shown.
    I will try to look it up... If you have in mind some particular function that does this please note me...

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    LoadResource / FindResource I think.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by Gordon View Post
    hello there

    (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_BG), IMAGE_BITMAP, x, y, NULL);
    This piece of code does not seem to work as it should...
    I need to draw a bitmap which is saved as source but the LoadImage() does not want to allow me that...
    LoadImage is fine for loading resource bitmaps provided you have properly included a BITMAP resource definition statement (in a resource script, *.rc) and associated #define for IDB_BG in your build - but replace NULL with LR_CREATEDIBSECTION as the last parameter of LoadImage. Make sure you check that the return value from LoadImage is non-NULL; if it's NULL, use GetLastError to provide you with more information regarding the api function failure.

    Search this board, too, as this sort of thing has been discussed before.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Which is the better way to draw?
    By g4j31a5 in forum Game Programming
    Replies: 16
    Last Post: 01-22-2007, 11:56 PM
  2. draw function HELP!!!
    By sunoflight77 in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 11:28 PM
  3. ray casting
    By lambs4 in forum Game Programming
    Replies: 62
    Last Post: 01-09-2003, 06:57 PM
  4. draw to a BITMAP* argument - allegro and objects again
    By MadHatter in forum Game Programming
    Replies: 13
    Last Post: 12-13-2002, 06:51 AM
  5. Draw Shapes.
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 08-19-2002, 09:22 AM