Sample:
Readme RCDATA readme.txt
My question is how to get the contents of this file within my program (HMG)?

Moderator: Rathinagiri
Dear Toledopctoledo wrote:Friends in files RC (Resource) you can include a file TXT using the parameter RCDATA (binary data).
Sample:
Readme RCDATA readme.txt
My question is how to get the contents of this file within my program (HMG)?
Hi,pctoledo wrote:Friends in files RC (Resource) you can include a file TXT using the parameter RCDATA (binary data).
Sample:
Readme RCDATA readme.txt
My question is how to get the contents of this file within my program (HMG)?
Code: Select all
/*-----------------------------------------------------------------*/
// PalyWavRc() funciona con recursos identificados con ID numerica
// ej:
// archivo rc. bcxwav.txt es un archivo ascii creado con bin2txt.exe desde un archivo .wav
// usar corchetes para compilar con minGW.
// 12345 RCDATA
// {
// #include "bcxwav.txt"
// }
// la llamada a la funcion es:
// PlayWaveRc( 12345 )
/*-----------------------------------------------------------------*/
HB_FUNC( PLAYWAVERC ) // resource id -> NIL
{
static HRSRC hr;
static HGLOBAL hg;
static LPVOID lpSndData;
memset( &hr, 0, sizeof( hr ) );
memset( &hg, 0, sizeof( hg ) );
memset( &lpSndData, 0, sizeof( lpSndData ) );
hr = FindResource( NULL, MAKEINTRESOURCE( hb_parni( 1 ) ), RT_RCDATA );
if( ! ( hr == 0 ) )
{
hg = LoadResource( NULL, hr );
if( ! ( hg == 0 ) )
{
lpSndData = LockResource( hg );
if( ! ( lpSndData == 0 ) )
{
hb_retl( PlaySound( ( AU_LPCSTR ) lpSndData, ( HMODULE ) 0, ( DWORD ) SND_MEMORY ) );
}
}
}
}
Code: Select all
#Include <hmg.ch>
Function Main()
Local cFileRes:=ResToFile("README")
MsgInfo(cFileRes)
Return Nil
#pragma BEGINDUMP
#include <Windows.h>
#include <hbApi.h>
HB_FUNC( RESTOFILE )
{
static HRSRC hr;
static HGLOBAL hg;
hr = FindResource( NULL, (LPSTR) hb_parc( 1 ), RT_RCDATA );
if( ! ( hr == 0 ) )
{
hg = LoadResource( NULL, hr );
if( ! ( hg == 0 ) )
{
char *lpRcData=( char *)LockResource( hg );
hb_retc( lpRcData );
}
}
}
#pragma ENDDUMP
Dear Esgici,esgici wrote:Dear Toledo
In order to produce a reliable / applicable answer to your question, please inform us about "binary rcData"; what is it, how produce it, how use it in other than HMG ?
http://www.pctoledo.com.br/forum/viewto ... 272#p86271Claudio Soto wrote:Hola Toledo,
en la siguiente versión de HMG voy a incluir la siguiente función:
Su uso sería:Code: Select all
// HMG_LoadResourceRawFile ( cFileName, cTypeResource | nTypeResourceID ) HB_FUNC ( HMG_LOADRESOURCERAWFILE ) { HRSRC hResourceData; HGLOBAL hGlobalResource; LPVOID lpGlobalResource = NULL; DWORD nFileSize; TCHAR *FileName = (TCHAR*) HMG_parc(1); TCHAR *TypeResource = HB_ISCHAR (2) ? (TCHAR*) HMG_parc(2) : MAKEINTRESOURCE ( hb_parni(2) ); hResourceData = FindResource ( NULL, FileName, TypeResource ); if ( hResourceData != NULL ) { hGlobalResource = LoadResource ( NULL, hResourceData ); if ( hGlobalResource != NULL ) { lpGlobalResource = LockResource ( hGlobalResource ); if ( lpGlobalResource != NULL ) { nFileSize = SizeofResource ( NULL, hResourceData ); hb_retclen ( (const CHAR *) lpGlobalResource, (HB_SIZE) nFileSize ); } FreeResource ( hGlobalResource ); } } if ( lpGlobalResource == NULL ) hb_retclen ( (const CHAR *) NULL, (HB_SIZE) 0 ); }
Archivo de recurso .RC:Code: Select all
/**************************************************************************** HMG_LoadResourceRawFile ( cFileName, cTypeResource | nTypeResourceID ) * *****************************************************************************/ // Standard resource type ID ( constant defined in i_controlmisc.ch ) #define RT_CURSOR (1) #define RT_FONT (8) #define RT_BITMAP (2) #define RT_ICON (3) #define RT_MENU (4) #define RT_DIALOG (5) #define RT_STRING (6) #define RT_FONTDIR (7) #define RT_ACCELERATOR (9) #define RT_RCDATA (10) #define RT_MESSAGETABLE (11) #define DIFFERENCE (11) #define RT_GROUP_CURSOR ( RT_CURSOR + DIFFERENCE ) #define RT_GROUP_ICON ( RT_ICON + DIFFERENCE ) #define RT_VERSION (16) #define RT_DLGINCLUDE (17) #define RT_PLUGPLAY (19) #define RT_VXD (20) #define RT_ANICURSOR (21) #define RT_ANIICON (22) #define RT_HTML (23) #define RT_MANIFEST (24) Function Main cData1 := HMG_LoadResourceRawFile ( "File1", RT_RCDATA ) cData2 := HMG_LoadResourceRawFile ( "File2", "TXT" ) Return Nil
Code: Select all
File1 RCDATA texto.txt File2 TXT texto.txt
Here you are (using zipped ttf):Rathinagiri wrote: ↑Fri Apr 21, 2017 7:54 am Anybody who have used a ttf/otf font file as a resource?
I want to add a font file into the executable file, so that the font need not be installed in the client's system.
Code: Select all
segoeuil RCDATA res\segoeuil.zip
Code: Select all
IF !FILE('segoeuil.ttf')
STRFILE(HMG_LoadResourceRawFile ( 'segoeuil', RT_RCDATA ),'segoeuil.zip')
WypakujZip('segoeuil')
FILEDELETE('segoeuil.zip')
ENDIF
(...)
cfnt:='segoeuil.ttf'
AddFont(cfnt)
SET FONT TO "Segoe UI Light", 13
(...)
//on release of program
RemoveFont(cfnt)
***********************************************************************************
Function RefrProgZip(cRFile,nRPos,cRPrct)
SetProperty(ThisWindow.name,'E_30_10','Value',cRFile)
SetProperty(ThisWindow.name,'ProgBar','Value',nRPos)
SetProperty(ThisWindow.name,'E_62_235','Value',cRPrct)
DO EVENTS
Return Nil
***********************************************************************************
Function WypakujZip(cArchiwum,cPliki,cGdzieUnZip)
//cArchiwum - name of archive (without .zip)
//cPliki - name of file, which to extract, if empty extract all files
//cGdzieUnZip - path to extracted files, if empty in current folder
IF FILE(cArchiwum+'.zip')
DEFINE WINDOW oUnZipFile AT 347 , 538 WIDTH 285 HEIGHT 130 TITLE "Extracting";
ICON Nil NOSIZE NOSYSMENU;
ON INIT StartUnZip(cArchiwum,cPliki,cGdzieUnZip);
ON RELEASE Nil;
BACKCOLOR Nil
ON KEY ALT+F4 ACTION Nil
LABEL(10,10,250,20,"Progress ...",'C')
LABEL(30,10,250,29,"","C")
DEFINE PROGRESSBAR ProgBar
ROW 60
COL 10
WIDTH 220
HEIGHT 20
RANGEMIN 1
RANGEMAX 10
VALUE 0
TOOLTIP ""
HELPID Nil
VISIBLE .T.
SMOOTH .T.
VERTICAL .F.
BACKCOLOR Nil
FORECOLOR Nil
END PROGRESSBAR
LABEL(62,235,40,20,"0 %","L")
END WINDOW
Center window oUnZipFile
Activate window oUnZipFile
ENDIF
Return Nil
***************************************************************
Function StartUnZip(cArchiwum,aPliki,cGdzieUnZip)
Local sukces
Declare Window oUnZipFile
IF VALTYPE(cGdzieUnZip)#'C' .OR. EMPTY(cGdzieUnZip)
cGdzieUnZip:='.\'
ENDIF
IF VALTYPE(aPliki)#'C' .OR. EMPTY(aPliki)
aPliki := hb_GetFilesInZip( cArchiwum+".zip" )
ENDIF
oUnZipFile.ProgBar.Value:=0
oUnZipFile.ProgBar.RANGEMIN:=1
oUnZipFile.ProgBar.RANGEMAX:=LEN(aPliki)
sukces:=hb_UnZipFile( cArchiwum+".zip",{|cFile , nPos| (RefrProgZip(cFile,nPos,ALLTRIM(STR(INT((nPos/LEN(aPliki))*100)))+" %"))},,,;
cGdzieUnZip,aPliki)
IF !sukces
MsgStop("Error while extracting "+cArchiwum+".zip !","Error")
ENDIF
ThisWindow.Release
RETURN Nil
*************************************************************************
FUNCTION Label(nRow,nCol,nSzer,nWys,cTresc,cAtrybut,aKolor,aTlo)
cNazEtyk:="E_"+ALLTRIM(STR(nRow))+"_"+ALLTRIM(STR(nCol))
DEFINE LABEL &cNazEtyk
ROW nRow
COL nCol
WIDTH nSzer
HEIGHT nWys
VALUE cTresc
IF ValType(cAtrybut)='C'
DO CASE
CASE AT('R',UPPER(cAtrybut))#0
RIGHTALIGN .T.
CASE AT('C',UPPER(cAtrybut))#0
CENTERALIGN .T.
ENDCASE
IF AT('B',UPPER(cAtrybut))#0
FONTBOLD .T.
ENDIF
IF AT('I',UPPER(cAtrybut))#0
FONTITALIC .T.
ENDIF
IF AT('U',UPPER(cAtrybut))#0
FONTUNDERLINE .T.
ENDIF
ENDIF
IF ValType(aKolor)='A'
FONTCOLOR aKolor
ELSE
FONTCOLOR Nil
ENDIF
IF ValType(aTlo)='A'
BACKCOLOR atlo
ELSE
BACKCOLOR Nil
ENDIF
ENDELLIPSES .T.
VISIBLE .T.
END LABEL
RETURN Nil
*---------------------------------*
FUNCTION AddFont(font)
*---------------------------------*
#define FR_PRIVATE 0x10
#define FR_NOT_ENUM 0x20
local nRet :=WAPI_ADDFONTRESOURCEEX(font, FR_PRIVATE+ FR_NOT_ENUM,0)
RETURN nRet
*---------------------------------*
FUNCTION RemoveFont(font)
*---------------------------------*
#define FR_PRIVATE 0x10
#define FR_NOT_ENUM 0x20
local nRet := WAPI_REMOVEFONTRESOURCEEX(font, FR_PRIVATE+ FR_NOT_ENUM,0)
RETURN nRet
****************************
Code: Select all
segoeuil RCDATA res\segoeuil.ttf
Code: Select all
IF !FILE('segoeuil.ttf')
STRFILE(HMG_LoadResourceRawFile ( 'segoeuil', RT_RCDATA ),'segoeuil.ttf')
ENDIF
(...)
cfnt:='segoeuil.ttf'
AddFont(cfnt)
SET FONT TO "Segoe UI Light", 13
(...)
//on release of program
RemoveFont(cfnt)
*---------------------------------*
FUNCTION AddFont(font)
*---------------------------------*
#define FR_PRIVATE 0x10
#define FR_NOT_ENUM 0x20
local nRet :=WAPI_ADDFONTRESOURCEEX(font, FR_PRIVATE+ FR_NOT_ENUM,0)
RETURN nRet
*---------------------------------*
FUNCTION RemoveFont(font)
*---------------------------------*
#define FR_PRIVATE 0x10
#define FR_NOT_ENUM 0x20
local nRet := WAPI_REMOVEFONTRESOURCEEX(font, FR_PRIVATE+ FR_NOT_ENUM,0)
RETURN nRet
****************************
Hi edk, thanks for the code. I too wanted to add ttf in my exe and was looking for an idea.edk wrote: ↑Fri Apr 21, 2017 9:09 amHere you are (using zipped ttf):Rathinagiri wrote: ↑Fri Apr 21, 2017 7:54 am Anybody who have used a ttf/otf font file as a resource?
I want to add a font file into the executable file, so that the font need not be installed in the client's system.
.RC file:Code: Select all
segoeuil RCDATA res\segoeuil.zip