FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Multiple icons/buttons in a cell
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 10:02 AM

Does not work :(

LoadBitmap( GetResources(), cResName ) returns 0, although the resource exists

FindResource(GetResources(), cResName, 10) > 0

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 10:15 AM

Works fine here, I use it extensively. Please try testres.prg sample.

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 10:54 AM

I looked at it. In this example, the resource dll is loaded

SET RESOURCES TO "TestRes.dll "

I have a resource located in .RC the file. Maybe that's the reason?

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 02:25 PM

No, I never used DLL for resources, only RC files. Can you provide a complete little sample of your problem?

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 03:36 PM

FWH26.03 - XHARBOUR y BCC77.

Enrico, por favor, intenta averiguar cuál es el problema en estos ejemplos de TESTRES.PRG: Si uso TESTRES.DLL, el sistema falla. Si uso TESTRES.RES, funciona. Además, ten en cuenta que los colores de la barra de herramientas (obar) no funcionan con el comando 2007.

Enrico, please see if you can figure out what the problem is in these TESTRES.PRG examples: If I use TESTRES.DLL, the system crashes. If I use TESTRES.RES it works. Also, note that the colors in the TOOLBAR (obar) don't work with the 2007 command.

Download completo con .DLL(32 bits), .RC, .RES.

https://mega.nz/file/VE1QXZJT#8vd5IpUTPk6_MXiFIBRng1ozgN4KFwOMMkBeMBNpfac

Gracias, tks.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 04:08 PM

I just load testres.dll with BRW32 and resave it, and now it works fine.

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 04:40 PM
Enrico Maria Giordano wrote:

I just load testres.dll with BRW32 and resave it, and now it works fine.

Modify TESTRES.PRG as follows:

Modifique TESTRES.PRG de la siguiente manera:

   SET MESSAGE OF oWnd TO FWVERSION 2007

Test / Teste.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 06:39 PM

Why ?

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 07:29 PM

Perhaps the original DLL was for 16 bit.

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Multiple icons/buttons in a cell
Posted: Thu Apr 30, 2026 08:31 PM

Sorry, I didn't understand anything! :(
What does the DLL have to do with it ? We are talking about png images (40x40).In the file. I need to show these pictures in the xBrowse cell.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Multiple icons/buttons in a cell
Posted: Fri May 01, 2026 07:37 AM

Dear Yuri,

Please describe your current situation in detail and explain what do you need help for

thank you

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Multiple icons/buttons in a cell
Posted: Fri May 01, 2026 02:39 PM

I need to get a handle icon from a resource. However, this cannot be done. Here is a simple example

#include "FiveWin.ch"

function Main
local  hRes:=GetResources()

? "p_s1", LoadBitmap(hRes, "p_s1"), FindResource(hRes, "p_s1", 10)
? "p_s2", LoadBitmap(hRes, "p_s2"), FindResource(hRes, "p_s2", 10)
return nil

.RC file

p_s1 RCDATA "s_1.png"
p_s2 RCDATA "s_2.png"

S_1.png https://cloud.mail.ru/public/68qu/hqtdcX4A2
S_2.png https://cloud.mail.ru/public/sHiF/UhrnWpSz9

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Multiple icons/buttons in a cell
Posted: Fri May 01, 2026 03:12 PM

That explains your problem: RCDATA is not compatible with LoadBitmap(). You can convert your PNG to BMP or use the GDI+ functions. Try this:

#include "FiveWin.ch"

function Main
local hRes:=GetResources()

? "p_s1", GDIP_FROMRESOURCE( hRes, "p_s1", 10, .T. ), FindResource(hRes, "p_s1", 10)
? "p_s2", GDIP_FROMRESOURCE( hRes, "p_s2", 10, .T. ), FindResource(hRes, "p_s2", 10)
return nil

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Multiple icons/buttons in a cell
Posted: Fri May 01, 2026 03:59 PM

Yes, it works with BMP format, thank you!

GDIP_FROMRESOURCE( hRes, "p_s1", 10, .T. ) ->0

hBMP:=GDIP_FROMRESOURCE( hRes, "b_s1" ) -> 0x24320 valtype(hBMP)->P Do I need to convert this value to decimal in order to use it in PalBMPDraw() ?

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Multiple icons/buttons in a cell
Posted: Fri May 01, 2026 04:23 PM

This is a working sample form Gemini:

#include "FiveWin.ch"

//----------------------------------------------------------------------------//
// HARBOUR SIDE
//----------------------------------------------------------------------------//

function Main()
   local oDlg, oFont
   local hRes := GetResources()
   local hBmp := 0

   // Initialize GDI+ engine
   GDIPLUSSTARTUP()

   // Load PNG from Resources and convert it to a standard GDI HBITMAP
   // "MIO_PNG" must be defined in your .RC file as RCDATA
   hBmp := FW_PNGTOHBMP( hRes, "MIO_PNG" )

   if Empty( hBmp )
      MsgStop( "Resource 'MIO_PNG' not found!" + CRLF + ;
               "Please check your .RC file and ensure it contains:" + CRLF + ;
               "MIO_PNG RCDATA 'your_image.png'" )
      GDIPLUSSHUTDOWN()
      return nil
   endif

   DEFINE FONT oFont NAME "Verdana" SIZE 0, -14
   

   DEFINE DIALOG oDlg TITLE "PNG Background via GDI+ Flat API" SIZE 600, 450

   // Use bPainted to draw the background image
   oDlg:bPainted := { | hDC | DrawBackground( hDC, oDlg, hBmp ) }

   @ 20, 20 SAY "PNG Background loaded successfully" OF oDlg ;
            PIXEL FONT oFont TRANSPARENT SIZE 250, 20
   

   @ 190, 250 BUTTON "&Close" SIZE 45, 13 OF oDlg PIXEL ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

   // Cleanup GDI objects
   DeleteObject( hBmp )
   oFont:End()
   

   // Shutdown GDI+ engine
   GDIPLUSSHUTDOWN()

return nil

//----------------------------------------------------------------------------//

static function DrawBackground( hDC, oDlg, hBmp )
   local aRect := GetClientRect( oDlg:hWnd )
   

   // DrawBitmap automatically scales the image to fit the Dialog dimensions
   DrawBitmap( hDC, hBmp, 0, 0, aRect[ 4 ], aRect[ 3 ] )
   

return nil

//----------------------------------------------------------------------------//
// C SIDE (GDI+ Flat API Wrapper)
//----------------------------------------------------------------------------//

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

// Directives for MSVC Linker
#pragma comment( lib, "gdiplus.lib" )
#pragma comment( lib, "ole32.lib" )

typedef void* GpBitmap;
typedef int GpStatus;

// Manually defining GDI+ Flat API prototypes to avoid C++ header conflicts (namespace errors)
#ifdef __cplusplus
extern "C" {
#endif
   // Use __stdcall for 32-bit compatibility (fixes LNK2019 errors)
   int __stdcall GdipCreateBitmapFromStream(IStream* stream, GpBitmap **bitmap);
   int __stdcall GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, HBITMAP* hbmReturn, COLORREF background);
   int __stdcall GdipDisposeImage(GpBitmap* image);
#ifdef __cplusplus
}
#endif

