METHOD GetText() INLINE If( ! ::lUnicode, GetWindowText( ::hWnd ),;
GetWindowTextW( ::hWnd ) )
METHOD SetText( cText ) INLINE ;
::cCaption := cText,;
If( ::lUnicode,;
SetWindowTextW( ::hWnd, ::cCaption ),;
SetWindowText( ::hWnd, ::cCaption ) )
HB_FUNC( SETWINDOWTEXTW )
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
if( IsWindow( hWnd ) )
{
LPWSTR pW = HB_ISCHAR( 2 ) ? UTF8toUTF16( hb_parc( 2 ) ): L"";
SetWindowTextW( ( HWND ) hb_parnl( 1 ), pW );
if( HB_ISCHAR( 2 ) )
hb_xfree( pW );
}
}
HB_FUNC( GETWINDOWTEXTW )
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
LPWSTR pText;
int iLen = IF( IsWindow( hWnd ), GetWindowTextLengthW( hWnd ), 0 );
if( iLen > 0 )
{
pText = ( LPWSTR ) hb_xgrab( ( iLen * 2 ) + 2 );
GetWindowTextW( hWnd, pText, ( iLen * 2 ) + 2 );
MessageBoxW( 0, pText, L"from C", 0 );
hb_retclen( pText, ( iLen * 2 ) + 2 );
hb_xfree( pText );
}
else
hb_retc( "" );
}
Antonio Linares wrote:Would you like to test it and help to complete the missing parts ? thanks
LPSTR UTF16toUTF8( LPWSTR utf16 )
{
WORD wUtf16Len = wcslen( utf16 );
WORD wUtf8Len = WideCharToMultiByte( CP_UTF8, 0, utf16, wUtf16Len,
NULL, 0, NULL, NULL );
LPSTR pString = ( LPSTR ) hb_xgrab( wUtf8Len + 1 );
pString[ 0 ] = 0;
WideCharToMultiByte( CP_UTF8, 0, utf16, wUtf16Len,
pString, wUtf8Len, 0, 0 );
return pString;
}
HB_FUNC( GETWINDOWTEXTW )
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
LPWSTR pText;
LPSTR szText;
int iLen = IF( IsWindow( hWnd ), GetWindowTextLengthW( hWnd ), 0 );
if( iLen > 0 )
{
pText = ( LPWSTR ) hb_xgrab( ( iLen * 2 ) + 2 );
GetWindowTextW( hWnd, pText, ( iLen * 2 ) + 2 );
szText = UTF16toUTF8( pText );
// MessageBoxW( 0, pText, L"GetWindowTextW", 0 );
hb_retclen( szText, strlen( szText ) + 1 );
hb_xfree( pText );
hb_xfree( szText );
}
else
hb_retc( "" );
}
// Save this file with UTF-8 coding
//
// ToDo: DT_RTLREADING
//
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oWnd
local aArray, aArray2
local lUnicode := .T.
local cCad1, oBtn, cText, oBrw, oCbx, oSay, oGet
aArray := { { "China: ", "中国版 (China)" },;
{ "Hong Kong", "香港版 (Hong Kong)" },;
{ "Japan:", "日本 (Japan)" },;
{ "Korea:", "한국 (Korea)" },;
{ "Taiwan:", "台灣版 (Taiwan)" },;
{ "Israel:", "ישראל (Israel)" },;
{ "Greece:", "Ελλάδα (Greece)" },;
{ "Arabic:", "العالم العربي (Arabic)" },;
{ "Russia:", "Россия (Russia)" },;
{ "India:", "हिन्दी (India)" },;
{ "India:", "தமிழ் (India)" },;
{ "India:", "മലയാളം (India)" },;
{ "India:", "తెలుగు (India)" } }
FW_SetUnicode( .T. )
aArray2 := {}
AEVAL( aArray, { |x| AADD(aArray2,x[2]) } )
DEFINE WINDOW oWnd FROM 3, 6 TO 36, 70 ;
TITLE "Unicode Window - " + aArray[ 1, 2 ] ;
MENU BuildMenu( oWnd, aArray )
SET MESSAGE TO "Message - " + aArray[ 1, 2 ] OF oWnd
@ 1, 3 SAY aArray[ 1, 2 ]
@ 2, 3 SAY aArray[ 2, 2 ]
@ 3, 3 SAY aArray[ 3, 2 ]
@ 4, 3 SAY aArray[ 4, 2 ]
@ 5, 3 SAY aArray[ 5, 2 ]
@ 1, 30 SAY aArray[ 6, 2 ]
@ 2, 30 SAY aArray[ 7, 2 ]
@ 3, 30 SAY aArray[ 8, 2 ]
@ 4, 30 SAY aArray[ 9, 2 ]
@ 5, 30 SAY aArray[ 10, 2 ]
@ 1, 50 SAY aArray[ 11, 2 ]
@ 2, 50 SAY aArray[ 12, 2 ]
@ 3, 50 SAY aArray[ 13, 2 ]
cText := aArray2[1]
@ 7.5, 2 COMBOBOX oCbx VAR cText OF oWnd ;
ITEMS aArray2 SIZE 250, 150 ;
ON CHANGE ( oWnd:SetText( aArray2[ oCbx:nAt ] ),;
oWnd:oMsgBar:SetMsg( aArray2[ oCbx:nAt ] ),;
oBtn:SetText( aArray2[ oCbx:nAt ] ), oGet:SetText( aArray2[ oCbx:nAt ] ) )
cCad1 := PADR( aArray[1,2], 100 )
@ 10, 2 SAY oSay PROMPT aArray[1,2]+":" OF oWnd
@ 11.2, 16 GET oGet VAR cCad1 OF oWnd SIZE 200, 24
@ 16, 4 LISTBOX oBrw ;
FIELDS "", "" ;
HEADERS aArray[1,2], aArray[3,2];
FIELDSIZES 150 ;
OF oWnd;
SIZE 400, 160
oBrw:SetArray( aArray )
oBrw:nAt := 1
oBrw:bLine := { || { aArray[ oBrw:nAt ][1], aArray[ oBrw:nAt ][2] } }
oBrw:bGoTop := { || oBrw:nAt := 1 }
oBrw:bGoBottom := { || oBrw:nAt := Eval( oBrw:bLogicLen ) }
oBrw:bSkip := { | nWant, nOld | nOld := oBrw:nAt, oBrw:nAt += nWant,;
oBrw:nAt := Max( 1, Min( oBrw:nAt, Eval( oBrw:bLogicLen ) ) ),;
oBrw:nAt - nOld }
oBrw:bLogicLen := { || Len( aArray ) }
oBrw:cAlias := "Array" // Just put something
oBrw:lUnicode := lUnicode
@ 23, 6 BUTTON oBtn PROMPT aArray[ 1, 2 ] SIZE 130, 24 OF oWnd ;
ACTION MsgInfoW( oBtn:GetText() ) // oBtn:SetText( aArray[ 2, 2 ] ) // oBnMsgInfoW( oBtn:SetText( oBtn:GetText() ), aArray[ 1, 2 ] )
@ 23, 45 BUTTON ">>> Dialog-Test" SIZE 130, 24 OF oWnd ;
ACTION UnicodeDialog( aArray, aArray2, lUnicode )
oWnd:Center()
ACTIVATE WINDOW oWnd
return nil
//----------------------------------------------------------------------------//
function UnicodeDialog( aArray, aArray2, lUnicode )
local oDlg, oBtn, oBrw, oCbx, cCad1, oGet, oSay, cText
DEFINE DIALOG oDlg FROM 3, 6 TO 37, 70 ;
TITLE "Unicode Dialog - " + aArray[ 1, 2 ]
@ 10, 15 SAY aArray[ 1, 2 ] PIXEL
@ 18, 15 SAY aArray[ 2, 2 ] PIXEL
@ 26, 15 SAY aArray[ 3, 2 ] PIXEL
@ 34, 15 SAY aArray[ 4, 2 ] PIXEL
@ 42, 15 SAY aArray[ 5, 2 ] PIXEL
@ 10, 85 SAY aArray[ 6, 2 ] PIXEL
@ 18, 85 SAY aArray[ 7, 2 ] PIXEL
@ 26, 85 SAY aArray[ 8, 2 ] PIXEL
@ 34, 85 SAY aArray[ 9, 2 ] PIXEL
@ 42, 85 SAY aArray[ 10, 2 ] PIXEL
@ 10, 180 SAY aArray[ 11, 2 ] PIXEL
@ 18, 180 SAY aArray[ 12, 2 ] PIXEL
@ 26, 180 SAY aArray[ 13, 2 ] PIXEL
cText = aArray2[ 1 ]
@ 4, 2 COMBOBOX oCbx VAR cText OF oDlg;
ITEMS aArray2 SIZE 150, 50;
ON CHANGE ( oDlg:SetText( aArray2[oCbx:nAt] ), oDlg:oMsgBar:SetMsg( aArray2[oCbx:nAt] ), oBtn:SetText( aArray2[oCbx:nAt] ), oGet:SetText( aArray2[oCbx:nAt] ) )
cCad1 := PADR( aArray[1,2], 100 )
@ 5.1, 2 SAY oSay PROMPT aArray[1,2]+":" OF oDlg
@ 6, 9 GET oGet VAR cCad1 OF oDlg SIZE 100, 12
@ 9, 4 LISTBOX oBrw ;
FIELDS "", "" ;
HEADERS aArray[1,2], aArray[3,2];
FIELDSIZES 150 ;
/*FONT oFont*/ OF oDlg;
SIZE 200, 80
oBrw:SetArray( aArray )
oBrw:nAt := 1
oBrw:bLine := { || { aArray[ oBrw:nAt ][1], aArray[ oBrw:nAt ][2] } }
oBrw:bGoTop := { || oBrw:nAt := 1 }
oBrw:bGoBottom := { || oBrw:nAt := Eval( oBrw:bLogicLen ) }
oBrw:bSkip := { | nWant, nOld | nOld := oBrw:nAt, oBrw:nAt += nWant,;
oBrw:nAt := Max( 1, Min( oBrw:nAt, Eval( oBrw:bLogicLen ) ) ),;
oBrw:nAt - nOld }
oBrw:bLogicLen := { || Len( aArray ) }
oBrw:cAlias := "Array" // Just put something
oBrw:lUnicode := lUnicode
@ 12,6 BUTTON oBtn PROMPT aArray2[ 1 ] SIZE 100,14 OF oDlg ;
ACTION MsgInfoW( oBtn:GetText(), aArray[ 1, 2 ] )
@ 12,31 BUTTON "Close" size 30,14 OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED;
ON INIT ( oDlg:oMsgBar := TMsgBar():New( oDlg, "Message - "+aArray[1,2], .F., .F., .F., .F.,,,, .F. ),;
oDlg:SetMenu( BuildMenu( oDlg, aArray, lUnicode ) ) )
return nil
//----------------------------------------------------------------------------//
function BuildSays( oWnd, hDC, aArray )
oWnd:Say( 1, 3, aArray[ 1, 2 ],,, , .F., .T. )
oWnd:Say( 2, 3, aArray[ 2, 2 ],,, , .F., .T. )
oWnd:Say( 3, 3, aArray[ 3, 2 ],,, , .F., .T. )
oWnd:Say( 4, 3, aArray[ 4, 2 ],,, , .F., .T. )
oWnd:Say( 5, 3, aArray[ 5, 2 ],,, , .F., .T. )
oWnd:Say( 1, 30, aArray[ 6, 2 ],,, , .F., .T. )
oWnd:Say( 2, 30, aArray[ 7, 2 ],,, , .F., .T. )
oWnd:Say( 3, 30, aArray[ 8, 2 ],,, , .F., .T. )
oWnd:Say( 4, 30, aArray[ 9, 2 ],,, , .F., .T. )
oWnd:Say( 5, 30, aArray[ 10, 2 ],,, , .F., .T. )
oWnd:Say( 1, 50, aArray[ 11, 2 ],,, , .F., .T. )
oWnd:Say( 2, 50, aArray[ 12, 2 ],,, , .F., .T. )
oWnd:Say( 3, 50, aArray[ 13, 2 ],,, , .F., .T. )
return nil
//----------------------------------------------------------------------------//
function BuildMenu( oWnd, aArray, lUnicode )
local oMenu, oMenuItem
MENU oMenu
MENUITEM aArray[ 1, 2 ] MESSAGE aArray[ 1, 2 ]
MENU
MENUITEM aArray[ 1, 2 ] MESSAGE aArray[ 1, 2 ]
MENUITEM aArray[ 2, 2 ] MESSAGE aArray[ 2, 2 ]
MENUITEM aArray[ 3, 2 ] MESSAGE aArray[ 3, 2 ]
MENUITEM aArray[ 4, 2 ] MESSAGE aArray[ 4, 2 ]
MENUITEM aArray[ 5, 2 ] MESSAGE aArray[ 5, 2 ]
SEPARATOR
MENUITEM aArray[ 6, 2 ] MESSAGE aArray[ 6, 2 ]
MENUITEM aArray[ 7, 2 ] MESSAGE aArray[ 7, 2 ]
MENUITEM aArray[ 8, 2 ] MESSAGE aArray[ 8, 2 ]
MENUITEM aArray[ 9, 2 ] MESSAGE aArray[ 9, 2 ]
MENUITEM aArray[ 10, 2 ] MESSAGE aArray[ 10, 2 ]
SEPARATOR
MENUITEM aArray[ 11, 2 ] MESSAGE aArray[ 11, 2 ]
MENUITEM aArray[ 12, 2 ] MESSAGE aArray[ 12, 2 ]
MENUITEM aArray[ 13, 2 ] MESSAGE aArray[ 13, 2 ]
ENDMENU
MENUITEM aArray[ 2, 2 ] MESSAGE aArray[ 2, 2 ]
MENUITEM aArray[ 3, 2 ] MESSAGE aArray[ 3, 2 ]
MENUITEM aArray[ 4, 2 ] MESSAGE aArray[ 4, 2 ]
MenuEnd()
oMenu:l2007 := .f.
oMenu:l2010 := .f.
return oMenu
//----------------------------------------------------------------------------//
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 52 guests