Multiple icons/buttons in a cell

Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am

Re: Multiple icons/buttons in a cell

Post by Natter »

Does not work :(

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

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

User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multiple icons/buttons in a cell

Post by Enrico Maria Giordano »

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

Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am

Re: Multiple icons/buttons in a cell

Post by Natter »

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

Code: Select all | Expand

SET RESOURCES TO "TestRes.dll "

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

User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multiple icons/buttons in a cell

Post by Enrico Maria Giordano »

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

User avatar
karinha
Posts: 8720
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: Multiple icons/buttons in a cell

Post by karinha »

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#8vd5IpUTP ... kBeMBNpfac

Gracias, tks.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multiple icons/buttons in a cell

Post by Enrico Maria Giordano »

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

User avatar
karinha
Posts: 8720
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: Multiple icons/buttons in a cell

Post by karinha »

Enrico Maria Giordano wrote: Thu Apr 30, 2026 4:08 pm

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:

Code: Select all | Expand

   SET MESSAGE OF oWnd TO FWVERSION 2007

Test / Teste.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am

Re: Multiple icons/buttons in a cell

Post by Natter »

Why ?

Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am

Re: Multiple icons/buttons in a cell

Post by Natter »

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.

User avatar
Antonio Linares
Site Admin
Posts: 44515
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Multiple icons/buttons in a cell

Post by Antonio Linares »

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
Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am

Re: Multiple icons/buttons in a cell

Post by Natter »

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

Code: Select all | Expand

#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

Code: Select all | Expand

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

User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multiple icons/buttons in a cell

Post by Enrico Maria Giordano »

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

Natter
Posts: 1402
Joined: Mon May 14, 2007 9:49 am

Re: Multiple icons/buttons in a cell

Post by Natter »

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() ?

User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multiple icons/buttons in a cell

Post by Enrico Maria Giordano »

This is a working sample form Gemini:

Code: Select all | Expand

#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
Post Reply