Visual Studio 2013 - 如何在 Mfc c++ 中创建透明矩形

visual studio 2013 - How to create transparent Rectangle in Mfc c++?

本文关键字:c++ 创建 透明 Mfc 2013 Studio Visual      更新时间:2023-10-16

我想创建一个完全透明的矩形,我试试这段代码。知道怎么做吗?

 BOOL CHtmlDlgTestDlg::PreTranslateMessage(MSG* pMsg)
    {
        if (pMsg->message == WM_MOUSEMOVE && (pMsg->wParam & MK_LBUTTON))
        {
            CPoint p = pMsg->pt;
            ScreenToClient(&p);
            CRect r(10, 15, 380, 50);
            CDC* pCDC = GetDC();
            pCDC->Rectangle(r);
            CBrush brush;

            brush.CreateSolidBrush(RGB(255, 255, 0));
            pCDC->FillRect(&r, &brush);

            if (r.PtInRect(p))
            {
                ReleaseCapture();
                SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0);
                SendMessage(WM_NCLBUTTONUP, HTCAPTION, 0);
                return 1;
            }
        }
        return CDHtmlDialog::PreTranslateMessage(pMsg);
    }

这是 mfc c++ 代码示例。

首先:如果你创建了一个实心画笔,然后用它做了一个 FillRect,你到底想如何创建一个透明矩形?

如果你想用画笔来做到这一点,你必须使用一个"不画任何东西",比如:

brush.CreateStockObject(NULL_BRUSH);

您可能想要一个具有不透明边框和透明内部的矩形。在这种情况下,除了空画笔之外,您需要创建的对象是 CPen。

CPen p(PS_SOLID, 0, RGB(255, 255, 0));
pCDC->SelectObject(&p);
pCDC->Rectangle(r);

其次,如果您不关心边框颜色(颜色是固定的;在Google图像中搜索DrawEdge以了解我的意思),我认为DrawEdge功能是最简单的方法。