【问题标题】:How to get the visible client rect of a CPropertySheet object?如何获取 CPropertySheet 对象的可见客户端矩形?
【发布时间】:2019-11-15 12:26:07
【问题描述】:

我正在尝试更改我的 MFC CPropertySheet 对象的一些颜色。我可以更改我想要的所有区域的颜色。但是,我仍然无法控制一个区域。这是我的代码得到的图像。

如您所见,我可以使用下面的代码在上边距和左边距上画一个细边框。

void CEasyPropertySheet::Draw_Borders(CDC* pDC)
{
    // I check how many lines of tabs the control has.
    CTabCtrl* pTab = this->GetTabControl();
    int lines = pTab->GetRowCount();

    // I get the rect I want to define the borders of the control.
    CRect rect; this->GetClientRect(rect);
    pDC->FillSolidRect(rect, GENERIC_BACKGROUND_COLOR);

    // I draw the border in 2 steps. First of all I fill one rect with the border color.
    // After that, I deflect the rect and I filled again using the background color I want.
    rect.DeflateRect(0, 19 * lines, 0, 0);  
    pDC->FillSolidRect(rect, GENERIC_BORDER_COLOR);
    rect.DeflateRect(1, 1);
    pDC->FillSolidRect(rect, PROPERTYPAGE_BACKGROUND_COLOR);
}

但是,我不能使用相同的方法来绘制其他的(底部和右侧边框)。我认为我使用的矩形比屏幕上显示的要大,但我不知道该怎么做才能得到那个矩形。

有人知道该怎么做吗?

【问题讨论】:

    标签: c++ mfc cdc cpropertysheet


    【解决方案1】:

    嗯。在尝试了几件事(包括没有意义的事情)之后,我终于找到了我正在寻找的答案。我所要做的就是得到一个不同的矩形。这是有效的代码:

    void CEasyPropertySheet::Draw_Borders(CDC* pDC)
    {
        // I check how many lines of tabs has the controls.
        CTabCtrl* pTab = this->GetTabControl();
        int lines = pTab->GetRowCount();
    
        // I get the rect I want to define the borders of the control.
        CRect rect;
        pTab->GetClientRect(rect);
        pDC->FillSolidRect(rect, GENERIC_BACKGROUND_COLOR);
    
        // I draw the border in 2 steps. First of all I fill one rect with the border color.
        // After that, I deflect the rect and I filled again using the background color I want.
        rect.DeflateRect(0, 19 * lines, 0, 0);
        pDC->FillSolidRect(rect, GENERIC_BORDER_COLOR);
        rect.DeflateRect(1, 1);
        pDC->FillSolidRect(rect, PROPERTYPAGE_BACKGROUND_COLOR);
    }
    

    我得到了整个CPropertySheet 的矩形,这是错误的。我要做的是得到CTabCtrl 的矩形。结果如下:

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      • 2011-10-10
      相关资源
      最近更新 更多