PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: paulDiagnos on November 01, 2004, 01:48:51 PM

Title: help with pictures
Post by: paulDiagnos on November 01, 2004, 01:48:51 PM
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
Title: help with pictures
Post by: TechSupport on November 01, 2004, 04:33:55 PM
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.
Title: help with pictures
Post by: Haakon Birkeland on November 01, 2004, 05:22:57 PM
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.
Title: help with pictures
Post by: paulDiagnos on November 02, 2004, 05:34:34 AM
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
Title: help with pictures
Post by: TechSupport on November 02, 2004, 07:17:28 PM
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.
Title: help with pictures
Post by: Haakon Birkeland on November 02, 2004, 08:17:23 PM
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..
Title: help with pictures
Post by: TechSupport on November 02, 2004, 09:21:43 PM
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 ?????
Title: help with pictures
Post by: Haakon Birkeland on November 03, 2004, 06:23:22 AM
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..?
Title: help with pictures
Post by: Roger Garstang on November 03, 2004, 07:29:15 PM
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.
Title: help with pictures
Post by: Haakon Birkeland on November 03, 2004, 08:50:53 PM
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..
Title: help with pictures
Post by: TechSupport on November 03, 2004, 09:51:09 PM
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
Title: help with pictures
Post by: Haakon Birkeland on November 04, 2004, 05:24:55 AM
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.   :)
Title: help with pictures
Post by: Roger Garstang on November 04, 2004, 08:58:15 PM
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.
Title: help with pictures
Post by: Roger Garstang on November 06, 2004, 04:21:54 AM
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.
Title: help with pictures
Post by: Roger Garstang on November 13, 2004, 09:32:15 PM
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.
Title: help with pictures
Post by: paulDiagnos on November 19, 2004, 05:53:53 AM
all working wonderfully now

although it is worth a note for any one ..

make sure you add an image to start with, otherwise  bmps with not display

maybe icon is default but not sure

ta PaUL
Title: help with pictures
Post by: Haakon Birkeland on November 19, 2004, 08:28:03 AM
Icon is default for now. But we await an option to choose default resource type in the future. To minimize application footprint you can use a one-pixel image (spacer), as we often "cheat" with on web pages, for the initial resource.
Title: help with pictures
Post by: Haakon Birkeland on December 26, 2004, 04:20:57 PM
Paul, is there a similar limitation, as discussed initialy in this thread, when it comes to putting a bitmap on the form itself?

I have played (researched and read for hours in POFFS) about how to "pick up" a bitmap from a resource file, to limit the size of the executable by reusing a bitmap on several forms. I'm now able to assign the bitmap to a picture control, but I get nowhere if I try to use it as a background picture on the form itself.

Alternatively I have tried to place the "skin" bitmap in a picture control, but the control then always lays itself over the other controls and mess averything up for me. Anyway, I'll prefer/want to use it as a background on the form.
Title: help with pictures
Post by: TechSupport on December 26, 2004, 07:10:49 PM
Are you using the "BackBitmap" property of the Form ????? That property should allow you to assign a bitmap to the background of a Form.
Title: help with pictures
Post by: Haakon Birkeland on December 26, 2004, 08:15:48 PM
Using the BackBitmap property works well, but doesn't do the trick in this case. I'm not using that option due to the fact and desire to use the bitmap on several forms. That would make the executable grow very quickly if appended during design-time. That's why I choose to put it in a resource module and load it when needed. The code, located in WM_CREATE, fails to give me a handle, other than 0, on the part where I "send" the picture to the form;

Dim hBMP As Long
hBMP = LoadImage(GetModuleHandle(ByVal %Null), "BackBitmap", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)

If hBMP Then
Dim RetVal As Long
RetVal = SendMessage(HWND_FRMMAIN, %STM_SETIMAGE, %IMAGE_BITMAP, hBMP)

FF_Control_SetText  (HWND_FRMMAIN, Str$(hBMP) & " - " & Str$(RetVal)) 'DEBUG
End If
Title: help with pictures
Post by: TechSupport on December 26, 2004, 09:02:36 PM
Ah, I see what you mean. I expect that maube you can use the FireFly generated code and add the LR_SHARED flag during the LoadImage. I believe that Roger uses this approach a lot.

