help with pictures

Started by paulDiagnos, November 01, 2004, 01:48:51 PM

Previous topic - Next topic

paulDiagnos

It may be my lack of knowlage of pwer basic, if it is then i am sorry...

but how do i change pictures during the program

e.g. push a button, new piccy shows in the picture box


can you give me a gentle yet firm push in the right direction

thanks Paul

TechSupport

Hi Paul,

FireFly uses the standard Win32 "Static" control to display icons and bitmaps.

In order to change the icon/bitmap during runtime you can use several approaches:

(1) If you only have a few pictures to display, then create a separate Picture control for each one. You can initially uncheck the WindowStyle property "WS_VISIBLE" for the controls that you do not want to show and then use FF_CONTROL_SHOWSTATE when you want to show/hide subsequent controls.

(2) If your icons/bitmaps are coming from a disk file then you will need to use the Win32 API function, LoadImage.

(3) You can add the images to the Project's Resource file and load them from there during runtime.

How is your program set up? Let me know the logic of what it is you are doing and I'm sure that myself or someone else here can give you exact instructions.

Haakon Birkeland

I actually intended to "take this one", although I've never tried it in PB. I thought I basically had it figured out. Load the the bitmap, and toss it over to the control.. Two simple steps I figured. Not so - easy.

Initially I'd be happy just to know the steps that I would have to include in the latter part, and then figure it out on my own. Cause it's surely a task when the only previous experience comes from VB's built-in function. ..so far the form background and the picture control I've played with doesn't change, and BitBlt seems to fail me. That is, if the first part is good.. It seems to contain a handle, as far as I understand.

Dim ImageHandle As Long
ImageHandle = LoadImage(%Null, "c:\picture.bmp", %IMAGE_BITMAP, %Null, %Null, %LR_LOADFROMFILE)

Gonna download the recommended API help file, cause my API viewer 2004 and the current help file declaration seem to differ a bit.

paulDiagnos

Thanks for your quick repsonse,

The idea of what im doing is kind of a sample view...

To click on an item in a listView, and the image appears as a little sample in a picture box.

thbere will be many unknown images :-( so this means the second option seems best,  as the files will be uploaded via serial in another part of the program


hope this is clear

Paul

TechSupport

If the images are unknow until runtime then you can use the approach that Haakon suggests:

Local ImageHandle As Long

'If the control already has a picture then delete it.
ImageHandle = SendMessage( HWND_FORM1_PICTURE1, %STM_GETIMAGE, %IMAGE_BITMAP, 0)
If ImageHandle Then DeleteObject ImageHandle

'Load the new image
ImageHandle = LoadImage(%Null, "print.bmp", %IMAGE_BITMAP, %Null, %Null, %LR_LOADFROMFILE)

'Assign the image to the control
SendMessage HWND_FORM1_PICTURE1, %STM_SETIMAGE, %IMAGE_BITMAP, ImageHandle



You should read up on the LoadImage API command because there are several flags that you use with it.

Haakon Birkeland

I knew (assumed) it was that "simple". But I wouldn't have guessed that SendMessage was the key to doing the last part. That's why I played around with BitBlt and other functions. Seems like SendMessage is quite much more universal and powerful than I anticipated..

A few lines and there yeah go.. That is, when it's nice to you. It ain't to me. The SendMessage fails for some reason, although the LoadImage gives me a handle to pass. Beats me what's wrong, cause I can't see any mistakes. But as long as I get that %NULL returned, nothing is going to happen, I get that..

TechSupport

Quote from: Haakon BirkelandThe SendMessage fails for some reason, although the LoadImage gives me a handle to pass. Beats me what's wrong, cause I can't see any mistakes. But as long as I get that %NULL returned, nothing is going to happen, I get that..
It worked fine for me. I tested it before I posted the example.

Was the Picture control that you initially created set up for a BITMAP. If you set it up initially with an ICON then maybe that is the problem ?????

Haakon Birkeland

Do you mean the Icon/Bitmap property in the WindowStyles|Style? Cause that is checked and disabled. - Can't change it. But it seems you are (off course) completely right about the icon vs bitmap thing, cause if the picture control already contains a bitmap (from design time), it's working as expected and exchanges it with the bitmap loaded from file. Does it have to be set from code what kind of bitmap it should accept, through a SendMessage perhaps..?

Roger Garstang

I had this same problem a while back with my Web Server and suggested that Paul allow the check for icon/bitmap.  The way he currently has it the type is set when you load the image in the IDE.  To get it to work yourself you have to edit the generated code and add the icon or bitmap style yourself if you don't set the image.  I ended up setting the image for one and dealing with the goofy name FF creates for it in the resource and then switching it back and forth myself with the icon I manually added to a resource file.

Haakon Birkeland

Ok, let's say I'd like to make some kind of print out with the option to add a logo or something. Then I wouldn't start of by placing any bitmap in the control, but rather leave it empty until it's needed and thus saving some overhead in the compiled application. But as I understand you, it's not doable without fuzzing around in the code files FF generates?! I have had FF deleting those files since the beginning. I really don't think I have any business messing around there with my current SDK skill-level.

Actually I've never understood why the WindowStyles have to differ from the way the other properties are handled. I'd prefer to see them alongside the rest. It's a better way to "memorize" and get acustomed to them. Actually I'd be fine if they all had "normal" names as well, but I guess it's this way for a reason..

TechSupport

Quote from: Haakon BirkelandOk, let's say I'd like to make some kind of print out with the option to add a logo or something. Then I wouldn't start of by placing any bitmap in the control, but rather leave it empty until it's needed and thus saving some overhead in the compiled application. But as I understand you, it's not doable without fuzzing around in the code files FF generates?! I have had FF deleting those files since the beginning. I really don't think I have any business messing around there with my current SDK skill-level.
As Roger points out, he suggested an option to leave it in the hands of the user to decide whether a picture should be an icon or bitmap. Basically, the user would set a property at design time specifying whether it is an icon or bitmap that will be loaded into the control later during run-time. I fully appreciate the benefits of that approach. Someday I hope to get the change into FireFly.....  ;)

