将CDialog分为两个不同背景的区域(里面的目标图片)

发布于 2024-12-27 03:12:20 字数 287 浏览 5 评论 0原文

我需要构建一个设计得与此完全相同的窗口(它在白色区域内有控件,但现在不相关):

http://dl.dropbox.com/u/3432167/example.png
我的问题是定义这两个具有不同背景的独立“区域”。
我最接近预期的外观是用空列表框表示白色区域,但结果并不相同(而且这是一个糟糕的黑客)。

关于如何实现这一目标有什么想法吗?

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
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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你列表最软的妹 2025-01-03 03:12:20

如果对话框不需要调整大小,最简单的方法是创建具有所需背景的 bmp(如果可以使用 CDialogEx 而不是 CDialog,则非常简单 - 只需调用 SetBackgroundImage)。

如果您不能使用位图,那么您将必须创建自己的控件来绘制此背景。

If the dialog does not need to be resizable, the easiest way would be to create a bmp with the desired background (quite easy if you can use CDialogEx instead of CDialog - just need to call SetBackgroundImage).

If you can not use a bitmap then you will have to create your own control to draw this background.

冷血 2025-01-03 03:12:20

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

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

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();
    }
}

解决方案最终非常简单,但我想无论如何分享还是有用的。

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文