Board index » cppbuilder » List view columns' headers related events

List view columns' headers related events


2007-06-13 05:47:44 AM
cppbuilder101
Hi
I have a Custom listview component which already handles CN_NOTIFY for
custom drawing purpose and I need to add handling for HDN_TRACKA,
HDN_TRACKW, HDN_ENDTRACKA, HDN_ENDTRACKW.
After having try several way of doing it, I can not get it to work
The code for custom drawing is given below, my question is where to put
the code for the HDN_** events ?
in the .h
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(CN_NOTIFY, TMessage, CNNotify)
END_MESSAGE_MAP(TListView)
in the .cpp
MESSAGE void __fastcall TSmCustomListView::CNNotify(TMessage& Msg)
{
// QUESTION WHERE THE INSERT THE HDN_**** HANDLING RELATED CODE
LPNM_LISTVIEW lpnm = (NM_LISTVIEW *)Msg.LParam;
if ( lpnm && (lpnm->hdr.code == NM_CUSTOMDRAW) && (lpnm->hdr.hwndFrom
== this->Handle) )
{
LPNMLVCUSTOMDRAW lplvcd = (NMLVCUSTOMDRAW *)Msg.LParam;
if ( lplvcd )
switch(lplvcd->nmcd.dwDrawStage)
{
// prior to painting the items...
case CDDS_PREPAINT:
...
break;
// prior to painting each item
case CDDS_ITEMPREPAINT:
...
break;
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
...
break;
default:
{
Msg.Result = CDRF_DODEFAULT;
break;
}
}
}
else
TListView::Dispatch(&Msg); // Default processing
};
 
 

Re:List view columns' headers related events

"E B" < XXXX@XXXXX.COM >wrote in message
Quote
I have a Custom listview component which already handles
CN_NOTIFY for custom drawing purpose
Why aren't you using the custom-draw events instead? TListView
already has built-in support for the drawing notifications you are
processing manually.
Quote
After having try several way of doing it, I can not get it to work
That is because you are looking for the wrong message. CN_NOTIFY is a
wrapper for WM_NOTIFY messages that were sent to the ListView's parent
window in response to ListView actions. The HDN_... events, on the
other hand, are issued from the ListView's header and thus will arrive
as WM_NOTIFY messages to the ListView itself, as it is the parent
window of the header control.
Quote
The code for custom drawing is given below, my question is
where to put the code for the HDN_** events ?
You need a second message handler, ie:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(CN_NOTIFY, TMessage, CNNotify)
VCL_MESSAGE_HANDLER(WM_NOTIFY, TMessage, WMNotify)
END_MESSAGE_MAP(TListView)
MESSAGE void __fastcall TSmCustomListView::CNNotify(TMessage& Msg)
{
// custom-drawing code here...
}
MESSAGE void __fastcall TSmCustomListView::WMNotify(TMessage& Msg)
{
NMHDR *pnmh = (NMHDR*) Msg.LParam;
switch( pnmh->code )
{
case HDN_TRACKA:
//...
break;
case HDN_TRACKW:
//...
break;
case HDN_ENDTRACKA:
//...
break;
case HDN_ENDTRACKW:
//...
break;
}
TListView::Dispatch(&Msg); // Default processing
}
Gambit
 

Re:List view columns' headers related events

E B < XXXX@XXXXX.COM >wrote:
Quote

In addition to what Gambit offered, be aware that TListView
is just a wrapper around an MS control and as such, it
hasn't been updated since prior to XP. Consequently, there
are a couple of bugs with custom message handling and XP (and
I presume Vista as well).
If you use google groups to search this group or the
vcl.writing group, I've posted code that demonstrates
how to subclass the Header's WndProc and if IRC, it
also includes many extra's like handling custom painting
with gradients ect..
~ JD
 

{smallsort}

Re:List view columns' headers related events

thank you for your answer it works fine.
I have another question
I want to resize a panel when columns resize ends
here is the code
case HDN_ENDTRACKA:
case HDN_ENDTRACKW:
pnFilter0->Width = ListView->Columns->Items[ 0 ]->Width;
break;
The problem is that ListView->Columns->Items[ 0 ]->Width has not been
updated yet. Its value is the initial width of the column (before resize).
Note : there are only 2 col in the list
How can I get the new width of the colum ?
 

Re:List view columns' headers related events

"E B" < XXXX@XXXXX.COM >wrote in message
Quote
The problem is that ListView->Columns->Items[ 0 ]->Width has
not been updated yet.
Pass the message to the base class Dispatch() first. Then it will be.
Quote
How can I get the new width of the colum ?
If you need the new width before passing the message to Dispatch(),
then you will have to extract the value from the HDN_ENDTRACK
notification directly instead. Look at the MSDN documentation for how
to do that. Keep in mind that TListColumn has MinWidth and MaxWidth
properties that the notification does not take into account, though,
as they are applied at the TListView level when it processes the
notifications.
Gambit
 

Re:List view columns' headers related events

thank you very much your answers really helped me