Re: SubClassDlgitem question
Try CWnd::SubclassWindow.
Re: SubClassDlgitem question
What is the context of your call to SubclassDlgItem ()? Are you calling it from within a dialog, or, a control class? Please post appropriate code.
Re: SubClassDlgitem question
Hi .. Thanks for the reply.
I'm implementing this from within the main dialog class of my dialog based app.
Im trying to subclass using 'CColorStaticST', a class which does exactly what I want that I found here on CodeGuru.
My code looks like this:
Code:
for(i=0; i<(m_GridXSize * m_GridYSize); i++)
{
if((i % m_GridXSize) == 0 && (bFirst == FALSE))
{
SlabRect.top = SlabRect.top + m_SquareSize;
SlabRect.bottom = SlabRect.bottom + m_SquareSize;
SlabRect.left = 50;
SlabRect.right = SlabRect.left + m_SquareSize;
}
m_NumberGrid.Add(new CColorStaticST());
((CColorStaticST*)m_NumberGrid.ElementAt(i))->Create(" ",WS_CHILD |WS_BORDER|WS_VISIBLE, SlabRect, this);
((CColorStaticST*)m_NumberGrid.ElementAt(i))->SubclassDlgItem(/*NEED TO PUT MY OBJECTS HANDLE HERE */, this);
SlabRect.OffsetRect(m_SquareSize,0);
bFirst = FALSE;
}
The author of CColorStaticST obviously intended that a CStatic drawn on the dialog would be used.
Hope you can help.
Thanks for your time
Phil
Re: SubClassDlgitem question
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.
Re: SubClassDlgitem question
It looks like he's saving them in m_NumberGrid.
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().
Re: SubClassDlgitem question
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
Re: SubClassDlgitem question
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".
Re: SubClassDlgitem question
Code:
// from wincore.cpp
BOOL CWnd::SubclassDlgItem(UINT nID, CWnd* pParent)
{
HWND hWndControl = ::GetDlgItem(pParent->m_hWnd, nID);
if (hWndControl != NULL)
return SubclassWindow(hWndControl);
...
}
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.
Re: SubClassDlgitem question
I should have read the whole thread.
Re: SubClassDlgitem question
Guys..
Thank you both very much.. Ive tried it both ways and both work well.
Now I can get on !!
thanks again for your help
Cheers
Phill:thumb: