| |

VerySource

 Forgot password?
 Register
Search
View: 790|Reply: 4

Regarding the issue of CListView and form split, please advise, thank you.

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Unknown

Post time: 2020-2-19 17:30:01
| Show all posts |Read mode
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.
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-5 23:00:01
| Show all posts
COpResultView OpResult;

????
How do you show it? ? ? If not ShowOpResult...
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-6 18:00:01
| Show all posts
It is to instantiate an object and then call its method OpResult.ShowOpResult() to insert the display result. Is there any problem?
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-8 14:45:01
| Show all posts
I mean, how did your view show up?


"Just by instantiating an object and then calling its method OpResult.ShowOpResult() to insert the display result"

How can there be such a view? Without calling OpResult.ShowOpResult(), do you see the view displayed? !
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-19 19:00:01
| Show all posts
Hey, I displayed it when I split the form.
    m_rightSplitter.CreateView(1,0,RUNTIME_CLASS(COpResultView),
CSize((rc.Width()-200),rc.Height()*3/10), pContext);
Several rows have been inserted when creating the view, which is normal, but it fails when OpResult.ShowOpResult() is called later, hWnd is empty, and the problem lies here. Hope you can correct me.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list