Re: Getting notification for dynamically added controls
On Tue, 12 Feb 2008 16:00:16 -0800, Zapanaz
<http://joecosby.com/code/mail.pl> wrote:
In resource.h I added this:
#define ID_DBLISTCTRL_FIRST 20000
#define ID_DBLISTCTRL_LAST 20999
UINT nextId = parentApp->GetNextDbListCtrlId();
myDbList->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,
initialRect, this, nextId);
I changed the message map for DbListCtrl to this:
BEGIN_MESSAGE_MAP(DbListCtrl, CListCtrl)
//{{AFX_MSG_MAP(DbListCtrl)
//}}AFX_MSG_MAP
ON_CONTROL_RANGE(NM_CLICK, ID_DBLISTCTRL_FIRST, ID_DBLISTCTRL_LAST, OnClickAny)
END_MESSAGE_MAP()
Then I added a function
void DbListCtrl::OnClickAny(UINT sourceId)
{
int test = sourceId;
}
But when I open a new DbListCtrl, and click on a row (this is a
report-view style CListCtrl), it doesn't enter OnClickAny.
OK I am getting a handle on this ...
There were two things wrong, one is that rather than adding the
message handler to the DbListCtrl, it was supposed to be added to the
parent window. I am still fairly new to Windows programming, I didn't
know about the idea of message reflection.
The other thing I am not quite sure I get yet ...
I changed to the ON_NOTIFY_RANGE() macro instead of ON_CONTROL_RANGE()
, and then it worked.
I am not sure if this was a problem ... I am still changing a lot of
things around and I need to pin down exactly what changes were helpful
and what weren't.
But using ON_NOTIFY_RANGE and moving the control function and message
map entry to the parent window, causes this to work.
***
Thanks again for the help, everybody. Without Usenet I would never
have been able to make this project work, or not in the time I have
had for it anyway.
--
Joe Cosby
http://joecosby.com/
"It is the doom of men that they forget"
:: Currently listening to Naima, 1997, by McCoy Tyner, from "The Definitive McCoy Tyner"