Draw bitmaps

This is a discussion on Draw bitmaps within the Windows Programming forums, part of the Platform Specific Boards category; 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... ...

  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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    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, 10: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, 05: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, 05:51 AM
  5. Draw Shapes.
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 08-19-2002, 09:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21