I am not around my development computer so I can't test any of this for you right now.  :(
Title: help with pictures
Post by: Haakon Birkeland on December 27, 2004, 06:53:47 AM
Actually I don't mind very much getting a new handle when I need to use the picture again. I'm assigned a handle from the LoadImage function, but not from the SendMessage function, when the target is the form itself.

If a picturebox is the target, the bitmap shows up. But when the form is the target, a zero (failed) is returned through the handle every time, and thus no picture shows up in the background. I fail to see how the shared equate would resolve that issue.
Title: help with pictures
Post by: TechSupport on December 27, 2004, 09:41:26 AM
Setting an image for the Form is much different then setting the image of a Picture control. You should create a sample program that uses the "BackImage" property and then examine the generated code. You will see that the image is created in WM_CREATE and assigned/re-sized in %WM_ERASEBKGND. Finally, the handle is destroyed in WM_DESTROY.

The Form and Picture Control are not the same class, so you can not simply use the SendMessage to assign a bitmap.
Title: help with pictures
Post by: Haakon Birkeland on December 27, 2004, 10:26:40 AM
No wonder I keep "hating" SDK-development. Presumable easy tasks end up beeing really nothing near easy for a novice. It's often both hard to understand and tedious to do, requiring hours of somewhat "fruitless" research/reading, increasing both stress and frustration. I begin to see how skilled a person you really have become Paul. Maybe at some point I will look back and frown at my current ignorance, if I'm not to give up meanwhile..

I never thought of examing the code created by FF. Normally I just have it deleted after compilation. I do recognize some of the code from the time spent reading through POFFS.

How would I go about placing code in the %WM_ERASEBKGND, without messing around in the generated code? Cause I can't see any "event" in the "event list". Could/should I use the Custom "event" function to sniff for the correct message and strut my stuff then and there?!

BTW: How come the optional way of achiveing the "same" result, using a picture control, messes up the Z-order(?) of the controls, making most of the controls actually over/above the picture control in design-time beeing hidden/unavailable at run-time?
Title: help with pictures
Post by: Haakon Birkeland on December 27, 2004, 02:30:16 PM
Now I get a handle for both hResBMP and hDC, and StretchBlt returns 1. But still the form stays mono-colored.. - nothing is drawn. Where did I go wrong? I can't seem to spot anything suspicious other than hBM not beeing assigned anything, (not in the FF created code either) although it's used in the SizeOf function.


Function FRMMAIN_WM_CREATE (hWndForm As Dword) As Long

Global FrmRect As Rect 'Rectangle structure for the form
Global hResBMP As Long 'Handle for the RESource BitMapped Picture

   If hResBMP Then DeleteObject hResBMP   'Delete system resources related to the resource bitmap
   GetClientRect HWND_FRMMAIN, FrmRect 'Put the rectangle structure for the form into the structure

   'Load the bitmap from the resource, and keep it's handle
    hResBMP = LoadImage(GetModuleHandle(ByVal %Null), "BackBitmap", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE + %LR_SHARED)

End Function

Function FRMMAIN_CUSTOM ( hWndForm  As Dword, _  ' handle of Form
                         wMsg      As Long,  _  ' type of message
                         wParam    As Dword, _  ' first message parameter
                         lParam    As Long   _  ' second message parameter
                        ) As Long

If wMsg = %WM_ERASEBKGND Then

  Dim hBM As BITMAP 'When is this actually assigned something?
  Dim hDC As Long   'Handle for the Device Context

  If GetStretchBltMode(wParam) <> %STRETCH_DELETESCANS Then SetStretchBltMode(wParam, %STRETCH_DELETESCANS)
 
    GetObject hResBMP, SizeOf(hBM), hBM 'How does hBM resolve to size of anything? Nothing is assigned..
    hDC = CreateCompatibleDC(wParam)    'Create a compatible Device Context
        SelectObject hDC, hResBMP  'Replace the object in the Device Context
   
        GetClientRect HWND_FRMMAIN, FrmRect 'Put the rectangle structure for the form into the structure

     Dim RetVal As Long     'Below: Copy the bitmap from the DC to the form
        RetVal = StretchBlt wParam, 0, 0, FrmRect.nRight, FrmRect.nBottom, hDC, 0, 0, hBM.bmWidth, hBM.bmHeight, %SRCCOPY
 
    DeleteDC hDC       'Delete the Device Context

 'Put some DEBUG info in the forms titlebar
  If RetVal Then FF_Control_SetText(HWND_FRMMAIN, Str$(hResBMP) & " " & Str$(hDC) & " " & Str$(RetVal)) 'DEBUG
