将CDialog划分为两个背景不同的区域(内部目标的图片) [英] Dividing a CDialog in two areas with different backgrounds (picture of the objective inside)

查看:124
本文介绍了将CDialog划分为两个背景不同的区域(内部目标的图片)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建一个设计成完全像这样的窗口(它在白色区域内具有控件,但这暂时不相关):

I need to build a window designed to look exactly like this (it has controls inside the white area, but that's not relevant for now):

http://dl.dropbox.com/u/3432167/example.png
我的问题是用不同的背景定义这两个单独的区域".
我最接近预期外观的是用空的ListBox表示白色区域,但是结果不一样(这是一个糟糕的hack).

http://dl.dropbox.com/u/3432167/example.png
My problem is defining those two separate "areas" with different backgrounds.
The closest I've got to the expected look was representing the white area with an empty ListBox, but the result is not the same (and it is a lousy hack).

关于如何实现这一目标的任何想法?

Any ideas on how achieve this?

推荐答案

经过一番挖掘,我发现一种很好的方法是重写OnPaint函数.
以下是用于上述问题的对话框的示例.矩形尺寸是硬编码的,因为此特定对话框不可调整大小.

After some digging, I've discovered that a good way to do this is overriding the OnPaint function.
Below is an example used for the dialog pictured on the question above. The rectangle dimensions are hard-coded because this particular dialog is not resizeable.

不要忘记将ON_WM_PAINT()添加到消息映射中.

Don't forget to add ON_WM_PAINT() to the message map.

void CTestDlg::OnPaint()
{
    if (IsIconic())
    {
        (...)
    }
    else
    {
        CPaintDC dc(this); // device context for painting
        dc.FillSolidRect(0,0,612,376, RGB(255,255,255));
        dc.FillSolidRect(0,376,612,60, ::GetSysColor(COLOR_3DFACE));
        CDialog::OnPaint();
    }
}

该解决方案最终变得非常简单,但无论如何我认为共享还是很有用的.

The solution ended up being quite simple, but I guess useful to share anyway.

这篇关于将CDialog划分为两个背景不同的区域(内部目标的图片)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