儿童窗口由兄弟窗口重叠 [英] Child window overlapped by sibling windows
问题描述
Hello MFC开发人员,
我尝试使用以下方法创建子窗口:
CreateEx( NULL,NULL, MyChild,WS_CHILD | WS_VISIBLE | WS_BORDER, 300 , 300 , 400 , 200 ,hParentWnd,NULL,NULL);
其中父 HWND hParentWnd
还有很多其他孩子窗户已经。然而,这创建了一个隐藏在所有兄弟姐妹后面的子窗口。
Windows Spy ++显示它位于 hParentWnd <子窗口中z顺序的顶部(第一个) / code>。我尝试了所有不同的WIN32命令,包括
SetWindowPos()
, BringWindowToTop()
, SetForegroundWindow( )
, SetFocus()
, SetActiveWindow()
, SendMessage (WM_ACTIVATE,0,0)
等等,但没有人从兄弟姐妹身后带来它。
当我更换 WS_CHILD
通过 WS_OVERLAPPEDWINDOW
在 CreateEX()
函数中,创建的非子窗口没有问题显示为最顶层前台活动窗口。
那么我必须做些什么才能让兄弟姐妹的窗户从兄弟姐妹的后面走到顶端?
万分感谢。
欧内斯特。
=========更多信息如下问题==========
这是代码我使用过:
HWND hButtWnd = CreateWindowEx(WS_EX_STATICEDGE, < span class =code-string> 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 :: FromHan dle(m_hWnd),NULL,NULL);
pChildWnd-> SetWindowPos(& wndTop, 0 , 0 , 0 , 0 ,SWP_NOMOVE | SWP_NOSIZE);
前两行在其他预先存在的兄弟窗口中创建一个新按钮MyButton。 MyButton可以在MyChild之后创建,但没关系,MyChild仍然隐藏在MyButton和所有其他兄弟姐妹背后。
我可以拖动垂直卷轴(I在样式中有WS_VSCROLL)但是MyChild无法被带到前台。总是留在兄弟姐妹身后。
禁用MyButton只会使MyButton变灰,而MyChild仍然留在MyButton后面。
Windows Spy ++确认SetWindowPos()命令确实将它带到z顺序的顶部;然而,它仍然落后于所有兄弟姐妹。
谢谢。
欧内斯特。
使用widnows样式:WS_CLIPSIBLINGS
HWND hButtWnd = CreateWindowEx(WS_EX_STATICEDGE, BUTTON, MyButton,WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, buttRect.left,buttRect.top, 50 , 60 ,m_hWnd,NULL,GetModuleHandle(NULL),NULL );
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.
Use the widnows style :WS_CLIPSIBLINGS
HWND hButtWnd = CreateWindowEx( WS_EX_STATICEDGE, "BUTTON", "MyButton", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS , buttRect.left, buttRect.top, 50, 60, m_hWnd, NULL, GetModuleHandle(NULL), NULL );
这篇关于儿童窗口由兄弟窗口重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!