Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC CBitmap LoadBitmap()

MFC CBitmap LoadBitmap()

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsdebugginghelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tom76
    wrote on last edited by
    #1

    Hi all, Bit of a problem with CBitmap's LoadBitmap() function. If I make a bitmap a resource and do BitmapObj.LoadBitmap(IDB_MYBITMAP); The image is loaded fine, but if I do BitmapObj.LoadBitmap("MyBitmap.bmp"); it returns 0 (failed). I've tried moving the location of the file around the local directory (debug, res, etc.) but no luck. What do I need to do? Obseve everything, remember more...

    R 1 Reply Last reply
    0
    • T tom76

      Hi all, Bit of a problem with CBitmap's LoadBitmap() function. If I make a bitmap a resource and do BitmapObj.LoadBitmap(IDB_MYBITMAP); The image is loaded fine, but if I do BitmapObj.LoadBitmap("MyBitmap.bmp"); it returns 0 (failed). I've tried moving the location of the file around the local directory (debug, res, etc.) but no luck. What do I need to do? Obseve everything, remember more...

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      You can't load a bitmap file like that. To load a bitmap image from a file, use LoadImage():

      HBITMAP hbm = (HBITMAP)LoadImage(NULL, "MyBitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

      Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
      Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

      T 1 Reply Last reply
      0
      • R Ryan Binns

        You can't load a bitmap file like that. To load a bitmap image from a file, use LoadImage():

        HBITMAP hbm = (HBITMAP)LoadImage(NULL, "MyBitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

        Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
        Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

        T Offline
        T Offline
        tom76
        wrote on last edited by
        #3

        Okay, but there is a function LoadBitmap() that takes an LPCTSTR string of the name of the bitmap. How does one use it? Obseve everything, remember more...

        R 1 Reply Last reply
        0
        • T tom76

          Okay, but there is a function LoadBitmap() that takes an LPCTSTR string of the name of the bitmap. How does one use it? Obseve everything, remember more...

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          It loads a bitmap from a resource. If you look at the MFC source code, you'll find that the one that takes a UINT actually calls the one that takes a LPCTSTR to do the work. All resources are loaded via strings. The UINTs have to be coerced into looking like strings so that Windows can load them. Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
          Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups