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 can I use LoadBitmap() for loading a bitmap no button

How can I use LoadBitmap() for loading a bitmap no button

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicsquestion
10 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.
  • S Offline
    S Offline
    Saday Sarkar
    wrote on last edited by
    #1

    I am new in vc++ world. I want to give a bit map on a button . I'm using CBitmapButton::LoadBitmap(); but it is not loaded.Giving error is:"Failed to load bitmap for normal image." Can any one help by giving proper method to do that. Thank to all THE CODE PROJECT users.

    O B 2 Replies Last reply
    0
    • S Saday Sarkar

      I am new in vc++ world. I want to give a bit map on a button . I'm using CBitmapButton::LoadBitmap(); but it is not loaded.Giving error is:"Failed to load bitmap for normal image." Can any one help by giving proper method to do that. Thank to all THE CODE PROJECT users.

      O Offline
      O Offline
      Owner drawn
      wrote on last edited by
      #2

      CBitmapButton myButton;

      // Create the bitmap button (must include the BS_OWNERDRAW style).
      myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
      CRect(10,10,100,100), pParentWnd, 1);

      // Load the bitmaps for this button.
      myButton.LoadBitmaps(IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE);

      You must replace IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE with your own bitmap id's that you have imported or added to the project.

      Jesus Loves You and Me :)

      --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

      S 1 Reply Last reply
      0
      • O Owner drawn

        CBitmapButton myButton;

        // Create the bitmap button (must include the BS_OWNERDRAW style).
        myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
        CRect(10,10,100,100), pParentWnd, 1);

        // Load the bitmaps for this button.
        myButton.LoadBitmaps(IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE);

        You must replace IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE with your own bitmap id's that you have imported or added to the project.

        Jesus Loves You and Me :)

        --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

        S Offline
        S Offline
        Saday Sarkar
        wrote on last edited by
        #3

        But if I replace the parameter "pParentWnd" by "this" the button is not showing. To Show that what I have to do? ------------------------------------------------------------------ CBitmapButton myButton; myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, CRect(10,10,100,100), this, 1); // Load the bitmaps for this button. myButton.LoadBitmaps(IDB_UPU, IDB_DOWND, IDB_FOCUSF, IDB_DISABLEX); ------------------------------------------------------------------ plz help. Thank u. -- modified at 4:10 Thursday 29th December, 2005

        O I S 3 Replies Last reply
        0
        • S Saday Sarkar

          But if I replace the parameter "pParentWnd" by "this" the button is not showing. To Show that what I have to do? ------------------------------------------------------------------ CBitmapButton myButton; myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, CRect(10,10,100,100), this, 1); // Load the bitmaps for this button. myButton.LoadBitmaps(IDB_UPU, IDB_DOWND, IDB_FOCUSF, IDB_DISABLEX); ------------------------------------------------------------------ plz help. Thank u. -- modified at 4:10 Thursday 29th December, 2005

          O Offline
          O Offline
          Owner drawn
          wrote on last edited by
          #4

          Are you trying this in a dialog. Do you already have a button. If so then you have to add a member variable for that button with type as CBitmapButton and then use AutoLoad(). And don't forget to set the ownerdrawn property to true. m_YourBmpButton.AutoLoad(IDC_MYBUTTON, this); and then set the images. Perhaps you may not have to call AutoLoad(...) if you are adding a member variable.

          Jesus Loves You and Me :)

          --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

          1 Reply Last reply
          0
          • S Saday Sarkar

            But if I replace the parameter "pParentWnd" by "this" the button is not showing. To Show that what I have to do? ------------------------------------------------------------------ CBitmapButton myButton; myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, CRect(10,10,100,100), this, 1); // Load the bitmaps for this button. myButton.LoadBitmaps(IDB_UPU, IDB_DOWND, IDB_FOCUSF, IDB_DISABLEX); ------------------------------------------------------------------ plz help. Thank u. -- modified at 4:10 Thursday 29th December, 2005

            I Offline
            I Offline
            Identity Undisclosed
            wrote on last edited by
            #5

            The problem is that since u r creating button in a function, so it will be allocated on stack. and as the function is returned back ,where u are creating a button, all items are pop out of the stack. So ur button will no longer exists. Either u make it(myButton) member of class or Create the CBitmapButton object on Heap. The code for creating on Heap is: CBitmapButton* myButton = new CBitmapButton; myButton->Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, CRect(10,10,100,100), this, 1); // Load the bitmaps for this button. myButton->LoadBitmaps(IDB_UPU, IDB_DOWND, IDB_FOCUSF, IDB_DISABLEX) Plus u must call delete in ur destructor or the entry after the button is not required. It hope it helps :P -- modified at 4:33 Thursday 29th December, 2005

            S 1 Reply Last reply
            0
            • S Saday Sarkar

              But if I replace the parameter "pParentWnd" by "this" the button is not showing. To Show that what I have to do? ------------------------------------------------------------------ CBitmapButton myButton; myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, CRect(10,10,100,100), this, 1); // Load the bitmaps for this button. myButton.LoadBitmaps(IDB_UPU, IDB_DOWND, IDB_FOCUSF, IDB_DISABLEX); ------------------------------------------------------------------ plz help. Thank u. -- modified at 4:10 Thursday 29th December, 2005

              S Offline
              S Offline
              Saday Sarkar
              wrote on last edited by
              #6

              Still now I'm not geting the result. PLz help. I am using dialog base. I take a button. Then create member m_button of the button. ------------------------------------------------------------------ CBitmapButton m_button;//at constractor ------------------------------------------------------------------- DDX_Control(pDX, IDC_BUTTON1, m_button);(at DoDataExchange) ------------------------------------------------------------------- I've import bitmaps mamed IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE then using .... ------------------------------------------------------------------- m_button.LoadBitmaps("IDB_UPU", "IDB_DOWND", "IDB_FOCUSF", "IDB_DISABLEX"); ----------------------------------------------------------------------- Q1> How can i give the property "WS_CHILD|WS_VISIBLE|BS_OWNERDRAW". Q2> If i use Autoload() then how i can give names of Bitmaps? Very Very thanks.

              O 1 Reply Last reply
              0
              • I Identity Undisclosed

                The problem is that since u r creating button in a function, so it will be allocated on stack. and as the function is returned back ,where u are creating a button, all items are pop out of the stack. So ur button will no longer exists. Either u make it(myButton) member of class or Create the CBitmapButton object on Heap. The code for creating on Heap is: CBitmapButton* myButton = new CBitmapButton; myButton->Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, CRect(10,10,100,100), this, 1); // Load the bitmaps for this button. myButton->LoadBitmaps(IDB_UPU, IDB_DOWND, IDB_FOCUSF, IDB_DISABLEX) Plus u must call delete in ur destructor or the entry after the button is not required. It hope it helps :P -- modified at 4:33 Thursday 29th December, 2005

                S Offline
                S Offline
                Saday Sarkar
                wrote on last edited by
                #7

                Ok I've got . Very very Thanks

                1 Reply Last reply
                0
                • S Saday Sarkar

                  Still now I'm not geting the result. PLz help. I am using dialog base. I take a button. Then create member m_button of the button. ------------------------------------------------------------------ CBitmapButton m_button;//at constractor ------------------------------------------------------------------- DDX_Control(pDX, IDC_BUTTON1, m_button);(at DoDataExchange) ------------------------------------------------------------------- I've import bitmaps mamed IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE then using .... ------------------------------------------------------------------- m_button.LoadBitmaps("IDB_UPU", "IDB_DOWND", "IDB_FOCUSF", "IDB_DISABLEX"); ----------------------------------------------------------------------- Q1> How can i give the property "WS_CHILD|WS_VISIBLE|BS_OWNERDRAW". Q2> If i use Autoload() then how i can give names of Bitmaps? Very Very thanks.

                  O Offline
                  O Offline
                  Owner drawn
                  wrote on last edited by
                  #8

                  Saday Sarkar wrote:

                  CBitmapButton m_button;//at constractor

                  :omg: What's this. You declared m_button in the constructor. You must do it in the header file. using AutoLoad is easy. But I don't think you will need it. But any way here it is. m_button.AutoLoad(IDC_BUTTON1, this/*parent window*/); m_button.SetBitmaps(..........) This should work. Make sure that the button in the dialog has the ownerdrawn property set to TRUE

                  Jesus Loves You and Me :)

                  --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

                  S 1 Reply Last reply
                  0
                  • O Owner drawn

                    Saday Sarkar wrote:

                    CBitmapButton m_button;//at constractor

                    :omg: What's this. You declared m_button in the constructor. You must do it in the header file. using AutoLoad is easy. But I don't think you will need it. But any way here it is. m_button.AutoLoad(IDC_BUTTON1, this/*parent window*/); m_button.SetBitmaps(..........) This should work. Make sure that the button in the dialog has the ownerdrawn property set to TRUE

                    Jesus Loves You and Me :)

                    --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

                    S Offline
                    S Offline
                    Saday Sarkar
                    wrote on last edited by
                    #9

                    Yes I've got. I've not do"the button in the dialog has the ownerdrawn property set to TRUE " Now ok. Very Very Thanks.

                    1 Reply Last reply
                    0
                    • S Saday Sarkar

                      I am new in vc++ world. I want to give a bit map on a button . I'm using CBitmapButton::LoadBitmap(); but it is not loaded.Giving error is:"Failed to load bitmap for normal image." Can any one help by giving proper method to do that. Thank to all THE CODE PROJECT users.

                      B Offline
                      B Offline
                      BlackDice
                      wrote on last edited by
                      #10

                      I think this way is easier:

                      //button must have 'Bitmap' property set to true
                      CButton* pButton = (CButton*)GetDlgItem(IDC_VIEWSCAPS);
                      ASSERT(pButton);
                      if(pButton)
                      {
                      	VERIFY(m_bmpBSBitmap.LoadBitmap(IDB_ADD));
                      	HBITMAP hbmp = (HBITMAP)m_bmpBSBitmap.GetSafeHandle();
                      	pButton->SetBitmap(hbmp);
                      }
                      

                      IDB_ADD is replaced with bitmap resource id IDC_VIEWSCAPS is replaced with button resource id make sure you set 'bitmap' property for the button to true My articles BlackDice

                      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