Click to See Complete Forum and Search --> : how to add message-map entry for dynamically created control (created at runtime) ???


gerd wagner
July 19th, 1999, 04:09 AM
hi there!
i have a dialog on which i create a lot of CListCtrl's at runtime and want to be able to respond to selchange messages or whatever.... how do i implement
a handler for these controls?
TIA
gerd wagner

Fabi Pantera
July 19th, 1999, 06:05 AM
First of all I don't understand why can't you reuse the CListCtrl that yiou created (just to change their stayles, position, etc).
Now, if you really want to dynamically add a message handler, you can use the ON_COMMAND_RANGE(id1, id2, function) macro to add a handler from ID1 to ID2. In the "function" you have to treat every ID in a switch (or whatever).
The IDs that you gave to the dynamically listCtrl, should be in order from id1 to <id2.
Let me know if this helps you.
Best regards,
Faby

gerd wagner
July 19th, 1999, 07:30 AM
hi faby!
thanks for your quick response ;-)

>First of all I don't understand why can't you reuse the CListCtrl that yiou created (just to change their
>stayles, position, etc).

it's a dialog with a userdefined amount of CListCtrl's... all CListCtrl's are visible at the same time and should respond to user interaction... how could i reuse 1 CListCtrl for all ListCtrls on screen? please advise!

>Now, if you really want to dynamically add a message handler, you can use the
>ON_COMMAND_RANGE(id1, id2, function) macro to add a handler from ID1 to ID2. In



just found this out ;-) thanks for confirming that i'm on the right way... but had no luck so far...

(oops... just noticed that i use

ON_CONTROL_RANGE(NM_DBLCLK,2000,2050, OnDblclkListCtrl)

and not ON_COMMAND_RANGE
will have a try at ON_COMMAND_RANGE now ;-)
)

i create my CListCtrls in InitDialog and give them ControlID's.
first i tried the UPPER BOUNDARY for control ID's -> that's 0xdfff subtracting the amout of CListCtrls that i want to use.. for the range of control id's but my handler doesn't get called....
(i put a AfxMessageBox inside so i can see if it gets called)
are there rules for reserving ControlID Ranges? ) next try was with id's in the range of 2000-2050 (50 CListCtrl's) no luck...
the ID's are unique to my app ofcourse, so they cant get confused with id's of other controls...)
any idea what i'm missing?
thanks again
bye


The Matrix Has You...

Fabi Pantera
July 19th, 1999, 07:44 AM
1. You're right!
For the IDs use values after WM_USER. You can use something like that:
#define MY_ITEMS WM_USER+1
In the InitDialog just initialize with MY_ITEMS+nCount.
It should work. (it works OK for me).
It is?
Regards,
Same Faby

gerd wagner
July 19th, 1999, 08:21 AM
ok, i found it... :)

it's
ON_NOTIFY_RANGE(NM_DBLCLK,IDC_ZIMMERLISTCTRLBASEID,IDC_ZIMMERLISTCTRLBASEID+ANZAHLZIMMERDIEMESSAGESABFANGEN, OnDblclkListCtrl)

but there's an extra catch ;-)
the handler function does receive an additional parameter (the id of the control) so the handler function definition looks like:

afx_msg void OnDblclkListCtrl(UINT id, NMHDR* pNMHDR, LRESULT* pResult);

>For the IDs use values after WM_USER. You can use something like that:
>#define MY_ITEMS WM_USER+1

sure? i thought WM_USER is a base value for MESSAGES and not for Control ID's...!?

thanks for your help
gerd wagner


The Matrix Has You...

Fabi Pantera
July 19th, 1999, 08:33 AM
1. The NOTIFY_RANGE come from your context (didn't know your context exactly). I used COMMAND_RANGE for some dynamically menu items on the mainframe.
2. WM_USER+something - you can use it as an ID, but also as a WM_COMMAND. TRy it and let me know.

Regards,
Same Faby