Bitmap Button - How to use? Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Bitmap Button - How to use?

Post by dominover »

I'm really new to WxWidgets.. Struggling a bit.
I want to do something very basic. In this case I'm trying to create an event (of which I know how to do) where I click on a wxBitmapButton and the event causes a Bitmap Image to form on the button in place of a label.

Here's the code I've used in the handler. This may look pretty dumb but I really don't know how this should work. The name of the bitmap image file is 'picta'

Which directory should the bitmap go in and is there something else I need to do here? I've put the bitmap image in several
directories with no luck.

Code: Select all

void Project12___bitmap_buttonFrm::WxBitmapButton1Click(wxCommandEvent& event)
{

wxBitmap picta;
WxBitmapButton1->SetBitmapSelected(picta);

}
Thanks very much..
Dominover
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: Bitmap Button - How to use?

Post by dominover »

Has anyone any clue at all as to how this works. I've provided my latest attempt below. Still no luck.
Should I be specifying the file path to the bmp file or maybe I have the bmp file in the wrong directory. Where should it go?
Thanks

Code: Select all

void Project12___bitmap_buttonFrm::WxBitmapButton1Click(wxCommandEvent& event)
{

wxBitmap tester;
tester.LoadFile("picta.bmp", wxBITMAP_TYPE_BMP);
WxBitmapButton1->SetBitmapSelected(tester);


}
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Bitmap Button - How to use?

Post by doublemax »

That code looks ok so far. First you should make sure that the method is actually called. For that purpose i added a wxLogMessage call below. Also, for a test, use an absolute path to the image file (adjust the path to the location on your system).

Code: Select all

void Project12___bitmap_buttonFrm::WxBitmapButton1Click(wxCommandEvent& event)
{
  wxLogMessage( wxT("WxBitmapButton1Click") );

  wxBitmap tester;
  tester.LoadFile("c:\\picta.bmp", wxBITMAP_TYPE_BMP);
  if( !tester.IsOk() ) {
    wxLogMessage( wxT("bitmap could not be loaded") );
  }
  WxBitmapButton1->SetBitmapSelected(tester);
}
Use the source, Luke!
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: Bitmap Button - How to use?

Post by dominover »

Thanks very much for that. I'm getting closer. I keep getting this error message before and after
I added the code you provided. I don't suppose you know what this means. I can't seem to make any sense of it
through a Google search. Provided the error message below. It's probably something I've forgotten to type though it compiles without error. The error comes when I run the binary file.


, ,I, ,/src/msw/dib, cpp( 142): assert "hbmp" Failed in CreateO: wxDIB:: CreateO: invalid bitmal=
Do you want to stop the program?
You can also choose [Cancel] to suppress Further warnings,


The next message, when I hit cancel, says.

'Bitmap Could Not be loaded'..


So, I'm thinking it has something to do with my file path... possibly.




Thanks for your help.
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: Bitmap Button - How to use?

Post by dominover »

Disregard my last.. It works..

Yes, it was my doing. I ended the file name 'picta' with '.bmp' in the directory. So I named it 'picta.bmp' and the file couldn't load. Silly me.

Thanks for your help. For a problem so small this has taken up allot of time but I've learned something here.

Thanks again, I really appreciate the help.

Dominover
Post Reply