I done some experiment about class management in Harbour: It is possible define Class's method in C and Manipulate a Class and return it from C code.
Here an example to avoid save item data in another array.
#include <fivewin.ch>
#include <dialog.ch>
procedure Main()
LOCAL oDlg
TListViewItem() //without this does not found the class :(
DEFINE DIALOG oDlg FROM 0,0 TO 220,200 PIXEL TITLE "Test"
ACTIVATE DIALOG oDlg CENTER ON INIT InitDlg(Self)
return
PROCEDURE InitDlg(oDlg)
LOCAL oList
@ 1,1 LISTVIEW oList PROMPTS "FiveWin","Item2" OF oDlg SIZE 160,160
@ 11,1 BUTTON "Test" ACTION CLICK(oList) SIZE 40,16
return
PROCEDURE CLICK(oList)
//LOCAL pItem := oList:MyGetItem(1) //if you declare it in class
LOCAL pItem := TLISTVIEW_MYGETITEM(oList,2)
LOCAL cInfo := ""
cInfo += "Item :" + pItem:cText
cInfo += " Image :" + STR(pItem:nImage)
MsgInfo(cInfo)
return
#pragma BEGINDUMP
#include <windows.h>
#include <CommCtrl.h>
#include <hbapi.h>
#include <hbapicls.h>
#include <hbapiitm.h>
#include <stdio.h>
#include <hbstack.h>
struct TLISTVIEWDATA
{
HB_USHORT classId;
HB_SIZE hWnd;
} TListViewData = {0};
void InitListViewData()
{
if(TListViewData.classId == 0)
{
TListViewData.classId = hb_clsFindClass("TLISTVIEW", NULL);
if(TListViewData.classId == 0) MessageBox(NULL,"TLISTVIEW not found","Error",MB_OK);
TListViewData.hWnd = hb_clsGetVarIndex(TListViewData.classId,hb_dynsymGet("hWnd"));
}
}
struct TLISTVIEWITEMDATA
{
HB_USHORT classId;
HB_SIZE oParent ;
HB_SIZE cText ;
HB_SIZE cToolTip ;
HB_SIZE nImage ;
HB_SIZE nGroup ;
HB_SIZE nIndent ;
HB_SIZE lChecked ;
HB_SIZE nItem ;
HB_SIZE Cargo ;
} TListViewItemData = {0};
void InitListViewItemData()
{
InitListViewData();
if(TListViewItemData.classId == 0)
{
TListViewItemData.classId = hb_clsFindClass("TLISTVIEWITEM", NULL);
if(TListViewItemData.classId == 0) MessageBox(NULL,"TLISTVIEWITEM not found","Error",MB_OK);
TListViewItemData.oParent = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("oParent"));
TListViewItemData.cText = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("cText"));
TListViewItemData.cToolTip = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("cToolTip"));
TListViewItemData.nImage = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("nImage"));
TListViewItemData.nGroup = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("nGroup"));
TListViewItemData.nIndent = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("nIndent"));
TListViewItemData.lChecked = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("lChecked"));
TListViewItemData.nItem = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("nItem"));
TListViewItemData.Cargo = hb_clsGetVarIndex(TListViewItemData.classId,hb_dynsymGet("Cargo"));
}
}
HB_FUNC( TLISTVIEW_MYGETITEM )
{
//PHB_ITEM pListView = hb_stackSelfItem(); //in this case all parameter id is one less
PHB_ITEM pListView = hb_param(1,HB_IT_OBJECT);
PHB_ITEM pItem;
HWND hWnd;
LVITEM lvItem;
char text[250];
InitListViewItemData();
if(pListView==0 || hb_objGetClass(pListView)!=TListViewData.classId)
{
/*
if(pListView==0) MessageBox(NULL,"no parameter","Error",MB_OK);
else if(hb_objGetClass(pListView)!=TListViewData.classId)
{
sprintf_s(text,250,"parameter is not a TListView, it is a %i instead of %i",
hb_objGetClass(pListView),TListViewData.classId);
MessageBox(NULL,text,"Error",MB_OK);
}*/
hb_ret();
return; //invalid input
}
#ifndef _WIN64
hWnd = ( HWND ) hb_itemGetNL( hb_itemArrayGet(pListView,TListViewData.hWnd) );
#else
hWnd = ( HWND ) hb_itemGetNLL( hb_itemArrayGet(pListView,TListViewData.hWnd) );
#endif
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID | LVIF_INDENT | LVIF_STATE | LVIF_PARAM;
lvItem.pszText = text; *text=0;
lvItem.iItem = hb_parnl( 2 )-1;
sprintf_s(text,250,"%i - %i - %i",lvItem.iItem, hWnd,TListViewItemData.classId );
lvItem.iSubItem = HB_ISNUM(3) ? hb_parnl( 3 ) : 0;
lvItem.cchTextMax = 250;
lvItem.stateMask = (UINT)-1;
ListView_GetItem(hWnd,&lvItem);
hb_clsAssociate( TListViewItemData.classId );
pItem = hb_stackReturnItem();
//hb_itemArrayPut(pItem,TListViewItemData.oParent ,
hb_itemArrayPut(pItem,TListViewItemData.cText , hb_itemPutC(NULL, text));
//hb_itemArrayPut(pItem,TListViewItemData.cToolTip ,
hb_itemArrayPut(pItem,TListViewItemData.nImage , hb_itemPutNI(NULL, lvItem.iImage));
hb_itemArrayPut(pItem,TListViewItemData.nGroup , hb_itemPutNI(NULL, lvItem.iGroupId));
hb_itemArrayPut(pItem,TListViewItemData.nIndent , hb_itemPutNI(NULL, lvItem.iIndent));
hb_itemArrayPut(pItem,TListViewItemData.lChecked , hb_itemPutL(NULL, (lvItem.state & LVIS_SELECTED)!=0));
hb_itemArrayPut(pItem,TListViewItemData.nItem , hb_itemPutNI(NULL, lvItem.iItem));
if(lvItem.lParam != 0)
hb_itemArrayPut(pItem,TListViewItemData.Cargo , (PHB_ITEM)lvItem.lParam); // It is an item, change add.
}
#pragma ENDDUMP