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.