0
点赞
收藏
分享

微信扫一扫

MFC中窗口隐藏后再显示,子窗口没刷新(WS_CLIPCHILDREN,WS_CLIPSIBLINGS)


问题描述

非模态对话框下,显示了子窗口,但窗口隐藏后,再通过任务栏显示出来时,子窗口内容就不显示了。

  • 正确的显示如下:
  • MFC中窗口隐藏后再显示,子窗口没刷新(WS_CLIPCHILDREN,WS_CLIPSIBLINGS)_WS_CLIPCHILDREN

  • 显示异常的情况
    -
  • MFC中窗口隐藏后再显示,子窗口没刷新(WS_CLIPCHILDREN,WS_CLIPSIBLINGS)_WS_CLIPCHILDREN_02

原因分析

显示父窗口时,父窗口会进行重绘(我的理解,可能有误:它不负责子窗口的重绘),默认情况下(即子窗口未指定WS_CLIPCHILDREN),父窗口会将子窗口与父窗口重叠的部分使用背景色进行绘制。

解决方案

创建子窗口加上WS_CLIPCHILDREN(剪去子窗口区域)。意思就是父窗口重绘时,不重绘子窗口背景。
MSDN上描述:

WS_CLIPCHILDREN Excludes the area occupied by child windows when you
draw within the parent window. Used when you create the parent window.

其他说明

  • WS_CLIPSIBLINGS
    MSDN原文

WS_CLIPSIBLINGS Clips child windows relative to each other; that is,
when a particular child window receives a paint message, the
WS_CLIPSIBLINGS style clips all other overlapped child windows out of
the region of the child window to be updated. (If WS_CLIPSIBLINGS is
not given and child windows overlap, when you draw within the client
area of a child window, it is possible to draw within the client area
of a neighboring child window.) For use with the WS_CHILD style only.

此窗口样式表示剪去兄弟窗口区域,即不绘制兄弟窗口与自己重叠的部分。父窗口为重叠窗口(overlapped),那么多个子窗口间就会存在重叠的情况,此样式可以对重叠部分的绘制进行控制。

举报

相关推荐

0 条评论