Project: MFC-SDI-C ++ (VS2012)
Hi everybody Im new programming in MFC i have the next:
1. I have built a CListCtrl-looking as a report on a CDialog (The CListCtrl was added using the controls toolbox). The CDialogEx is on a CDockablePanel that are created when the program is opened and always is showed. I added columns and items to CListCtrl to be created without any problems
(Class: CCoordsListDlg).
2. I have created a different class that generate double type data
(Class: CCoordsGenerator). These data are generated catching the mouse click screen coordinates without any problems. These data should be added on the the CListCtrl as subitems.
3. To add the generate data on the CListCtrl, i have a method that is called from the CCoordsGenerator class but when the method that add the subitems run a DEBUG ASSERTION appears.
4. The DEBUG ASSERTION stop in:
ASSERT(::IsWindow(m_hWnd)); of the winctrl2.cpp file in the next section:
BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0);
LVITEM lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPTSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXT, nItem, (LPARAM)&lvi);
}
The class code where the CListCtrl is created is the next
(CCoordsListDlg.cpp):
BOOL CCoordsListDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
CListCtrl m_coordslist;
m_coordslist.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SINGLEROW |LVS_EX_GRIDLINES|LVS_SHOWSELALWAYS);
m_coordslist.InsertColumn(0,"point");
m_coordslist.SetColumnWidth(0,90);
m_coordslist.InsertColumn(1,"x coord");
m_coordslist.SetColumnWidth(1,64);
m_coordslist.InsertColumn(2,"y coord");
m_coordslist.SetColumnWidth(2,64);
m_coordslist.InsertItem(0,"p1");
m_coordslist.InsertItem(1,"p2");
m_coordslist.InsertItem(2,"p3");
m_coordslist.InsertItem(3,"p4");
return TRUE;
}
A portion of the code where the data are generated is
(CCoordsGenerator.cpp):
void CCoordsGenerator::OnLeftButtonDown()
{
double q[2];
picker->GetPickPosition(q);
x_coord = q[0];
y_coord = q[1];
CCoordsListDlg m_coordDlg;
m_coordDlg.RWImageInteractor(row, x_coord, y_coord);
createSpherePoint(row, x_coord,y_coord);
}
The method of the class
CCoordsListDlg that add the subitems is:
void CCoordsListDlg::RWImageInteractor(int row, double x_coord, double y_coord)
{
char x_buff[8],
y_buff[8];
_gcvt(x_coord,8,x_buf);
_gcvt(y_coord,8,y_buff);
m_coordslist.SetItemText(row,1,x_buff);
m_coordslist.SetItemText(row,2,y_buff);
}
Could you help me to understand where my error is?
Thank you all so much for your help
Regards
What I have tried:
really I don´t know what is the trouble with my code. I've tried to use the LVITEM methosd to add the subitems and put progamatically the focus on the CListCtrl but the assertion always appears.