I'm a newbie with MFC. Here's my function. I modified your code a little:
//Here's your function:
BOOL ListCtrlEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
HD_NOTIFY *pHDN = (HD_NOTIFY*)lParam;
if( (pHDN->hdr.code == HDN_BEGINTRACKW || pHDN->hdr.code == HDN_BEGINTRACKA) )
{
if(GetColumnWidth(pHDN->iItem) == 0) // when the size of the column is 0, we want to hide
{ // this column and prevent the resizing of the column
*pResult = TRUE; // disable tracking
return TRUE;
}
else
{
return FALSE;
}
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
//And my function:
void ListCtrlEx::SizeColumnsToText()
{
const int COL_SEPARATION = 8; // extra pixels to account for list control grid
int MINCOLWIDTH = 10;
int nCol = 0; // Column iterator
int MaxColWidth = 0; //initializing at zero
BOOL bSubImage = FALSE;
SetRedraw(FALSE);
for (nCol; nCol < m_nColumnCount; nCol++)
{
//int temp = GetColumnWidth( nCol );
if (int temp = GetColumnWidth( nCol ) == 0)
ListCtrlEx::OnNotify( wParam, lParam, pResult );
//SetColumnWidth( nCol, 0 );
else
{
int ColWidth1 = GetColumnWidth( SetColumnWidth( nCol, LVSCW_AUTOSIZE_USEHEADER ) );
int ColWidth2 = GetColumnWidth( SetColumnWidth( nCol, LVSCW_AUTOSIZE ) );
if( ColWidth1 > MINCOLWIDTH || ColWidth2 > MINCOLWIDTH )
MaxColWidth = max( ColWidth1, ColWidth2 );
else
MaxColWidth = MINCOLWIDTH;
if (bSubImage = TRUE)
SetColumnWidth( nCol, MaxColWidth + COL_SEPARATION + 15 );
else
SetColumnWidth( nCol, MaxColWidth );
}
}
SetRedraw(TRUE);
}
I'm not sure how to implement this. Please help.
Thanks!
Reply
Originally posted by: Joe
Thank you, for your article. It have a good result in my application.
ReplyOriginally posted by: Gregory J. Spiers
NOTE THAT WE CAN ONLY APPLY INDIVIDUAL RESIZING TO COLUMNS
Turn bits on for columns not to be resized, or off for
Handling the column resize calls works like this:
BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
switch (((NMHDR*)lParam)->code)
// Set mask to identify coumn
// Ensure that the column specified is less than the bits of a DWORD
// Do not resize any column without permission
break;
Sometimes it would be handy to specify any combination of
columns that are not to be resized. To accomplish that
with the solution described in the main topic, we only
need to have a member variable as part of our derived
class that will hold a bit for each column indicating
whether or not it can be resized.
THAT MATCH BITS IN OUR MEMBER VARIABLE MASK
(a DWORD can represent 32 columns, a BYTE can represent 8).
columns that will resize. The rightmost bit represents
column 0 and the leftmost bit is the largest column
number we can control.
{
HD_NOTIFY *pHDN = (HD_NOTIFY*)lParam;
{
// Is this a resize request?
case HDN_BEGINTRACKW: // drag column to resize
case HDN_BEGINTRACKA:
case (HDN_DIVIDERDBLCLICKA): // double click column to resize
case (HDN_DIVIDERDBLCLICKW):
DWORD dwMaskedItem = 0L; // Set to 0 before we apply the mask
if (pHDN->iItem < 32)
{
// and set the value of the bit corresponding to the specified column
dwMaskedItem = (0x01 << pHDN->iItem);
}
dwMaskedItem &= m_dwNoSizeCols; // AND with member variable holding the column mask
if (dwMaskedItem != 0L)
{ // Must be a non-resizing column, so we..
*pResult = TRUE; // Tell our program that we processed the message and..
return TRUE; // return
}
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
Originally posted by: vidya
It worked fine. Really good. But how the same thing can be done in win32 application?
ReplyOriginally posted by: Kapil Arya
It was too good, I was searching for it, and found on the right time, Thankx for Ur effort, Keep Writing these type of code
Originally posted by: Wiseguy
Im having a litle problem subclassing the ListView. The example above is for mfc but how do i do this in win32. Please can any ine help?
Reply
Originally posted by: venkatesh
Colud you tell me how to restrict resizing the column header if the list control is added on a ATL dialog.
Originally posted by: cromianha
What ? ->
HDN_BEGINTRACKW ?, HDN_ENDTRACKA ?
Originally posted by: aisha
I do have the same problem as of shinoj, saving the column widths, can anybody help??
ReplyOriginally posted by: Girish
Notify message is sent always to the parent window when you add this piece of code in the Message notification and if you are trying to add some string to a edit control on the NM_CLICK event of your list control the string to the edit control will not be added
Reply