窗口中有若干控件,如果通过SetWindowPos(hWnd, HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE)增加某个控件的大小会导致变大的控件覆盖其他控件。
对于SetWindowPos的第二个参数如果指定HWND_TOP则会导致变大的控件在鼠标响应上处于顶端,但是其他的控件会绘制在变大的控件上。如图所示:
但是SetWindowPos的第二个参数如果指定HWND_BOTTOM则会导致变大的控件在鼠标响应方面处于底端,也就是说如果你点击变大的控件时,如果这个位置恰好有一个按钮则,那个被覆盖的按钮会相应鼠标事件。如图所示:
请求如果处理此问题
请问你的想要达到什么目的?覆盖其它按钮,并且不响应底部按钮的事件?
相关API我不太熟悉,不过你可以看看msdn或者百度百科,用HWND_TOPMOST试试?你可以把看起来有关的flag都试试。或者,用MoveWindow试试?
简单点说:
执行这条 API 函数
SetWindowPos(w.m_hWnd, HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_DEFERERASE);
后发生了如下变化:
如何避免如图所示的,(1、任务基本信息)右边的那个扩大的控件与其他控件重叠
看来这是 Windows 系统的恶疾,找到如下帖子
同级别子窗口彼此覆盖时,Windows程序就会出现问题。尽管可以通过SetWindowPos()调整各个子窗口的z序,但是仍会存在问题。典型情况就是对话框中如果用一个子窗口覆盖整个客户区,对话框里的控件仍然会不时的露出来。设计程序时,要避免子窗口彼此重叠的问题。如果一定要重叠,解决方式是用重叠的“非子窗口”,Windows支持非子窗口重叠,但不支持overlapping controls.
Child window controls should not be overlapped in applications for the Windows operating system. When one control overlaps another control, or another child window, Windows may or may not draw the window or some of its elements correctly. This behavior is a consequence of the way that Windows is designed.
The following example illustrates the painting problems caused by the ambiguity of overlapping borders. Consider three edit controls, called A, B and C, which overlap each other, and an enclosing child window D:
____________________________________________
| | A | B | C | |
| ---------------------------------------- |
| D |
--------------------------------------------
Assume that control B has the focus. If this set of controls is covered by another window, which is subsequently moved away, Windows will send a series of client and nonclient messages to each of the controls and to the enclosing child window. The result of these messages may appear as the illustration below, where the portion of window B's border that overlapped with part of window D's border is missing:
| | A | B | C | |
| ---------------------------------------- |
| D |
--------------------------------------------
Repainting problems related to overlapping controls may vary depending on the control and version of Windows used. To avoid this problem, ensure that all child windows are not overlapping or that all windows are members of the same child-parent hierarchy. For example:
________
| Parent |
--------
/ \
_________ _________
| Child A | | Child B |
--------- ---------
/ \
________ ________
| Child C| | Child D|
-------- --------
In this case, all of the child windows are control windows. Child A and Child B are overlapped sibling windows. Therefore, the all of the child windows may have painting problems. The way to correct this and still have overlapped control windows is to make Child B the parent of Child A (or vice versa).
Another consequence of having overlapping controls is that the user of the application may be confused, because clicking the mouse in the common area may not activate the control that the user intended to activate.