Include file TXT within a file RC (Resource)

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Include file TXT within a file RC (Resource)

Post by pctoledo »

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

:roll:
Regards/Saludos,

Toledo

Clipper On Line
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Include file TXT within a file RC (Resource)

Post by esgici »

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

:roll:
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 ?

Viva HMG :D
Viva INTERNATIONAL HMG :D
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: Include file TXT within a file RC (Resource)

Post by Carlos Britos »

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

:roll:
Hi,
hope this can give you an idea

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 ) );
         }
      }
   }
}
Replace AU_LPCSTR with LPCWSTR (unicode) or LPCTSTR (ansi)
Regards/Saludos, Carlos (bcd12a)
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Include file TXT within a file RC (Resource)

Post by pctoledo »

Carlos, thank you very much!

I made some changes in your example:

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
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 ?
Dear Esgici,

I actually wanted to include a text-only file.

Thanks to all!
Attachments
resToFile.zip
(698 Bytes) Downloaded 278 times
Regards/Saludos,

Toledo

Clipper On Line
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Include file TXT within a file RC (Resource)

Post by Pablo César »

Parabéns Toledo !

Você não vai acreditar, eu também peguei o exemplo do Carlos e consegui fazer o mesmo ou alias quase o mesmo que você e quando ia postar eu vi que tu já tinha resolvido.

Code: Select all

#include <hmg.ch>

Function Main()

MsgDebug(ReadTxt(12345))
Return Nil

#pragma BEGINDUMP

#include <windows.h>

HB_FUNC( READTXT )
{
   static HRSRC   hr;
   static HGLOBAL hg;

   hr = FindResource( NULL, MAKEINTRESOURCE( hb_parni( 1 ) ), RT_RCDATA );

   if( ! ( hr == 0 ) )
   {
      hg = LoadResource( NULL, hr );
      
      if( ! ( hg == 0 ) )
      {
         hb_retc( hg ) ;
      }
   }
}

#pragma ENDDUMP
Eu estava procurando desde ontem, mas não tinha conseguido êxito... :oops:

Valeu mestre ! Serviu no nosso aprendizado ! :)

Y muchas gracias a Carlos ! Fué fundamental su ayuda. :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Include file TXT within a file RC (Resource)

Post by pctoledo »

Claudio Soto wrote:Hola Toledo,
en la siguiente versión de HMG voy a incluir la siguiente función:

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 );
}
Su uso sería:

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

Archivo de recurso .RC:

Code: Select all

File1    RCDATA  texto.txt
File2    TXT        texto.txt
http://www.pctoledo.com.br/forum/viewto ... 272#p86271

Hola Dr. Claudio,

Voy a esperar a la nueva versión de HMG, pero gracias por el envío del código de la función de antemano.

Gracias,
Regards/Saludos,

Toledo

Clipper On Line
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Include file TXT within a file RC (Resource)

Post by Rathinagiri »

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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Include file TXT within a file RC (Resource)

Post by serge_girard »

Rathi, No idea, this completly new for me! But the TXT sample looks like it could be serve very well?

Serge
There's nothing you can do that can't be done...
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Include file TXT within a file RC (Resource)

Post by edk »

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.
Here you are (using zipped ttf):

.RC file:

Code: Select all

segoeuil   RCDATA res\segoeuil.zip
.PRG file:

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
****************************

Or without .zip:

.RC file:

Code: Select all

segoeuil   RCDATA res\segoeuil.ttf
.PRG file:

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
****************************
User avatar
Anand
Posts: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: Include file TXT within a file RC (Resource)

Post by Anand »

edk wrote: Fri Apr 21, 2017 9:09 am
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.
Here you are (using zipped ttf):

.RC file:

Code: Select all

segoeuil   RCDATA res\segoeuil.zip
Hi edk, thanks for the code. I too wanted to add ttf in my exe and was looking for an idea.

One query, can't we just add the .ttf file directly in .rc file ? We can add .png, .html etc. I found.

Regards,

Anand
Regards,

Anand

Image
Post Reply