SetParent() on a control

M

miben

I am creating a ListView through CreateWindowEx(). It works fine when
I create it as a child window as so:

hControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
WS_VISIBLE | WS_CHILD | LVS_REPORT, 300, 100, 100, 100, hWnd, NULL,
NULL, NULL);

However, I want to create the control with no parent, then add it to
the parent form later. Something like this...

hControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
LVS_REPORT, 300, 100, 100, 100, NULL, NULL, NULL, NULL);

SetParent(hControl, hWnd);

The drawing of the ListView in that code goofs up the window drawing.
I played arround a bit and came up with this:

hControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
WS_POPUP, 100, 100, 100, 100, NULL, NULL, NULL, NULL);

SetParent(hControl, hWnd);

dwStyle = GetWindowLong(hControl, GWL_STYLE);
dwStyle &= ~(WS_CLIPSIBLINGS | WS_POPUP);
dwStyle |= WS_CHILD | WS_VISIBLE | LVS_REPORT;

SetWindowLong(hControl, GWL_STYLE, dwStyle);
ShowWindow(hControl, SW_SHOW);

This works for the drawing, but if you right click in the header area,
you will get a stack error. Any ideas?
 
G

Gavin Deane

I am creating a ListView through CreateWindowEx(). It works fine when
I create it as a child window as so:

hControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
WS_VISIBLE | WS_CHILD | LVS_REPORT, 300, 100, 100, 100, hWnd, NULL,
NULL, NULL);

However, I want to create the control with no parent, then add it to
the parent form later. Something like this...

hControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
LVS_REPORT, 300, 100, 100, 100, NULL, NULL, NULL, NULL);

SetParent(hControl, hWnd);

The drawing of the ListView in that code goofs up the window drawing.
I played arround a bit and came up with this:

hControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
WS_POPUP, 100, 100, 100, 100, NULL, NULL, NULL, NULL);

SetParent(hControl, hWnd);

dwStyle = GetWindowLong(hControl, GWL_STYLE);
dwStyle &= ~(WS_CLIPSIBLINGS | WS_POPUP);
dwStyle |= WS_CHILD | WS_VISIBLE | LVS_REPORT;

SetWindowLong(hControl, GWL_STYLE, dwStyle);
ShowWindow(hControl, SW_SHOW);

This works for the drawing, but if you right click in the header area,
you will get a stack error. Any ideas?

None of this is standard C++. There's no guarantee that people here
will recognise any of your code. You'll have much better luck asking in
a Windows programming newsgroup.

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Gavin Deane
 
V

Victor Bazarov

I am creating a ListView through CreateWindowEx(). It works fine when
[...]

However, I want to create the control with no parent, then add it to
the parent form later. Something like this...

[...]

This works for the drawing, but if you right click in the header area,
you will get a stack error. Any ideas?

You're in a wrong newsgroup. Try 'microsoft.public.vc.mfc'.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top