End If
End Function


Function FRMMAIN_WM_DESTROY ( _
                           hWndForm      As Dword _  ' handle of Form
                           ) As Long
                           
DeleteObject hResBMP
End Function
Title: help with pictures
Post by: TechSupport on December 27, 2004, 02:44:05 PM
I would assume that because you are handling the background erase yourself that you will need to return true after processing the message. If you do not, then Windows will process the background erase essentially erasing your bitmap that you just placed on the Form.  :)


  If wMsg = %WM_ERASEBKGND Then
 
     Dim hBM As BITMAP 'When is this actually assigned something?
     Dim hDC As Long   'Handle for the Device Context
       
        If GetStretchBltMode(wParam) <> %STRETCH_DELETESCANS Then SetStretchBltMode(wParam, %STRETCH_DELETESCANS)
       
        GetObject hResBMP, SizeOf(hBM), hBM 'How does hBM resolve to size of anything? Nothing is assigned..
        hDC = CreateCompatibleDC(wParam)    'Create a compatible Device Context
        SelectObject hDC, hResBMP           'Replace the object in the Device Context
     
        GetClientRect HWND_FRMMAIN, FrmRect 'Put the rectangle structure for the form into the structure
     
        Dim RetVal As Long                  'Below: Copy the bitmap from the DC to the form
         RetVal = StretchBlt wParam, 0, 0, FrmRect.nRight, FrmRect.nBottom, hDC, 0, 0, hBM.bmWidth, hBM.bmHeight, %SRCCOPY
       
        DeleteDC hDC                         'Delete the Device Context
 
       'Put some DEBUG info in the forms titlebar
        If RetVal Then FF_Control_SetText(HWND_FRMMAIN, Str$(hResBMP) & " " & Str$(hDC) & " " & Str$(RetVal)) 'DEBUG

     FUNCTION = %TRUE:  EXIT FUNCTION  '<---- TRY ADDING THIS !!!!!!
  End If  
Title: help with pictures
Post by: Haakon Birkeland on December 27, 2004, 03:39:56 PM
Aahh(rg).. So that's why that line was in FF's generated code. I couldn't quite see what it did, so I left it out.  :oops:  Now it's up and running as expected and hoped. - Thank you for pushing me to mange this, I've slightly contributed and learned a lot!  :)

I still wonder though, why the picture control I tried to use instead, ended up covering most of the other controls..
Title: help with pictures
Post by: TechSupport on December 27, 2004, 10:27:29 PM
Quote from: Haakon BirkelandI still wonder though, why the picture control I tried to use instead, ended up covering most of the other controls..

I would assume that it was created higher in the z-order thereby covering some controls. A lot depends on the order that the controls are created. You can move the controls afterwards using SetWindowPos API.
Title: help with pictures
Post by: paulDiagnos on January 11, 2005, 07:58:52 AM
right used the code that was shown to me in this link,

i put the bitmap as default and can change the pictures via button presses ect


but!!!!! when using the FF code on an xp machine the image will not display:-(

can you tell me why
Title: help with pictures
Post by: TechSupport on January 11, 2005, 08:32:08 AM
Quote from: paulDiagnosbut!!!!! when using the FF code on an xp machine the image will not display:-(
can you tell me why

Can you email me a small FireFly project that demonstrates this? I will trace through the code on various operating systems to see if maybe there is a Style or something that may be causing a problem.
Title: help with pictures
Post by: paulDiagnos on January 11, 2005, 09:22:36 AM
ok will do

just ave me lunch first :-)
Title: help with pictures
Post by: paulDiagnos on January 13, 2005, 11:36:48 AM
ok i have the answer,

You have to be care ful with the bitmaps you try and switch. if you are on xp and you use xp created bitmaps it will be fine,,,

looking at headers of the bitmaps (which is what my projects is currently about), you have to have an XP compatible one.

have no i dea why this should effect anything as bitmaps are usually backwards and forwards compatible (ithink ) but there we go


thanks for looking into it i have a habit of answering my own questions

Paul
Title: help with pictures
Post by: TechSupport on January 13, 2005, 01:22:05 PM
Well that is very interesting. I was wondering why the bitmap that you emailed me would not work while other bitmaps on my computer worked with no problems.

Happy to hear that the problem is solved. That's one less thing for me to worry about. :D