|
I created an MFC project, the interface is the way of left tree and right picture, and the operation results are displayed on the bottom right.
Now split the window into four sub-windows, and I want to display the results of each step on the bottom right. This is a CListView. I have no problem in initializing this control in the OnCreate method, but it always outputs unsuccessfully in my custom output function. , Followed up and found that it was an assertion error, the reason is that the hWnd obtained is empty, and it is puzzling, please everyone to advise.
code show as below:
int COpResultView :: OnCreate (LPCREATESTRUCT lpCreateStruct)
{
if (CListView :: OnCreate (lpCreateStruct) == -1)
return -1;
// Get ListCtrl control from ListView
CListCtrl&m_ListControl = GetListCtrl ();
// Set the ListCtrl style
m_ListControl.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES
| LVS_EX_HEADERDRAGDROP | LVS_EX_REGIONAL);
// Insert column name
m_ListControl.InsertColumn (0, "Host", LVCFMT_CENTER, 150);
m_ListControl.InsertColumn (1, "IP", LVCFMT_CENTER, 100);
m_ListControl.InsertColumn (2, "Port", LVCFMT_CENTER, 50);
m_ListControl.InsertColumn (3, "Operation", LVCFMT_CENTER, 200);
m_ListControl.InsertColumn (4, "time", LVCFMT_CENTER, 170);
m_ListControl.InsertItem (0, "BMW 317i");
m_ListControl.SetItemText (0,1, "Sport");
m_ListControl.SetItemText (0,2, "Germany");
m_ListControl.InsertItem (0, "Ford Fiesta");
m_ListControl.SetItemText (0,1, "Family");
m_ListControl.SetItemText (0,2, "USA");
return 0;
}
There is no problem with this method, but there is a problem with my custom output function.
void COpResultView :: ShowOpResult (CString hostname, CString IP, int port,
CString Result, CString time)
{
CListCtrl&m_ListControl = GetListCtrl ();
CString tempport;
tempport.Format ("% d", port);
m_ListControl.InsertItem (0, _T (hostname));
m_ListControl.SetItemText (0,1, _T (IP));
m_ListControl.SetItemText (0,2, _T (tempport));
m_ListControl.SetItemText (0,3, _T (Result));
m_ListControl.SetItemText (0,4, _T (time));
}
HWnd in this method m_ListControl is always empty and cannot be manipulated.
I have COpResultView OpResult in MainFrm; then call ShowOpResult ().
I don't know CListCtrl&m_ListControl = GetListCtrl (); Is there anything wrong, I don't know if it has something to do with the split of the form, please enlighten me, thank you. |
|