Answered by:
Avoid Resizing of column header for listcontrol in MFC

Question
-
Hi,
How to avoid resizing of column header of a listcontrol in report view, without changing the attributes in the listcontrol contents(i.e i have implemented text colors in the contents only resizing of column should avoided). I am using VS2003 MFC Dialog based application.
Please do suggest me with some lines of codes.
Friday, April 1, 2011 4:17 AM
Answers
-
BOOL CHeaderFixedListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { HD_NOTIFY *pHDN = (HD_NOTIFY*)lParam; //1st and 2nd coloumns are fixed by the following code. Add as many you want if((pHDN->hdr.code == HDN_BEGINTRACKW || pHDN->hdr.code == HDN_BEGINTRACKA) && ((pHDN->iItem == 1) || pHDN->iItem == 2 )) { *pResult = TRUE; return TRUE; } return CListCtrl::OnNotify(wParam, lParam, pResult); }
Knowledge is like light; It spreads only when you have clear and transparent mind.- Proposed as answer by Nikita Leontiev Friday, April 1, 2011 9:35 AM
- Marked as answer by lucy-liu Thursday, April 7, 2011 8:23 AM
Friday, April 1, 2011 4:52 AM
All replies
-
BOOL CHeaderFixedListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { HD_NOTIFY *pHDN = (HD_NOTIFY*)lParam; //1st and 2nd coloumns are fixed by the following code. Add as many you want if((pHDN->hdr.code == HDN_BEGINTRACKW || pHDN->hdr.code == HDN_BEGINTRACKA) && ((pHDN->iItem == 1) || pHDN->iItem == 2 )) { *pResult = TRUE; return TRUE; } return CListCtrl::OnNotify(wParam, lParam, pResult); }
Knowledge is like light; It spreads only when you have clear and transparent mind.- Proposed as answer by Nikita Leontiev Friday, April 1, 2011 9:35 AM
- Marked as answer by lucy-liu Thursday, April 7, 2011 8:23 AM
Friday, April 1, 2011 4:52 AM -
Hi Sreedhar, How do I use for dialog based applications.
Below is my problem.
I am working on a CDHTMLDialog based application where I ahve added a CListCtrl as shown below.
The list control has only one column.
IDD_TEST_DIALOG DIALOGEX 0, 0, 419, 286
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CONTROL "",IDC_LIST_TEXT,"SysListView32",LVS_REPORT | LVS_OWNERDATA | LVS_NOSORTHEADER | NOT WS_VISIBLE | WS_BORDER | WS_TABSTOP,20,143,397,136
END
The problem is that I can drag the colum header to extreme left and the column goes hidden. To bring it back I will have to again drag the column header to the right.
I want to prevent resizing of this column so that the user cannot drag this completely to the left and make it hidden.
I did try the following code but it is not working.
void CMyTestDlg::OnHDNEndtrackListLog(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
// TODO: Add your control notification handler code here
if(m_ListCtrl.GetColumnWidth(0) < 100)
{
m_ListCtrl.SetColumnWidth(0, 500);
}
*pResult = 0;
}
Since I have very less time to implement this, I request you kindly give me some examples from MFC Dialog based applications.Wednesday, February 8, 2012 7:03 PM -
What would be the consequences of "m_list.GetHeaderCtrl()->EnableWindow(FALSE);" ?Tuesday, July 24, 2012 5:48 AM