PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Connect an Image to the ImageButton  (Read 507 times)

Klaas Holland

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 100
  • FF3 User
Connect an Image to the ImageButton
« on: August 22, 2018, 06:40:26 PM »

I tried to connect an Image to the ImageButton in the Program but it doesn't work.

1. In AppStart :      Common Shared gLogo        as String
2. In WinMain :       gLogo = "Logo-K3H.bmp"
3. In Form1 :           SendMessage (HWND_FORM1_IMAGEBUTTON1, BM_SetImage, Image_Bitmap, gLogo)           

4. Error :   \CODEGEN_KCREDITEURFB_FORM1_FORM.inc(1187) error 57: Type mismatch, at parameter 4 of SENDMESSAGE() in 'SendMessage       (HWND_FORM1_IMAGEBUTTON1, BM_SetImage, Image_Bitmap, gLogo)         

What am I doing wrong?
Logged

Josť Roca

  • FireFly3 Registered User
  • Master Member
  • *
  • Posts: 3109
    • Jos
Re: Connect an Image to the ImageButton
« Reply #1 on: August 22, 2018, 06:56:24 PM »

The last parameter of SendMessge is not the name of a file but the handle of a bitmap. Therefore, you have to load the image usind LoadImage or LoadBitmap to get the handle and pass it to SendMessage.
« Last Edit: August 22, 2018, 07:00:30 PM by Josť Roca »
Logged

Klaas Holland

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 100
  • FF3 User
Re: Connect an Image to the ImageButton
« Reply #2 on: August 23, 2018, 04:46:42 AM »

Sorry Jose, I need an example.

I have not 1/100 of the knowledge you have.
Logged

Marc Pons

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 133
  • FF3 User
Re: Connect an Image to the ImageButton
« Reply #3 on: August 23, 2018, 01:07:05 PM »


c++ example, quite simple to translate
Code: [Select]
int main() {
 
    HANDLE hBitMap = LoadImage(0, "img.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
   
    BITMAP bitmap;
    GetObject(hBitMap,sizeof(BITMAP),&bitmap);
    cout << &bitmap;   
    int size = bitmap.bmHeight*bitmap.bmWidth*bitmap.bmBitsPixel/8;
   
    cout << size;
    BYTE *lpBits = new BYTE[ size ];
   
    GetBitmapBits((HBITMAP)hBitMap,size,lpBits );
   
    delete []lpBits;
   
    system("PAUSE");
    return 0;
}
Logged

Klaas Holland

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 100
  • FF3 User
Re: Connect an Image to the ImageButton
« Reply #4 on: August 23, 2018, 02:24:24 PM »

Sorry Marc, but this does not make sence to me either.

Paul,

Can you make a Function for me that works like:

FF_CONTROL_SETIMAGE ( HWND_FORM1_IMAGEBUTTON1, gLogo )

Thanks in advance
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Connect an Image to the ImageButton
« Reply #5 on: August 23, 2018, 03:59:01 PM »

I am not at my development computer but based on the info you have provided, it should look something like this:

dim hImage, nWidth, nHeight as dword
nWidth = 32: nHeight = 32
hImage = LoadImage(App.Instance, gLogo, %IMAGE_BITMAP, nWidth, nHeight, %LR_LOADFROMFILE)
SendMessage (HWND_FORM1_IMAGEBUTTON1, BM_SetImage, Image_Bitmap, hImage)

Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Connect an Image to the ImageButton
« Reply #6 on: August 23, 2018, 04:01:15 PM »

At some point you will have to DeleteObject(hImage) for the image you load, or if you decide to change the image to a different image.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Klaas Holland

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 100
  • FF3 User
Re: Connect an Image to the ImageButton
« Reply #7 on: August 24, 2018, 06:03:58 AM »

Thanks Paul,

I made a Function of the code and it works Oke.

But the quality of the image is half as good as when I use the Image Library Manager.

Is there a way to improve that?
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Connect an Image to the ImageButton
« Reply #8 on: August 24, 2018, 08:20:38 AM »

Depending on how you used the ImageButton from the Toolbox, you may have used additional window style flags that affected how the image was loaded from the Image Library. Here are some LoadImage flags that could be affecting your image quality:

LR_DEFAULTSIZE
LR_LOADMAP3DCOLORS
LR_LOADTRANSPARENT

Just OR them to your existing flags. For example:
%LR_LOADMAP3DCOLORS Or %LR_LOADFROMFILE

https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-loadimagea
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Klaas Holland

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 100
  • FF3 User
Re: Connect an Image to the ImageButton
« Reply #9 on: August 24, 2018, 12:10:15 PM »

Thanks all,

The nWidth and nHeight must both be set to 0 then the picture shows natural.

Here's the Function:

Function FF_SetImage ( ByVal hControl  as HWnd,  ByRef hLogo  as String ) as String

    Dim hImage   as Long  =  LoadImage (0, hLogo, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)

    SendMessage (hControl, BM_SetImage, Image_Bitmap, hImage)

    DeleteObject (hImage)
   
End Function
Logged