QuoteActually I've never understood why the WindowStyles have to differ from the way the other properties are handled. I'd prefer to see them alongside the rest. It's a better way to "memorize" and get acustomed to them. Actually I'd be fine if they all had "normal" names as well, but I guess it's this way for a reason..
WindowStyles are basically the equates that used during a CreateWindowsEX API call. That call is what actually creates the Windows controls at runtime. For users with SDK and DDT experience, these equates are not  foreign to them at all.  For users coming directly over from Visual Basic - it can be mind boggling. I hope to add a way that a description will show when you click on a WindowStyle. At least that will give you a bit of help.

.... you can also download and browse through the Win32 API Help file. It is not as hard as most people make it out to be. I came from a Visual Basic background and I was able to follow it.  Haakon, you're certainly as capable as I am. :D

Haakon Birkeland

How would we, without messing around in the generated code, be able to leave the picture control empty and then fill it as needed with a run-time bitmap. Should I examine a particular API call? A brief hint on where to look would be appreciated.

What's the standard for the control now? - None? Is it not decided until a icon of bitmap is loaded in the IDE? How about making it default to bitmap (mostly used I suppose), and having an additional picture control for icons, with default size 32x32 and initial 'support' for transparency..

As for the WindowStyles they mostly (or all) seem to be ON/OFF items, and I guess they could be presented like the 'boolean' properties like fx. AutoSize. And frankly, all caps equations makes it 'hard'(er) to read. PB forms also seems to favour the caps and odd way of presenting them alongside the properties. Not my favourite..

Your'e right that the API (functions) ain't always that hard to figure out , but sometimes it's not clear what steps has to be involved to achieve a certain thing. Then the lack of experience sometimes makes it a huge challenge. Not to mention the need for specific knowledge of the inner workings of Windows - totally screened away in VB.

..and no, I'm most certainly not as capable in PB/SDK as you ((yet)). Ad that's why I normally shut mu trap when people needs tech/SDK advice here and in the PB forum.
Your products and apparent understanding of SDK proves that you're way ahead of me. I envy you skills there Paul. I have my strong sides, I'm making a decent living, but I would starve at this point if PB was my only tool/skill.

..hey, this wasn't even 'my' thread! Must be the jolly happy mood from all the relaxing Xbox'ing yesterday.   :)

Roger Garstang

Paul,

How come the options are even there anyway if they can't be changed?  Are they still read at compile time to set the styles?  I don't see why they couldn't just be enable and still let the selection of an icon or bitmap set them, but still give the user the option to change, or maybe only disabled if they have a picture selected, and if no picture is selected enabled with neither selected to allow the user to decide as with the other styles of the control..or even default to icon since most would be that...but still have it enabled to change it.  The Radio Buttons are a good idea too.

No big rush as I'm pretty happy with everything so far.  It is just that I imagine most people will use that control to display their own images which would be multiple images they load and like mentioned here maybe they want no image there to start, etc.  Right now the only option to allow no picture is setting it to a transparent image or setting the icon/bitmap style of the control with api calls (SetWindowLong, GetWindowLong- To get current value) in WM_CREATE if editing the code isn't an option.

Other things I mentioned at the same time as this before was a way to edit the Resource names and whether they use ID #s or String names.  And with this things like an imagelist control and other things could be created.  Also, using my example from the Listbox Drive list you could make not only it, but an option for the imagelist control to be the system list and FF_Functions to get the index of icons for drives/files/folders.  That is why the Listbox example was so big as well was for future additions to work with any imagelist the user makes or FF creates/uses.

Roger Garstang

Also, while we are on this, can we change the way FF generates code that gets the size of the control with GetClientRect hWndControl, FF_RECT and sets the width and height of the image with FF_RECT.nRight, FF_RECT.nBottom.  Maybe make it an option to stretch the image to the size of the control or set the height and width manually.

%LR_LOADMAP3DCOLORS would need to be an option too as not everyone will want to map the 3D Colors of their images to the current system 3D colors.

Roger Garstang

One more thing that could even be done now before any changes is to add .ani files to the type of image and make them the icon style so we can put animated icons there.