It would be nice to be able to handle notification messages from the Header control embedded in the List View control (TListViewCtrl) using the response table, as we do for other notifications. For example:
DEFINE_RESPONSE_TABLE1(TMyDialog, TDialog)
EV_HDN_ITEMCHANGED(IDC_LISTVIEW, EvHdnItemChanged),
END_RESPONSE_TABLE;
However, this does not work. The Header embedded in List View is a child window of the latter and has its own ID, which defaults to 0. For lookup in the response table, 0 is not a valid ID.
To make it work, we must assign an ID to the Header control:
void TMyDialog::SetupWindow()
{
TDialog::SetupWindow();
const auto header = ListView.GetHeaderCtrl(); CHECK(header);
::SetWindowLong(header, GWL_ID, IDC_LISTVIEW);
}
This works fine, but it is cumbersome. It would be nice if TListViewCtrl could do this for us in its own SetupWindow.
Note that we here use the same ID for the Header as for its parent List View. This works in this instance, but may cause conflict in other situations. To allow the user to specify a distinct ID, it would be nice if we could simply pass it to the TListViewCtrl constructor, along with the ID for the List View. For example, add these overloads:
TListViewCtrl(TWindow* parent, int id, int headerId, const TRect&, TModule* = nullptr);
TListViewCtrl(TWindow* parent, int resourceId, int headerId, TModule* = nullptr);
Alternatively, if these overloads cause conflict with the existing constructors, we can use a std::pair for the IDs:
TListViewCtrl(TWindow* parent, std::pair<int, int> listAndHeaderIds, const TRect&, TModule* = nullptr);
TListViewCtrl(TWindow* parent, std::pair<int, int> resourceAndHeaderIds, TModule* = nullptr);
Commit: [r6302]
Discussion: Classes | TColumnHeaderDlg example
Wiki: Frequently_Asked_Questions
Wiki: OWLNext_Roadmap_and_Prereleases
Anonymous
This feature was implemented on the trunk in [r6297]. A typo in the documentation was fixed in [r6299]. Both revisions were merged into Owlet in [r6301].
Please review.
Related
Commit: [r6297]
Commit: [r6299]
Commit: [r6301]
Last edit: Vidar Hasfjord 2023-01-18