Re: ? Create Not Called in Dialog for Subclassed Control
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 17 Dec 2008 16:33:47 -0500
See below...
On Wed, 17 Dec 2008 13:01:21 -0500, "Alec S." <nospam@xxxxxxxxx> wrote:
Okay, I'm baffled.****
I've created a control derived from CListCtrl. I want to have it set itself to
be a virtual list control (ie not have to use the resource editor to do that).
The problem is that LVS_OWNERDATA can only be applied when the control is
created, not changed later. The bigger problem is that because it's a subclassed
control in a dialog box, it does not get Create, OnCreate, or PreCreateWindow
called before it is subclassed, on PreSubclassWindow is called, and it is too
late at that point because it is already created.
So you create it at design time with the OwnerData flag.
PreSubclassWindow:
ASSERT(GetStyle() & LVS_OWNERDATA); // requires Owner Data style
You can also consider adding, instead,
OnInitDialog:
if( (list.GetStyle() & LVS_OWNERDATA) == 0)
{ /* not ownerdata */
DWORD style = list.GetStyle();
style |= LVS_OWNERDATA;
DWORD id = list.GetDlgCtrlId();
CRect r;
list.GetWindowRect(&r);
ScreenToClient(&r);
CMyListCtrl newctl;
newctl.Create(style, r, this, id);
newctl.SetWindowPos(&list, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
list.DestroyWindow();
list.Attach(newctl.Detach();
} /* not ownerdata */
Note that there is nothing that disallows having, for a short period of time, two controls
with the same ID, because, during the time when these two controls exist, nobody is trying
to access them by control ID.
Note that this trick CANNOT be used in the PreSubclassWindow handler because the
SubclassWindow function (that calls PreSubclassWindow) retains the original HWND of the
window, which this code would invalidate. You can also move this code into your subclass
and call in EnsureUserData, and therefore call
list.EnsureUserData();
you would just change a few parameters of the code to make it work in the context (such as
using GetParent() instead of this for the parent...)
*****
****
I have found a few posts where people explained the above points, but no
solutions were provided. I have also found a few pages in which people applied
the LVS_OWNERDATA style in PreCreateWindow or Create, but I can only assume they
were using a form-view instead of a dialog (or else the code wasn't tested and
didn't actually work).
Again, I'm stumped. How can I set a style of a control in a dialog at creation
if it is subclassed? (It is subclassed via the dialog?s DoDataExchange.)
You won't ever get a notification such as PreCreateWindow or OnCreate because the window
has already been created long before the subclassing
joe
****
Joseph M. Newcomer [MVP]
(I recently had VS put in the code for each of those functions then used
breakpoints to see which ones actually get called, and I could swear that at
least one of the create ones did, so I don't know why they are not getting hit
now.)
Thanks.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: ? Create Not Called in Dialog for Subclassed Control
- From: Alec S.
- Re: ? Create Not Called in Dialog for Subclassed Control
- References:
- ? Create Not Called in Dialog for Subclassed Control
- From: Alec S.
- ? Create Not Called in Dialog for Subclassed Control
- Prev by Date: Re: recurring mouse click messages
- Next by Date: Re: Getting ASSERT on one machine but NOT the other
- Previous by thread: Re: ? Create Not Called in Dialog for Subclassed Control
- Next by thread: Re: ? Create Not Called in Dialog for Subclassed Control
- Index(es):
Relevant Pages
|