RichEdit Justificar Texto
Enviado: 26 Ago 2015 00:22
Olá,
Alguém sabe como justificar um texto em um RichEdit?
Alguém sabe como justificar um texto em um RichEdit?
Código: Selecionar todos
SendMessage (hRichEditBox, EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY);
Código: Selecionar todos
// RichEditBox_SetParaFormatAlignment ( hRichEditBox, nAlignment )
HB_FUNC ( RICHEDITBOX_SETPARAFORMATALIGNMENT )
{
HWND hRichEditBox = (HWND) HMG_parnl (1);
WORD Alignment = (WORD) hb_parni (2);
PARAFORMAT2 ParaFormat2;
ZeroMemory ( &ParaFormat2, sizeof (PARAFORMAT2) );
ParaFormat2.cbSize = sizeof (PARAFORMAT2);
ParaFormat2.dwMask = PFM_ALIGNMENT;
switch( Alignment )
{
case 1: ParaFormat2.wAlignment = PFA_LEFT; break;
case 2: ParaFormat2.wAlignment = PFA_RIGHT; break;
case 3: ParaFormat2.wAlignment = PFA_CENTER; break;
case 4: ParaFormat2.wAlignment = PFA_JUSTIFY; break;
default: ParaFormat2.wAlignment = PFA_LEFT; break;
}
SendMessage ( hRichEditBox, EM_SETPARAFORMAT, 0, (LPARAM) &ParaFormat2 );
}
Código: Selecionar todos
@ x,y RICHEDIT oRichEdit ...
RICHEDITBOX_SETTYPOGRAPHYOPTIONS ( oRichEdit:handle )
RichEditBox_SetParaFormatAlignment ( oRichEdit:handle , nAlignment )
#pragma BEGINDUMP
#include "hwingui.h"
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include <shlwapi.h>
#include "hbapi.h"
HB_FUNC ( RICHEDITBOX_SETTYPOGRAPHYOPTIONS )
{
HWND hRichEditBox = ( HWND ) HB_PARHANDLE( 1 );
SendMessage (hRichEditBox, EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY);
}
// RichEditBox_SetParaFormatAlignment ( hRichEditBox, nAlignment )
HB_FUNC ( RICHEDITBOX_SETPARAFORMATALIGNMENT )
{
HWND hRichEditBox = ( HWND ) HB_PARHANDLE ( 1 );
WORD Alignment = (WORD) hb_parni (2);
PARAFORMAT2 ParaFormat2;
ZeroMemory ( &ParaFormat2, sizeof (PARAFORMAT2) );
ParaFormat2.cbSize = sizeof (PARAFORMAT2);
ParaFormat2.dwMask = PFM_ALIGNMENT;
switch( Alignment )
{
case 1: ParaFormat2.wAlignment = PFA_LEFT; break;
case 2: ParaFormat2.wAlignment = PFA_RIGHT; break;
case 3: ParaFormat2.wAlignment = PFA_CENTER; break;
case 4: ParaFormat2.wAlignment = PFA_JUSTIFY; break;
default: ParaFormat2.wAlignment = PFA_LEFT; break;
}
SendMessage ( hRichEditBox, EM_SETPARAFORMAT, 0, (LPARAM) &ParaFormat2 );
}
#pragma ENDDUMP
Código: Selecionar todos
@ x,y RICHEDIT oRichEdit ... ON OTHERMESSAGES {|...| Test(...) ) } Código: Selecionar todos
FUNCTION Test ( oRichEdit, msg, wParam, lParam )
IF msg == WM_KEYDOWN .AND. hwg_PtrToUlong( wParam ) == 116 // VK_F5
RICHEDITBOX_SETTYPOGRAPHYOPTIONS ( oRichEdit:handle )
RichEditBox_SetSelRange ( oRichEdit:handle, { 0, -1 } ) // selecciona todo el texto
RichEditBox_SetParaFormatAlignment ( oRichEdit:handle , 4 )
ENDIF
RETURN -1
Código: Selecionar todos
// RichEditBox_SetSelRange ( hWndControl, { nMin, nMax } )
HB_FUNC ( RICHEDITBOX_SETSELRANGE )
{
CHARRANGE CharRange;
HWND hWndControl = ( HWND ) HB_PARHANDLE ( 1 );
CharRange.cpMin = (LONG) hb_parvnl(2,1);
CharRange.cpMax = (LONG) hb_parvnl(2,2);
SendMessage ( hWndControl, EM_EXSETSEL, 0, (LPARAM) &CharRange );
}
Código: Selecionar todos
nDataFormat := 4
lSelection := .F. // si es .T. grava solo el texto seleccionado
cFileName := "arch.rtf"
RichEditBox_StreamOut ( oRichEdit:handle, cFileName, lSelection, nDataFormat )
Código: Selecionar todos
DWORD CALLBACK EditStreamCallbackWrite (DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
{
HANDLE hFile = (HANDLE) dwCookie;
if ( WriteFile (hFile, (LPVOID) lpBuff, (DWORD) cb, (LPDWORD) pcb, NULL) )
return 0;
else
return -1;
}
#ifdef UNICODE
#define HMG_CHAR_TO_WCHAR(c) ((c != NULL) ? hb_osStrU16Encode(c) : NULL) // return WCHAR
#define HMG_parc(n) HMG_CHAR_TO_WCHAR (hb_parc(n))
#else
#define HMG_parc(n) hb_parc (n)
#endif
// RichEditBox_StreamOut ( hWndControl, cFileName, lSelection, nDataFormat )
HB_FUNC ( RICHEDITBOX_STREAMOUT )
{
HWND hWndControl = ( HWND ) HB_PARHANDLE ( 1 );
TCHAR *cFileName = (TCHAR*) HMG_parc (2);
BOOL lSelection = (BOOL) hb_parl (3);
LONG nDataFormat = (LONG) hb_parnl (4);
HANDLE hFile;
EDITSTREAM es;
LONG Format;
switch( nDataFormat )
{
case 1: Format = SF_TEXT; break; // ANSI and UTF-8 with BOM
case 2: Format = ( CP_UTF8 << 16 ) | SF_USECODEPAGE | SF_TEXT; break; // ANSI and UTF-8 without BOM
case 3: Format = SF_TEXT | SF_UNICODE; break; // UTF-16 LE
case 4: Format = SF_RTF; break;
case 5: Format = ( CP_UTF8 << 16 ) | SF_USECODEPAGE | SF_RTF; break;
default: Format = SF_RTF; break;
}
if ( lSelection )
Format = Format | SFF_SELECTION;
if( ( hFile = CreateFile (cFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL )) == INVALID_HANDLE_VALUE )
{ hb_retl (FALSE);
return;
}
es.pfnCallback = EditStreamCallbackWrite;
es.dwCookie = (DWORD_PTR) hFile;
es.dwError = 0;
SendMessage ( hWndControl, EM_STREAMOUT, (WPARAM) Format, (LPARAM) &es );
CloseHandle (hFile);
if( es.dwError )
hb_retl (FALSE);
else
hb_retl (TRUE);
}
Código: Selecionar todos
nDataFormat := 4
lSelection := .F. // si es .T. el archivo cargado sustituye al texto seleccionado
cFileName := "arch.rtf"
RichEditBox_StreamIn ( oRichEdit:handle, cFileName, lSelection, nDataFormat )
Código: Selecionar todos
DWORD CALLBACK EditStreamCallbackRead (DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
{
HANDLE hFile = (HANDLE) dwCookie;
if ( Read File (hFile, (LPVOID) lpBuff, (DWORD) cb, (LPDWORD) pcb, NULL) )
return 0;
else
return -1;
}
// RichEditBox_StreamIn ( hWndControl, cFileName, lSelection, nDataFormat )
HB_FUNC ( RICHEDITBOX_STREAMIN )
{
HWND hWndControl = ( HWND ) HB_PARHANDLE ( 1 );
TCHAR *cFileName = (TCHAR*) HMG_parc (2);
BOOL lSelection = (BOOL) hb_parl (3);
LONG nDataFormat = (LONG) hb_parnl (4);
HANDLE hFile;
EDITSTREAM es;
LONG Format;
switch( nDataFormat )
{
case 1: Format = SF_TEXT; break; // ANSI and UTF-8 with BOM
case 2: Format = ( CP_UTF8 << 16 ) | SF_USECODEPAGE | SF_TEXT; break; // ANSI and UTF-8 without BOM
case 3: Format = SF_TEXT | SF_UNICODE; break; // UTF-16 LE
case 4: Format = SF_RTF; break;
case 5: Format = ( CP_UTF8 << 16 ) | SF_USECODEPAGE | SF_RTF; break;
default: Format = SF_RTF; break;
}
if ( lSelection )
Format = Format | SFF_SELECTION;
if( ( hFile = CreateFile (cFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL )) == INVALID_HANDLE_VALUE )
{ hb_retl (FALSE);
return;
}
es.pfnCallback = EditStreamCallbackRead;
es.dwCookie = (DWORD_PTR) hFile;
es.dwError = 0;
SendMessage ( hWndControl, EM_STREAMIN, (WPARAM) Format, (LPARAM) &es );
CloseHandle (hFile);
if( es.dwError )
hb_retl (FALSE);
else
hb_retl (TRUE);
}
Claudio Soto escreveu:PD: en la linea 4, Read File va todo junto sin espacio en el medio, si lo escribo sin espacio el servidor no me acepta.