简体   繁体   English

检测CListCtrl列的大小调整

[英]Detecting CListCtrl column resizing

I have a pretty simple dialog containing basically a CListCtrl in report mode with several columns and with a header. 我有一个非常简单的对话框,基本上在报表模式下包含一个CListCtrl ,其中包含几列和标题。

Now I need to detect when the user has resized a column and I hoped that OnHdnChanged would be called each time the user has resized a column. 现在,我需要检测用户何时调整了列的大小,并希望每次用户调整列的大小时都会调用OnHdnChanged

Amoungst others I have this in my message map, IDC_LIST1 being the id of the list control. 在其他消息中,我的消息映射中包含IDC_LIST1它是列表控件的ID。

ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList)
ON_NOTIFY(HDN_ENDTRACKW, IDC_LIST1, OnHdnChanged)

OnHdnChanged function: OnHdnChanged函数:

void CMyDlg::OnHdnChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
  ...
  *pResult = 0;
}

void CSanDlg::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
{
  ...

OnItemchangedList is called when exepected, but OnHdnChanged is not. OnItemchangedList exepected时被调用,但OnHdnChanged不是。 I supposed OnHdnChanged is not called because the header control's parent is not my dialog but it's the list control. OnHdnChanged没有调用OnHdnChanged因为标头控件的父级不是我的对话框,而是列表控件。

Does anybody know what I can do? 有人知道我能做什么吗?

I was just looking at this old article , which suggests changing the ON_NOTIFY to ON_NOTIFY(HDN_ENDTRACKW, 0, OnHdnChanged) , since the control ID of the header control seems always to be 0. 我只是在看这篇旧文章 ,它建议将ON_NOTIFY更改为ON_NOTIFY(HDN_ENDTRACKW, 0, OnHdnChanged) ,因为标头控件的控件ID似乎始终为0。

I don't know if that's still true, but it's worth checking. 我不知道这是否仍然正确,但是值得检查。


Edit: Updating based on responding comment. 编辑:根据响应评论进行更新。 Here 's another suggestion I came across, which is subclassing the CListCtrl and handling the notification there. 是我遇到的另一个建议,它是CListCtrl子类并在那里处理通知。 Presumably that handler could delegate actual handling logic to its parent. 大概该处理程序可以将实际的处理逻辑委托给其父级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM