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. How to use LoadBitmap in a dialog box

How to use LoadBitmap in a dialog box

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutoriallearning
23 Posts 4 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.
  • Y yaminisridaran

    I have to load a bitmap in a dialog box. I have loaded the Image in bitmap resource and then I tried the below code HBITMAP hBitmap=(HBITMAP)LoadBitmap(AfxGetInstanceHandle,"IDB_IMAGE"); but when i execute this statement the hBitmap is 0x0000000. Can anyone give me some suggestions. Is there any way to transparent the background of a button S.Yamini

    B Offline
    B Offline
    Bhavesh Bagadiya
    wrote on last edited by
    #9

    If u want it use it with CDC(though not recommended) u can use it like below, PAINTSTRUCT pStruct; CDC* pDC = BeginPaint(&pStruct); //Use CDC here. pDC->DoWhatEverYouWantToDo(); // !! EndPaint(&pStruct); //Don't forget this o'wise sometime result would be disastrous.!! (For your knowledge, CClientDC and CPaintDC both do BeginPaint in Constructor and EndPaint in Destructor..)

    Y 1 Reply Last reply
    0
    • C chandu004

      it is a bit easy task to load an image, on a dialog but before i proceed to suggest you the best technique, that suits your application, please answer these questions. 1.is your image constant throughout the application, or it may change based on the context dynamically. 2.have you already created a resource for that image? 3.if you have only one image and want to see it on the screen, then you can link it statically. 4.if you have to load images, based on the context(condition) then you can take that many number of controls and toggle them as per your requirement.

      Y Offline
      Y Offline
      yaminisridaran
      wrote on last edited by
      #10

      I have to change the image dynamically according to the move movement on the dialog box S.Yamini

      C 1 Reply Last reply
      0
      • B Bhavesh Bagadiya

        If u want it use it with CDC(though not recommended) u can use it like below, PAINTSTRUCT pStruct; CDC* pDC = BeginPaint(&pStruct); //Use CDC here. pDC->DoWhatEverYouWantToDo(); // !! EndPaint(&pStruct); //Don't forget this o'wise sometime result would be disastrous.!! (For your knowledge, CClientDC and CPaintDC both do BeginPaint in Constructor and EndPaint in Destructor..)

        Y Offline
        Y Offline
        yaminisridaran
        wrote on last edited by
        #11

        I tried it in onintidialog it does not work. Can u suggest some more ways to solve this issue S.Yamini

        B 1 Reply Last reply
        0
        • Y yaminisridaran

          I have to change the image dynamically according to the move movement on the dialog box S.Yamini

          C Offline
          C Offline
          chandu004
          wrote on last edited by
          #12

          how many images you have to the max.

          Y C 2 Replies Last reply
          0
          • Y yaminisridaran

            I tried it in onintidialog it does not work. Can u suggest some more ways to solve this issue S.Yamini

            B Offline
            B Offline
            Bhavesh Bagadiya
            wrote on last edited by
            #13

            after onInitdialog completes, whole dialog being repainted so your graphics erased. one solution is to override OnEraseBkgnd and return TRUE from it so System will never erase background. but be careful, system never erase Background !!

            Y 1 Reply Last reply
            0
            • C chandu004

              how many images you have to the max.

              Y Offline
              Y Offline
              yaminisridaran
              wrote on last edited by
              #14

              I have two images.I has to toggle according to the mouse movement. I nned to know how to get the dc of the dialog control.Please S.Yamini

              C 1 Reply Last reply
              0
              • B Bhavesh Bagadiya

                after onInitdialog completes, whole dialog being repainted so your graphics erased. one solution is to override OnEraseBkgnd and return TRUE from it so System will never erase background. but be careful, system never erase Background !!

                Y Offline
                Y Offline
                yaminisridaran
                wrote on last edited by
                #15

                I cannot use erasebk bcoz i have to toggle the images. S.Yamini

                B 1 Reply Last reply
                0
                • Y yaminisridaran

                  I cannot use erasebk bcoz i have to toggle the images. S.Yamini

                  B Offline
                  B Offline
                  Bhavesh Bagadiya
                  wrote on last edited by
                  #16

                  so whats problem will be in toggling images after overriding eraseBk ??? whatever painting done by you will be there, only system won't paint its default bkground ...

                  Y 1 Reply Last reply
                  0
                  • C chandu004

                    how many images you have to the max.

                    C Offline
                    C Offline
                    chandu004
                    wrote on last edited by
                    #17

                    are you using the bitmap control you have in your tool bar, or is it ok for you if i give my active X control which can take any bitmap image any time. what all you have to do is, you have to specify the file path. for example, ctrl.SetImage("C:\\image1.bmp"); then after some time, ctrl.SetImage("C:\\image2.bmp"); is it ok for u.

                    1 Reply Last reply
                    0
                    • Y yaminisridaran

                      I have two images.I has to toggle according to the mouse movement. I nned to know how to get the dc of the dialog control.Please S.Yamini

                      C Offline
                      C Offline
                      chandu004
                      wrote on last edited by
                      #18

                      assign a member variable to that control, then, m_ctrl.GetDC();

                      1 Reply Last reply
                      0
                      • B Bhavesh Bagadiya

                        so whats problem will be in toggling images after overriding eraseBk ??? whatever painting done by you will be there, only system won't paint its default bkground ...

                        Y Offline
                        Y Offline
                        yaminisridaran
                        wrote on last edited by
                        #19

                        Yes it will work. Can u suggest me for transparenting the background for the button control S.Yamini

                        B 1 Reply Last reply
                        0
                        • Y yaminisridaran

                          Yes it will work. Can u suggest me for transparenting the background for the button control S.Yamini

                          B Offline
                          B Offline
                          Bhavesh Bagadiya
                          wrote on last edited by
                          #20

                          again, You can override OnEraceBk,, and return TRUE from there for that button, it won't paint buton background...

                          Y 1 Reply Last reply
                          0
                          • B Bhavesh Bagadiya

                            again, You can override OnEraceBk,, and return TRUE from there for that button, it won't paint buton background...

                            Y Offline
                            Y Offline
                            yaminisridaran
                            wrote on last edited by
                            #21

                            Thanks I will try S.Yamini

                            1 Reply Last reply
                            0
                            • Y yaminisridaran

                              I have to load a bitmap in a dialog box. I have loaded the Image in bitmap resource and then I tried the below code HBITMAP hBitmap=(HBITMAP)LoadBitmap(AfxGetInstanceHandle,"IDB_IMAGE"); but when i execute this statement the hBitmap is 0x0000000. Can anyone give me some suggestions. Is there any way to transparent the background of a button S.Yamini

                              H Offline
                              H Offline
                              Hamid Taebi
                              wrote on last edited by
                              #22

                              If you have bmp on the resource you can use of CBitmap class.

                              Y 1 Reply Last reply
                              0
                              • H Hamid Taebi

                                If you have bmp on the resource you can use of CBitmap class.

                                Y Offline
                                Y Offline
                                yaminisridaran
                                wrote on last edited by
                                #23

                                Thanks. Is there any calculation to convert the x,y coordinate of the CPoint to angle of the circle S.Yamini

                                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