Does not work :(
LoadBitmap( GetResources(), cResName ) returns 0, although the resource exists
FindResource(GetResources(), cResName, 10) > 0
Does not work :(
LoadBitmap( GetResources(), cResName ) returns 0, although the resource exists
FindResource(GetResources(), cResName, 10) > 0
Works fine here, I use it extensively. Please try testres.prg sample.
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?
No, I never used DLL for resources, only RC files. Can you provide a complete little sample of your problem?
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.
I just load testres.dll with BRW32 and resave it, and now it works fine.
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 2007Test / Teste.
Regards, saludos.
Why ?
Perhaps the original DLL was for 16 bit.
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.
Dear Yuri,
Please describe your current situation in detail and explain what do you need help for
thank you
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
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
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() ?
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