help with pictures

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

Previous topic - Next topic

paulDiagnos

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

Haakon Birkeland

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.

Haakon Birkeland

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.

TechSupport

Are you using the "BackBitmap" property of the Form ????? That property should allow you to assign a bitmap to the background of a Form.

Haakon Birkeland

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

TechSupport

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.  :(

Haakon Birkeland

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.

TechSupport

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.

Haakon Birkeland

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?

Haakon Birkeland

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

TechSupport

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  

Haakon Birkeland

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..

TechSupport

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.

paulDiagnos

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

TechSupport

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.