HB_FUNC( FW_PNGTOHBMP )
{
   // Parameters: 1 = hInstance, 2 = Resource Name, 3 = Resource Type (optional, default RCDATA)
   HMODULE hInst   = ( HMODULE ) hb_parptr( 1 ); 
   LPCTSTR pName   = ( LPCTSTR ) hb_parc( 2 );
   LPCTSTR pType   = ( hb_pcount() > 2 ) ? MAKEINTRESOURCE( hb_parni( 3 ) ) : RT_RCDATA;

   HBITMAP hBmpResult = NULL;
   HRSRC hResource    = FindResource( hInst, pName, pType );

   if ( hResource )
   {
      DWORD dwSize     = SizeofResource( hInst, hResource );
      HGLOBAL hResData = LoadResource( hInst, hResource );
      

  if ( dwSize > 0 && hResData )
  {
     void const * lpData = LockResource( hResData );
     HGLOBAL hgImage     = GlobalAlloc( GMEM_MOVEABLE, dwSize );
     
     if ( hgImage )
     {
        void * pBuffer = GlobalLock( hgImage );
        if ( pBuffer )
        {
           CopyMemory( pBuffer, lpData, dwSize );
           GlobalUnlock( hgImage );

           IStream * pStream = NULL;
           // Create a COM stream on the allocated memory
           if ( CreateStreamOnHGlobal( hgImage, TRUE, &pStream ) == S_OK )
           {
              GpBitmap * pBitmap = NULL;

              // Load the PNG into GDI+ Bitmap object (requires GDI+ initialized)
              if ( GdipCreateBitmapFromStream( pStream, &pBitmap ) == 0 )
              {
                 // Convert GDI+ Bitmap to a standard GDI HBITMAP.
                 // We use COLOR_BTNFACE to blend PNG transparency with the default dialog color.
                 GdipCreateHBITMAPFromBitmap( pBitmap, &hBmpResult, GetSysColor( COLOR_BTNFACE ) );
                 
                 // Cleanup GDI+ object
                 GdipDisposeImage( pBitmap );
              }
              
              // Release COM stream
              pStream->lpVtbl->Release( pStream );
           }
           else
           {
              GlobalFree( hgImage );
           }
        }
     }
  }
   }

   // Return the HBITMAP handle (handles both 32-bit and 64-bit architectures)
   #ifdef _WIN64
      hb_retnll( ( LONGLONG ) hBmpResult );
   #else
      hb_retnl( ( LONG ) hBmpResult );
   #endif
}

#pragma ENDDUMP