问题
I am having a bit of a problem when handling a HDN_ENDTRACKW message for a custom class which derives from CListCtrl .
Essentially, it seem that when this message is sent, the actual value which stores the width of the column is not updated until after my handling code has been executed.
The code inside the handle simply instructs a progress bar to resize, to fill the width of the resized column. The code:
void ProgListCtrl::OnEndTrack(NMHDR* pNMHDR, LRESULT* pResult)
{
int width = ListView_GetColumnWidth(GetSafeHwnd(), m_nProgressColumn);
ResizeProgressbar();
}
The ListView_GetColumnWidth is there just to help with debugging at the moment.
The default value for the particular column I am changing is 150, when i resize the column in the UI, this method is called but the width stays at the same 150, the progress bar does not resize. Only when a column is resized again does the width value now reflect the value of the column after the first resize, the ResizeProgressBar method then correctly changes the progbar size to fill the column it is in. This is continuous, the width value always seems to be one step behind the actual value.
I would apreciate any help. Cheers.
回答1:
Use the information that HDN_ENDTRACK itself provides to you, ie:
void ProgListCtrl::OnEndTrack(NMHDR* pNMHDR, LRESULT* pResult)
{
NMHEADER *pHdr = (NMHEADER*) pNMHDR;
if ((pHdr->iItem == m_nProgressColumn) &&
(pHdr->pitem) &&
(pHdr->pitem->mask & HDI_WIDTH))
{
int width = pHdr->pitem->cxy;
ResizeProgressbar();
}
}
Alternatively, look at the HDN_ITEMCHANGING
and HDN_ITEMCHANGED
notifications instead of HDN_ENDTRACK.
来源:https://stackoverflow.com/questions/1426665/problem-with-hdn-endtrack-when-resizing-a-list-column