Página 1 de 1

Incluir arquivo TXT dentro de um arquivo RC (Resource)

Enviado: 03 Jan 2014 10:56
por Toledo
Amigos, nos arquivos RC (Resource) tem como incluir um arquivo TXT usando o parâmetro RCDATA ou TEXT.

Exemplo:
Leiame RCDATA texto.txt
Bom, minha dúvida é depois como usar este arquivo dentro do meu programa?

Abraços,

Incluir arquivo TXT dentro de um arquivo RC (Resource)

Enviado: 04 Jan 2014 18:29
por Toledo
Amigos, com a ajuda do Carlos Britos do Fórum HMG consegui resolver esta minha dúvida, segue o código:

Código: Selecionar todos

#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
Abraços,

Incluir arquivo TXT dentro de um arquivo RC (Resource)

Enviado: 12 Jan 2014 14:22
por Claudio Soto
Hola Toledo,
en la siguiente versión de HMG voy a incluir la siguiente función:

Código: Selecionar todos

//        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:

Código: Selecionar todos



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

Código: Selecionar todos

File1    RCDATA  texto.txt
File2    TXT        texto.txt

Incluir arquivo TXT dentro de um arquivo RC (Resource)

Enviado: 12 Jan 2014 15:29
por Toledo
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,

Incluir arquivo TXT dentro de um arquivo RC (Resource)

Enviado: 12 Jan 2014 18:10
por Claudio Soto
Me olvidaba,
sí usas MiniGui Extended, solo hay que cambiar en la linea 9 de la función en C:

HMG_parc (1)

por

hb_parc (1)

Saludos,
Claudio.