FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour how to use Member pszText, cx & Co from LVCOLUMN Structure
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
how to use Member pszText, cx & Co from LVCOLUMN Structure
Posted: Mon Oct 17, 2022 10:38 AM
hi,

i use LVCOLUMN from this Thread
https://forums.fivetechsupport.com/viewtopic.php?f=3&t=42301

LVCOLUMN Structure at Microsoft
https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-lvcolumna
https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-lvcolumnw
Code (fw): Select all Collapse
HB_FUNC( LVCOLUMNNEW )
{
   LVCOLUMN * lvcol = ( LVCOLUMN * ) hb_xgrab( sizeof( LVCOLUMN ) );

   memset( lvcol, 0, sizeof( LVCOLUMN ) );
   hb_retptr( ( void * ) lvcol );
}


but it fail here
Code (fw): Select all Collapse
METHOD InitTheListView()
   ::oLVCol := LVCOLUMN():New()

   // LVCF_FMT     = col:fmt   -> LVCFMT_LEFT / LVCFMT_RIGHT / LVCFMT_CENTER
   // LVCF_WIDTH   = col:cx    -> Pixel wide
   // LVCF_TEXT    = col:pszText -> Data
   // LVCF_SUBITEM = use Sub-Items
   ::oLVCol:Mask := hb_bitOr(LVCF_FMT, LVCF_WIDTH, LVCF_TEXT, LVCF_SUBITEM )

   for nCol := 1 to LEN(::aHeader)
      ::oLVCol:pszText  := ::aHeader[nCol][ID_HEADER]

Error description: Error BASE/1005 Message not found: LVCOLUMN:_PSZTEXT
Args:
[ 1] = O LVCOLUMN


Question : do i have to define a Method and HB_FUNC() for every Structure Member :-)

Code (fw): Select all Collapse
METHOD pszText( cValue ) CLASS LVColumn
...
HB_FUNC( LV_COLUMNPSZTEXT )
{
   int pszText = ( ( LVCOLUMN * ) hb_parptr( 1 ) )->pszText;

   if( ! hb_pcount() )
      hb_retnl( ( HB_LONG ) pszText );
   else
      ( ( LVCOLUMN * ) hb_parptr( 1 ) )->pszText = ( char * ) hb_parnl( 2 );

   hb_retnl( pszText );
}


under Xbase++ i have access to all Member of Structure
greeting,

Jimmy
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to use Member pszText, cx & Co from LVCOLUMN Structure
Posted: Mon Oct 17, 2022 03:56 PM

Dear Jimmy,

> Question : do i have to define a Method and HB_FUNC() for every Structure Member ?

Yes

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: how to use Member pszText, cx & Co from LVCOLUMN Structure
Posted: Mon Oct 17, 2022 11:08 PM
hi,

i got Warning
Warning W8069 LVREPORT.prg 435: Nonportable pointer conversion in function HB_FUN_LV_COLUMNPSZTEXT

