May 07, 2024, 10:25:28 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


getting information from a Clistview derived class

Started by Haim, July 18, 2006, 10:19:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

Hi all.
I created a class derived from  Clistview.
I use the OnLButtonDown method of that class to obtain information on which item/subitem is being clicked.
Currently I use the OnNotify method of the parent window to detect a click on a column header.
How can I detect a click on a column header directly from the class - without having to use the parent window?
Any help would be appreciated.

Haim

Ionic Wind Support Team

July 18, 2006, 11:06:59 PM #1 Last Edit: July 18, 2006, 11:09:18 PM by Paul Turley
Controls send their parent the notification messages. Which is how the common controls are designed. They don't get the message first unfortunately.  I've always thought of it as a weird design but the gurus at Microsoft strive to keep a strict parent/child relationship.

You could reflect the message back to the child control,  But you would still need to process the message in the parent window/dialog first.  The nID parameter of the OnNotify handler contains the ID of the control sending the notification message, so you can get a pointer to the control class using GetControl.  Then either send it a message, or call a method.  Something like this:

Parent::OnNotify(int code,int nID,NMHDR *pnmhdr),int
{
CControl *pControl = GetControl(nID);
if(code = LVNCOLUMNCLICK)
{
*(MyListView)pControl->HandleClick(*(NMLISTVIEW)pnmhdr.iSubItem);
                  //alternatively
                  //SendMessageA(pControl->m_hWnd, MY_CLICKED_MESSAGE, 0,*(NMLISTVIEW)pnmhdr.iSubItem);
                 return true;
}
return CWindow!!OnNotify(code,nID,pnmhdr);
}

Which is kind of how MSVC++ handles message reflection.  The second alternate using SendMessageA depends on you creating your own registered message ID. 

Also you should always call the base class OnNotify as I did above on return.  Otherwise OnControl might not function for certain messages.

Paul.

Ionic Wind Support Team

Haim

Thanks,
Actually I was toying with the idea of encapsulation, trying to create an independent class that can be aware of everything that happens to it and respond to all events... I was hoping there was some easy way of doing thiis.
As I understand now, I have two major alternatives: either reflect the notification back to the control or
defining the class so that it contains both a Cwindow to serve as a parent window and a Clistview.
Many things to explore  :)

Haim