• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

CDialog划分为两个背景不同的区域(内部目标的图片)

用户头像
it1352
帮助1

问题说明

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

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?

正确答案

#1

经过一番挖掘,我发现一种很好的方法是重写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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhchabbc
系列文章
更多 icon
同类精品
更多 icon
继续加载