Code (fw): Select all Collapse
HB_FUNC( LV_COLUMNPSZTEXT )
{
   int pszText = ( ( LVCOLUMN * ) hb_parptr( 1 ) )->pszText;

who can help me please with "C" Code of HB_FUNC( LV_COLUMNPSZTEXT )
greeting,

Jimmy
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: how to use Member pszText, cx & Co from LVCOLUMN Structure
Posted: Tue Oct 18, 2022 01:17 AM
next Problem

Error E2096 LVREPORT.prg 636: Illegal structure operation in function HB_FUN_LV_DISPINFO
Error E2096 LVREPORT.prg 641: Illegal structure operation in function HB_FUN_LV_DISPINFO


Code (fw): Select all Collapse
634│HB_FUNC( LV_DISPINFO )
635│{
636│   UINT item = ( ( NMLVDISPINFOA * ) hb_parptr( 1 ) )->item;
637│
638│   if( ! hb_pcount() )
639│      hb_retnl( ( HB_LONG ) item );
640│   else
641│      ( ( NMLVDISPINFOA * ) hb_parptr( 1 ) )->item = ( UINT ) hb_parnl( 2 );
642│
643│   hb_retnl( item );
644│}
greeting,

Jimmy
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: how to use Member pszText, cx & Co from LVCOLUMN Structure
Posted: Tue Oct 18, 2022 05:40 AM
hi,

have found out that i have to use Member of Structure in HB_FUNC() as "C" Code like for LVITEMx

Code (fw): Select all Collapse
HB_FUNC ( LISTVIEW_INSERTITEM )
{
   LV_ITEM LVI;
   HWND hWnd = (HWND) HMG_parnl (1);
   INT nRow  = (INT)  hb_parni (2);
   INT nColumnCount = (INT)  hb_parni (4);
   INT nCol;
   
   LVI.mask      = LVIF_TEXT;
   LVI.iItem     = nRow;
   LVI.iSubItem  = 0;
   LVI.state     = 0;
   LVI.stateMask = 0;
   LVI.pszText   = (TCHAR*) HMG_parvc (3, 1);
   LVI.iImage    = 0;

   ListView_InsertItem (hWnd, &LVI);

   for (nCol = 1 ; nCol < nColumnCount ; nCol++)
        ListView_SetItemText (hWnd, nRow, nCol, (TCHAR*) HMG_parvc (3, nCol+1));
}

so i have to call HB_FUNC() with Parameter and "right" Type ... hm
btw. Prefix "HMG_" is "compatible" with 64 Bit, what under FiveWin :-)

but how to pass Array and use a Loop to "fill" Member of Structure
Code (fw): Select all Collapse
{
   LV_COLUMN oLVCol ;
   for (nCol = 1 ; nCol < nColumnCount ; nCol++)
      // how to use Array ?
     oLVCol.pszText  := aHeader[nCol][ID_HEADER]+ chr(0)
     oLVCol.cx       := aHeader[nCol][ID_WIDTH ]
}

p.s. why it is called LV_ITEM under harbour while Microsoft say LVITEMA / LVITEMW for Structure
is there a List to "see" which Structure harbour use ?
greeting,

Jimmy
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: how to use Member pszText, cx &amp; Co from LVCOLUMN Structure
Posted: Tue Oct 18, 2022 10:23 AM
hi,

got a Solution
Code (fw): Select all Collapse
   AADD( aHeader, { "Name", 250, LVCFMT_LEFT, "C" } )
   AADD( aHeader, { "Size", 100, LVCFMT_RIGHT, "N" } )
   AADD( aHeader, { "Date", 80, LVCFMT_RIGHT, "D" } )
   AADD( aHeader, { "Time", 70, LVCFMT_RIGHT, "C" } )
   AADD( aHeader, { "Attr", 40, LVCFMT_CENTER, "C" } )


Code (fw): Select all Collapse
   FOR nCol := 1 TO LEN( ::aHeader )
      nWidth := ::aHeader[ nCol ] [ ID_WIDTH ]
      cCaption := VAR2CHAR( ::aHeader[ nCol ] [ ID_HEADER ] ) + CHR( 0 )
      nJustify := ::aHeader[ nCol ] [ ID_ALIGN ]

      LV_ADDCOLUMN( hWnd, nCol, nWidth, cCaption, nJustify )          
   NEXT


Code (fw): Select all Collapse
HB_FUNC( LV_ADDCOLUMN )
{
   LV_COLUMN COL;

   COL.mask= LVCF_WIDTH | LVCF_TEXT | LVCF_FMT | LVCF_SUBITEM ;
   COL.cx= hb_parni(3);
   COL.pszText = (TCHAR*) hb_parc(4);
   COL.iSubItem=hb_parni(2)-1;
   COL.fmt = hb_parni(5) ;

   ListView_InsertColumn ( (HWND) hb_parnl (1), hb_parni(2)-1, &COL );
}
greeting,

Jimmy

Continue the discussion