Click here to Skip to main content
11,638,173 members (70,932 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/MFC
Hello MFC developers,

I tried to create a child window using:
CreateEx( NULL, NULL, "MyChild", WS_CHILD | WS_VISIBLE | WS_BORDER, 300, 300, 400, 200, hParentWnd, NULL, NULL );
Where the parent HWND hParentWnd has many other child windows already. However, this created a child window hiding behind all the siblings.
Windows Spy++ shows that it is on top (first) of the z-order among the child windows of hParentWnd. I have tried all different WIN32 commands including SetWindowPos(), BringWindowToTop(), SetForegroundWindow(), SetFocus(), SetActiveWindow(), SendMessage(WM_ACTIVATE, 0, 0), etc., but none brings it from behind the siblings.
When I replaced WS_CHILD by WS_OVERLAPPEDWINDOW in the CreateEX() function, the created non-child window has no problem showing as the topmost foreground active window.

So what must I do to get the child window to the top from behind the siblings?

Thanks a million.

Ernest.

========= more info to the question as follows ==========

Here is the code I used:

HWND hButtWnd = CreateWindowEx( WS_EX_STATICEDGE, "BUTTON", "MyButton", WS_CHILD | WS_VISIBLE,	buttRect.left, buttRect.top, 50, 60, m_hWnd, NULL, GetModuleHandle(NULL), NULL );
::EnableWindow(hButtWnd, FALSE);
CWnd* pChildWnd = new CWnd;
pChildWnd->CreateEx( NULL, NULL, "MyChild", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL, childRect, CWnd::FromHandle(m_hWnd), NULL, NULL );
pChildWnd->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

The first two lines create a new button MyButton among other pre-existing sibling windows. MyButton could be created after MyChild, but it didn't matter, MyChild still appeared hidden behind MyButton and all other siblings.

I could drag on the vertical scroll (I have WS_VSCROLL in the style) but MyChild could not be brought to the foreground. Always remained behind the siblings.

Disabling MyButton only greyed out MyButton, and MyChild still remained behind MyButton.

Windows Spy++ confirmed that the SetWindowPos() command did bring it to the top of the z-order; however, it was still behind all its siblings.

Thanks.

Ernest.
Posted 28-Feb-12 9:25am
Edited 29-Feb-12 6:10am
v5
Comments
André Kraak at 28-Feb-12 15:43pm
   
Edited question:
Added pre tags

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 jyo.net 322
1 Sergey Alexandrovich Kryukov 314
2 stibee 303
3 Mika Wendelius 185
4 Richard Deeming 180
0 OriginalGriff 9,051
1 Sergey Alexandrovich Kryukov 8,773
2 Mika Wendelius 7,034
3 Suvendu Shekhar Giri 2,425
4 F-ES Sitecore 2,408


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 29 Feb 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100