Problem with ShowWindow() and losing focus
-
Hi, I have MFC application with splitter window that divides client area to two views, both are CListView-derived classes. Because I want to keep columns to have stable proportions all the time, I'm catching CMyListView::OnSize() and executing this code: void CMyFileView::OnSize(UINT nType, int cx, int cy) { int my_cx = cx; INT iWidth = 0; RECT viewRect; ::ZeroMemory(&viewRect, sizeof(RECT)); GetClientRect(&viewRect); INT iViewLen = viewRect.right - viewRect.left; CMultiColumnSortListView::OnSize(nType, cx, cy); // disable horizontal scroll bar GetListCtrl().ShowScrollBar(SB_HORZ, FALSE); INT iColWidth = 0; if (cx != old_cx) { GetListCtrl().ShowWindow(SW_HIDE); for (INT i = 0; i < (COLUMN_NUM - 1); i++) { iColWidth = viewRect.right * COLUMN_WIDTHS[i]; iWidth += iColWidth; GetListCtrl().SetColumnWidth(i, (viewRect.right * COLUMN_WIDTHS[i])); } GetListCtrl().SetColumnWidth((COLUMN_NUM - 1), (iViewLen - iWidth)); GetListCtrl().ShowWindow(SW_SHOW); } } old_cx = cx; } I call ShowWindow() in order to stop flickering, it helped. The problem is, calling ShowWindow() deselectes selected item (selected before with SetItemState()). I tried to call SetItemState() again after ShowWindow(SW_SHOW), but it doesn't work as expected, it highlights item, but it doesn't select and focus it 100% (it just draw grey rectangle aroung the item, but doesn't display dark blue rectangle which appears in normal case). Does somebody know what to do to select and focus the item again successfully? Thanks for any suggestion.