May 20, 2024, 07:18:27 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Bitmap button using resource?

Started by barry, December 05, 2006, 08:00:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

barry

Is it possible to create a bitmap button using a resource?  I finally got it working with a bitmap file but I want to put it in a project and include the resource in the executable to have a single file program.  I don't see any provision for doing that.

Any tips will be appreciated.

Barry

Zen

Barry. Load your bitmap resource and obvisouly create your button as a bitmpa button. Then on your @INITDIALOG message use sendmessage to set the image on the button.

MSDN Documentation (BM_SETIMAGE)

Lewis

Ionic Wind Support Team

Just save the bitmap in resources with a text ID.  Like "BITMAP_1".  Make sure your using the bitmap style on the button and then:

SetControlText win, id, "BITMAP_1"

Will do it.

Ionic Wind Support Team

barry

Okay but how do I get the resourceID of the image?

Barry

barry

Where do I give the bitmap a textID?

Barry

Ionic Wind Support Team

Create a project, add your source file, select the resource menu and choose "add".

You will see the resource dialog come up.  The ID is the first text box, click the "choose" button and select your bitmap.

Read the users guide on using projects.  The only big difference is you need to tell the compiler where execution should start in your program, in other words which file contains the beginning of code.  Because you can have 100's of source files.

That is done by simply using the $main preprocessor command.  Even if you only have one source file in the project.

Paul.
Ionic Wind Support Team

barry

I've done all that, including reading the resource section.

I think the problem I'm having is that the ID I give the image is a numeric ID and not a string.  It all compiles correctly but I don't see the bitmap.

Before when I was loading the bitmap from a file it all worked correctly but I want a single file program so I created the project.

Barry

Ionic Wind Support Team

Where are you using SETCONTROLTEXT?

If it is a dialog it should be in response to @IDINITDIALOG

You can use numeric ID's too.  Don't include the quotes in the resource dialog though, forgot to mention that.  If you have an ID of 30 then then the command would be:

SETCONTROLTEXT win, control_id, "30"

For an example this is the handler for the About dialog of the menu editor:


SUB about_handler
POINTER pWnd
pWnd = @HITWINDOW
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW #<WINDOW>pWnd
SETCONTROLTEXT #<WINDOW>pWnd,2,"30"
SETFOCUS #<WINDOW>pWnd,1
CASE @IDCONTROL
IF @CONTROLID = 1 AND @NOTIFYCODE = 0 THEN CLOSEDIALOG #<WINDOW>pWnd,@IDOK
CASE @IDCLOSEWINDOW
CLOSEDIALOG #<WINDOW>pWnd,@IDOK
ENDSELECT
RETURN
ENDSUB
Ionic Wind Support Team

barry

It's in a window and I'm doing it shortly after opening the window and right after creating the control.  I'm not doing it in the handler routine, but in the initialization routine.  That worked fine when it was being loaded from a file.

I have several buttons and I'm just changing one at the moment and the others are still loading from files and still working just fine.

Barry

Ionic Wind Support Team

It does work, just did it here myself with an ID of 30 and with an ID of BITMAP_1.  Make sure you are actually using a type of "BITMAP" in the resource dialog.

On another note:  If your using numeric ID's don't use an id higher than 32766 as it won't work.  ID's above that are reserved by Windows ;)

And one other comment...you had problems with a path in your documents directory if I remember correctly.  On the odd chance that the resource compiler doesn't like that path try changing everything to c:\test just for diagnostic purposes.

I've never had a problem myself with any location that I've stored a project.  But you never know.

If all else fails feel free ot send me your project zipped up and I will correct it for you this afternoon when I get back from some running I have to do.

Paul.

Ionic Wind Support Team

barry

I just did a showimage in an unused part of the window to be sure it's loading okay and it is so it's not the path.

I'll just keep playing with it till I get it.  I'll learn more that way than if you do it for me, but thanks.  You already know how. :)

This is my first real attempt at projects.  I tried them once in IBPro but found them problematic and I didn't really need them anyway.  But this time I've decided to get there.

Barry

barry

Okay I got it working but now I'm more confused than ever.

What I was doing was using a constant value to symbolically represent the ID.  When I changed that to the ID number itself (or maybe it's a numeric string) it worked.  The reason that's confusing is that I had previously tried to use a string instead of a number as the ID but that didn't work.

Also the symbolic constant works fine in LOADIMAGE, indicating that the ID is a number after all.  Is there magic involved here or am I missing something?

Is the ID actually a number or a string or sometimes one and sometimes the other?  Or does SETCONTROLTEXT turn the number into a string for me?  What is going on?   Do I need garlic? :)

Barry

Ionic Wind Support Team

The add resouce dialog knows nothing about the constants you may define in your source, so you have to put the actual numeric identifier in the numeric ID box.

SetControlText works because it sends a WM_SETTEXT message to the control which intercepts the message for a bitmap button and tries to determine what you want.

SetControlText win, control_id, "30"

The 30 gets converted to an actual number to reference the resource identifer.
Ionic Wind Support Team

barry

Okay I think I see now.

Thanks,
Barry

barry

I just realized that that probably explains why the symbolic constant wont work.  The compiler treats that as a string, probably.  So am I forced to use numbers there instead of something symbolic?  Not a problem with the little stuff I'm likely to do but for anyone writing something larger it might be.

Barry

Ionic Wind Support Team

Just use STR$

SetControlText win, control_id, STR$(IMG_BITMAP_1)

Which will convert the constant to a string representation of the number and match the ID you have in the resource dialog.   I suppose if it is a big problem for you I can throw in another command like LoadButtonResource.

Ionic Wind Support Team

barry

Okay.  Little by little.  I really should have thought of that.  Thank you.

Barry

mrainey

I was fighting the same "no image" thing until I remembered to add the @CTLBTNBITMAP flag to the control definition.  The following lines worked together for me to get it done (in a window).  The resource ID was 1001, type Bitmap.


Def ImageName:UInt

ImageName = LoadImage (1001,@IMGBITMAP)

Control MainWin,@Button,"",100,100,130,46,@CTLBTNBITMAP,1

SetControlText MainWin,1,"1001"
Software For Metalworking
http://closetolerancesoftware.com