我在一个单文档程序中动态添加了一个CListCtrl控件ID为m_ListCtrl,是通过右键菜单添加的,添加之后m_ListCtrl不是处在激活状态,我使用了m_ListCtrl.BringWindowToTop()使它获得了焦点,但m_ListCtrl却无法显示,如果不用m_ListCtrl.BringWindowToTop(),m_ListCtrl可以显示,但不是处在激活状态。如果能够使m_ListCtrl创建后就处在激活状态而且能显示出来呢?
调试欢乐多
if(mm_ListCtrl)
{
mm_ListCtrl.DestroyWindow();
}
CWnd *CFrmWnd=AfxGetMainWnd();
CFrmWnd->SetFocus();
CFrmWnd->GetClientRect(rect);
rect.top+=3;
CStatic mm_Static;
mm_ListCtrl.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,rect,CFrmWnd,1); CFrmWnd->GetClientRect(rect); //mm_ListCtrl.SetBkColor(RGB(177,151,240));
mm_ListCtrl.SetTextColor(RGB(0,0,0));
//mm_ListCtrl.SetTextBkColor(RGB(177,151,240));
mm_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
mm_ListCtrl.InsertColumn(0,_T("右键标准编号"),LVCFMT_LEFT,100);
mm_ListCtrl.InsertColumn(1,_T("右键标准名称"),LVCFMT_LEFT,100);
mm_ListCtrl.BringWindowToTop();
CString str;
for(int i=0;i<4;i++)
{
str.Format("编号%d",i+1);
mm_ListCtrl.InsertItem(i,str);
str.Format("房间%d",i+1);
mm_ListCtrl.SetItemText(i,1,str);
}以上是我的代码,运行后mm_ListCtrl无法显示
改为:
mm_ListCtrl.ShowWindow(SW_SHOW);
我现在的程序通过右键菜单可以显示listctrl,但是它没被激活,因为它的表头无法通过鼠标拉动来改变其长度。