FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Listview Unicode for CLASS TGrid()
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Listview Unicode for CLASS TGrid()
Posted: Wed Aug 30, 2023 01:14 PM
hi,

i have found in c:\fwh\source\winapi\listview.c what was change for Unicode
Code (fw): Select all Collapse
   LPWSTR pWide = fw_parWide( 3 );

//   lvi.pszText  = ( LPTSTR ) hb_parc( 3 );
   lvi.pszText  = pWide;
Question : is fw_parWide() the same as AnsiToWide() :?:

---

i have now include
Code (fw): Select all Collapse
#define UNICODE    // Made Unicode compatible 2023-07-07
#include <CommCtrl.h>
#undef UNICODE
#include "fwh.h"
Question : why "#undef UNICODE" :?:

---

now i get Warning
Warning W8075 .\\HB_FUNC.PRG 702: Suspicious pointer conversion in function HB_FUN_LV_ADDITEM
Warning W8075 .\\HB_FUNC.PRG 717: Suspicious pointer conversion in function HB_FUN_LV_ADDITEM
Warning W8075 .\\HB_FUNC.PRG 764: Suspicious pointer conversion in function HB_FUN_LV_ADDITEMS
Warning W8075 .\\HB_FUNC.PRG 778: Suspicious pointer conversion in function HB_FUN_LV_ADDITEMS
Warning W8075 .\\HB_FUNC.PRG 813: Suspicious pointer conversion in function HB_FUN_LV_ADDCOLUMN
Warning W8075 .\\HB_FUNC.PRG 942: Suspicious pointer conversion in function HB_FUN_LV_GETITEMTEXT
Warning W8075 .\\HB_FUNC.PRG 948: Suspicious pointer conversion in function HB_FUN_LV_GETITEMTEXT
Warning W8075 .\\HB_FUNC.PRG 1265: Suspicious pointer conversion in function HB_FUN_LV_INSERTCOLUMN
Warning W8075 .\\HB_FUNC.PRG 1407: Suspicious pointer conversion in function HB_FUN_LV_SETITEMTEXT
Warning W8075 .\\HB_FUNC.PRG 1601: Suspicious pointer conversion in function HB_FUN_LV_SETGRIDQUERYDATA
Warning W8075 .\\HB_FUNC.PRG 1601: Suspicious pointer conversion in function HB_FUN_LV_SETGRIDQUERYDATA
i guess it is while i have not use fw_parWide() / LPWSTR but LPTSTR

---

how to use this with Unicode
Code (fw): Select all Collapse
   lvi.pszText    = (TCHAR*) hb_parvc (2, 1);
Code (fw): Select all Collapse
    LPSTR lpText;
   char *   caption;
   ...
   for (nCol = 1; nCol < nColumnCount; nCol++)
   {
      caption  = (TCHAR*) hb_parvc (2, nCol+1) ;
      lpText = caption;
      ListView_SetItemText (hWnd, nRow, nCol, lpText );
   }
Code (fw): Select all Collapse
1599   // lstrcpyn( pDispInfo->item.pszText, ( CHAR * ) hb_parc( 2 ), pDispInfo->item.cchTextMax );
1600   LPWSTR lpText = fw_parWide( 2 );
1601   lstrcpyn( pDispInfo->item.pszText, lpText, pDispInfo->item.cchTextMax );
Code (fw): Select all Collapse
HB_FUNC( LV_GETITEMTEXT )
{
   TCHAR buffer [1024] ;
...
   lvi.pszText = buffer;
   buffer[ 0 ] = 0;
   buffer[ 1023 ] = 0;

   ListView_GetItem( hWnd, &lvi );

   hb_retc (lvi.pszText);
}
how can help me please
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Listview Unicode for CLASS TGrid()
Posted: Wed Aug 30, 2023 02:50 PM
Question : is fw_parWide() the same as AnsiToWide() :?:
No.
if the parameter is UTF8 it uses "MultiByteToWideChar()", Windows API function and if not, then it is ANSI and uses AnsiToWide()
See:
https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar
https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte

It is safer to use FWH built-in functions to make properly working Unicode library.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Listview Unicode for CLASS TGrid()
Posted: Wed Aug 30, 2023 06:06 PM
Code (fw): Select all Collapse
#define UNICODE    // Made Unicode compatible 2023-07-07
#include <CommCtrl.h>
#undef UNICODE
#include "fwh.h"
Sole purpose of this def and undef is to get the our program defines to work with Wide structures and Wide api functions.
Beyond that we have no use for this define.


In some cases Wide api handle normal ansi strings also well.
In this small module this is enough for us.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Listview Unicode for CLASS TGrid()
Posted: Wed Aug 30, 2023 06:08 PM
i guess it is while i have not use fw_parWide() / LPWSTR but LPTSTR
Yes.
If you like we can make the modifications.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Listview Unicode for CLASS TGrid()
Posted: Wed Aug 30, 2023 06:11 PM
how to use this with Unicode
Code:
lvi.pszText = (TCHAR*) hb_parvc (2, 1);
can I see the full HB_FUNC?
Or you can send to me.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Listview Unicode for CLASS TGrid()
Posted: Thu Aug 31, 2023 03:21 AM
hi,
nageswaragunupudi wrote:can I see the full HB_FUNC?
you can find Source of CLASS TGrid and Hb_Func.PRG ( all "C" Code ) at
https://github.com/AugeOhr/TGRID

---

i try to learn "C" but for these "Problem" my "C" Knowledge is to small
my ANSI Version , using TCHAR / LPSTR , work but how with Unicode :?:

need some help please
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Listview Unicode for CLASS TGrid()
Posted: Mon Sep 04, 2023 02:25 PM
i try to learn "C" but for these "Problem" my "C" Knowledge is to small
I am also still learning Sir.
We will surely assist you on this.
Please give me a little more time.
Too many things on hand right now.

Note:
This is my personal opinion. I will stand corrected if I am wrong.
I think if the application is not at all meant for East Asian Languages which are totally dependent on Unicode, better we stick to ANSI mode only ( I mean for applications meant for West European Languages only.
Only requirement for UTF8 is when writing to and reading data from Utf encoded database tables.
We have other ways of handling that.
Just an idea for you and other friends to consider.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Listview Unicode for CLASS TGrid()
Posted: Mon Sep 04, 2023 09:53 PM
hi,

i do understand that East Asian Languages are not the biggest Problem for Fivewin

my TGrid() ANSI Version work so far but when enable LVS_OWNERDATA it does not work with FW_SetUnicode( .T. ) :(
Code (fw): Select all Collapse
      ::nStyle := nOR( ::nStyle, LVS_OWNERDATA )
      ::bDisplay := { | nPtrNMHDR | ::OnDISPINFO( nPtrNMHDR ) }
when set FW_SetUnicode( .T. ) it does "block" notify Event LVN_GETDISPINFO
Code (fw): Select all Collapse
METHOD Notify( nIdCtrl, nPtrNMHDR ) CLASS TGrid
LOCAL nCode := GetNMHDRCode( nPtrNMHDR )
LOCAL nItem := GETNMHEAITEM( nPtrNMHDR )
LOCAL nKey
LOCAL nPosi, nRow, r

STATIC nOption

   DO CASE
      CASE nCode == LVN_GETDISPINFO
         IF ::bDisplay != nil
            EVAL( ::bDisplay, nPtrNMHDR, Self )
         ENDIF
i "hope" that it work when my CLASS TGrid() is Unicode "ready" to use "virtual Grid"
it does now work only with "virtual Grid" when use FW_SetUnicode( .F. )
greeting,

Jimmy

Continue the discussion