Im hoping someone can help me with something.
I want to call SubClassDlgitem() against an object that I have just dynamically creted, so I have a pointer to the item.(its a Cstatic object in fact).
I thought I would be able to get this from the Hwnd, but I dont think I can now.
Does anyone know how I can get the handle to the object I have just created??
Looking around a bit, it seems it may be rather orkward..
You're going to need to save the pointer to the newly created static control so that you can use it in the call to SubclassDlgItem. More importantly, as written, your code allows for a memory leak because you are creating those controls on the heap and do not retain a pointer to them so their memory can be released when they are no longer needed.
The nID you need is part of the CStatic::Create() method. It has a default of 0xffff as coded above. You need to supply one, then use it in your call to SubclassDlgItem().
H guys..
Thanks for the reply.
yep hoxiew I have the pointers in the m_numberGrid aray.
Are you suggesting that I invent an ID dynamically and suplly it to both the Create and SubClassDlgItem methods ?? If so, is it sufficient to just add 1 to the default each time through the loop ??
Ill look into that when I get back to my desk!
Thanks again
Phill
You can assign them any ID you'd like as long as they don't conflict with other dialog controls IDs. When you use a dialog template resource to create controls, VS does this automatically for you and keeps track of them in the resource.h file. You can add a range of your own IDs to this file using the "Resource Symbols" wizard. You can access this from the "Resources" tab by right-clicking on the <YourAppName>.rc entry and selecting "Resource Symbols".
After generating unique item ID, you can use SubclassDlgItem, which effectively calls SubclassWindow. You can call SubclassWindow without item ID, as I suggested in my first post.
Bookmarks