简体   繁体   English

如何在 Mfc C++ 中创建透明矩形?

[英]How to create transparent Rectangle in Mfc c++?

I want to create a rectangle total transparent i try this code.我想创建一个完全透明的矩形我试试这个代码。 Any idea how to do that?知道怎么做吗?

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

This is mfc c++ code example.这是 mfc c++ 代码示例。

First: How the hell do you want to create a transparent rectangle, if you created a solid brush and after did a FillRect with it?第一:如果你创建了一个实心画笔,然后用它做了一个 FillRect,你到底想如何创建一个透明的矩形?

If you wanted to do that using a brush, you would have to go with one "that not paints anything" like:如果你想用画笔来做到这一点,你必须使用一个“不画任何东西”的画笔,比如:

brush.CreateStockObject(NULL_BRUSH);

May be you wanted a rectangle with an opaque border and transparent interior.可能您想要一个带有不透明边框和透明内部的矩形。 In that case, in addition to the null brush, the object you need to create is a CPen.在这种情况下,除了空画笔之外,您需要创建的对象是 CPen。

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

Secondly, I think the DrawEdge function is the simplest way to go if you dont' care about the border color (the colors are fixed; search DrawEdge in Google images to see what I mean).其次,如果您不关心边框颜色(颜色是固定的;在 Google 图片中搜索 DrawEdge 以了解我的意思),我认为DrawEdge函数是最简单的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM