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. CBitmap::LoadBitmap help

CBitmap::LoadBitmap help

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
17 Posts 3 Posters 3 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    I am trying to load a bit map its in my res folder in fact I have also copied it folder where my .exe is it fail to load Here is My rc statement

    IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"

    and I do a CBitmap.LoadBitmap(IDB_BITMAP1); The return code is 0 The Documentations says

    Quote:

    by the ID number in nIDResource from the application's executable file.

    does that mean I have to link the application a certain way thanks

    V F 2 Replies Last reply
    0
    • F ForNow

      I am trying to load a bit map its in my res folder in fact I have also copied it folder where my .exe is it fail to load Here is My rc statement

      IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"

      and I do a CBitmap.LoadBitmap(IDB_BITMAP1); The return code is 0 The Documentations says

      Quote:

      by the ID number in nIDResource from the application's executable file.

      does that mean I have to link the application a certain way thanks

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      1. Are you sure the bitmap IDB_BITMAP1 is really included in your .exe? (try to load the .exe as a resource in VS and proof it). 2. Did you try to use LoadImage instead? 3. What does the GetLastError return if the loading fails?

      F 2 Replies Last reply
      0
      • V Victor Nijegorodov

        1. Are you sure the bitmap IDB_BITMAP1 is really included in your .exe? (try to load the .exe as a resource in VS and proof it). 2. Did you try to use LoadImage instead? 3. What does the GetLastError return if the loading fails?

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        What do you mean 'included in your .exe' I did try the load image and it failed I am not really sure what you mean by 'try to load the .exe as a resource' does the bitmap have to be linked into the .exe

        V 1 Reply Last reply
        0
        • F ForNow

          What do you mean 'included in your .exe' I did try the load image and it failed I am not really sure what you mean by 'try to load the .exe as a resource' does the bitmap have to be linked into the .exe

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          ForNow wrote:

          I am not really sure what you mean by 'try to load the .exe as a resource' does the bitmap have to be linked into the .exe

          Just open your VS, then Menu -> File -> Open -> find in the open file dialog (File Explorer) your .exe file -> open it! Then you will see the tree with all the embedded resources. Just navigate to the Bitmap hive and ensure that the bitmap with your bitmap ID does exist!

          1 Reply Last reply
          0
          • V Victor Nijegorodov

            1. Are you sure the bitmap IDB_BITMAP1 is really included in your .exe? (try to load the .exe as a resource in VS and proof it). 2. Did you try to use LoadImage instead? 3. What does the GetLastError return if the loading fails?

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            Yes it see it there are the resource numbers of my bitmaps my questions is then the following

            Quote:

            BREAKPOINT BITMAP "C:\\DriveRichEdit\\DriveRichEdit\\DriveRichEdit\\res\\bullet_red.bmp" IDR_MAINFRAME BITMAP "res\\Toolbar.bmp" IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"

            I have tried various strings 1) full path name of where the bitmap resides as indicated by my first entry 2) partial as indicated by my second entry "res\\Toolbar.bmp" would you know the correct entry thanks

            V 1 Reply Last reply
            0
            • F ForNow

              Yes it see it there are the resource numbers of my bitmaps my questions is then the following

              Quote:

              BREAKPOINT BITMAP "C:\\DriveRichEdit\\DriveRichEdit\\DriveRichEdit\\res\\bullet_red.bmp" IDR_MAINFRAME BITMAP "res\\Toolbar.bmp" IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"

              I have tried various strings 1) full path name of where the bitmap resides as indicated by my first entry 2) partial as indicated by my second entry "res\\Toolbar.bmp" would you know the correct entry thanks

              V Offline
              V Offline
              Victor Nijegorodov
              wrote on last edited by
              #6

              ForNow wrote:

              would you know the correct entry

              According your OP it should be:

              ForNow wrote:

              Here is My rc statement

              IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"

              F 1 Reply Last reply
              0
              • V Victor Nijegorodov

                ForNow wrote:

                would you know the correct entry

                According your OP it should be:

                ForNow wrote:

                Here is My rc statement

                IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                I re-checked the doc and it say I can put in the full path name of the bitmap going to do that I’ll also do a getlasterror if RC _!= 0 Thanks

                L 1 Reply Last reply
                0
                • F ForNow

                  I re-checked the doc and it say I can put in the full path name of the bitmap going to do that I’ll also do a getlasterror if RC _!= 0 Thanks

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  You should not need to as the location is only required by the compiler when it builds the executable. Part of the build process is to embed all resources into the final executable. You can check it by getting hold of one of the many free resource editors available online.

                  F 1 Reply Last reply
                  0
                  • L Lost User

                    You should not need to as the location is only required by the compiler when it builds the executable. Part of the build process is to embed all resources into the final executable. You can check it by getting hold of one of the many free resource editors available online.

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #9

                    so the bitmap is in the exe I google and see a product Resource tuner maybe i should try it see if it finds the bitap and maybe the problem is I didn't link it in right with the res file thanks

                    L 1 Reply Last reply
                    0
                    • F ForNow

                      so the bitmap is in the exe I google and see a product Resource tuner maybe i should try it see if it finds the bitap and maybe the problem is I didn't link it in right with the res file thanks

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      I have never encountered a project where the resources did not get included correctly. In fact I just ran a quick test and it worked fine.

                      1 Reply Last reply
                      0
                      • F ForNow

                        I am trying to load a bit map its in my res folder in fact I have also copied it folder where my .exe is it fail to load Here is My rc statement

                        IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"

                        and I do a CBitmap.LoadBitmap(IDB_BITMAP1); The return code is 0 The Documentations says

                        Quote:

                        by the ID number in nIDResource from the application's executable file.

                        does that mean I have to link the application a certain way thanks

                        F Offline
                        F Offline
                        ForNow
                        wrote on last edited by
                        #11

                        Did a Cimage load the HRESULT was 0 did CBitmap::Attach (there is not documentation on this) but return code was 1 when I looked at the n_hObject in VS debugger it had high order X'FF' the handle was FFFFFFFF88052070 never saw a resource handle with high order X'FF' ITS usually zeros

                        V L 3 Replies Last reply
                        0
                        • F ForNow

                          Did a Cimage load the HRESULT was 0 did CBitmap::Attach (there is not documentation on this) but return code was 1 when I looked at the n_hObject in VS debugger it had high order X'FF' the handle was FFFFFFFF88052070 never saw a resource handle with high order X'FF' ITS usually zeros

                          V Offline
                          V Offline
                          Victor Nijegorodov
                          wrote on last edited by
                          #12

                          1. "the HRESULT was 0" (S_OK) means the function completed successfully. 2. "(there is not documentation on CBitmap::Attach)". However, there is a documentation on its base class method: [CGdiObject Class | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/mfc/reference/cgdiobject-class?view=msvc-160#attach)

                          1 Reply Last reply
                          0
                          • F ForNow

                            Did a Cimage load the HRESULT was 0 did CBitmap::Attach (there is not documentation on this) but return code was 1 when I looked at the n_hObject in VS debugger it had high order X'FF' the handle was FFFFFFFF88052070 never saw a resource handle with high order X'FF' ITS usually zeros

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            I suspect that whatever results you got are not valid, since you need to pass a GDI object to the Attach call in the first place. So what were you trying to attach? As I suggested earlier you definitely need to find out whether this image actually exists in your executable's resources, and if not, why not?

                            1 Reply Last reply
                            0
                            • F ForNow

                              Did a Cimage load the HRESULT was 0 did CBitmap::Attach (there is not documentation on this) but return code was 1 when I looked at the n_hObject in VS debugger it had high order X'FF' the handle was FFFFFFFF88052070 never saw a resource handle with high order X'FF' ITS usually zeros

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #14

                              As I have mentioned previously I do not have MFC. But recreating what you are trying to do in pure Win32 (which is what MFC does under the covers) I have successfully loaded and displayed a bitmap resource.

                              F 1 Reply Last reply
                              0
                              • L Lost User

                                As I have mentioned previously I do not have MFC. But recreating what you are trying to do in pure Win32 (which is what MFC does under the covers) I have successfully loaded and displayed a bitmap resource.

                                F Offline
                                F Offline
                                ForNow
                                wrote on last edited by
                                #15

                                thanks for your help I re-linked my app and after I did the attach the HANDLE had leading zeros and displayed I played around with BitBlt and StreachBlt One problem the RED bullet is placed in the middle of a rectangle the color of the rectangle is black. So my static control is gray. and there is a black squared with a red bullet. Is there anyway to have the black "background color of the bitmap rectangle" be the the same as the background of the destination control I have tried creating a brush with that control color selecting/selectobjct and CDC::Fillrect and FillSolidRect Doesn't seem to have any effect Thanks

                                V 1 Reply Last reply
                                0
                                • F ForNow

                                  thanks for your help I re-linked my app and after I did the attach the HANDLE had leading zeros and displayed I played around with BitBlt and StreachBlt One problem the RED bullet is placed in the middle of a rectangle the color of the rectangle is black. So my static control is gray. and there is a black squared with a red bullet. Is there anyway to have the black "background color of the bitmap rectangle" be the the same as the background of the destination control I have tried creating a brush with that control color selecting/selectobjct and CDC::Fillrect and FillSolidRect Doesn't seem to have any effect Thanks

                                  V Offline
                                  V Offline
                                  Victor Nijegorodov
                                  wrote on last edited by
                                  #16

                                  Try to use icon (with transparent background) instead.

                                  F 1 Reply Last reply
                                  0
                                  • V Victor Nijegorodov

                                    Try to use icon (with transparent background) instead.

                                    F Offline
                                    F Offline
                                    ForNow
                                    wrote on last edited by
                                    #17

                                    Quote:

                                    used TransparentBLT thank you all"

                                    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