MFC中的动态透明度几何

问题描述

我正在为我的MFC应用程序创建一个新UI演练,并希望在演练进行时突出显示某些控件。具体来说,除了要强调的控件外,我想使整个窗口变暗。

我尝试使用SetLayeredWindowAttributes创建部分透明的黑色叠加层,但这不能让我完全透明地设置子区域 UpdateLayeredWindow可以做到这一点,但我并不急于为需要突出显示的每个控件创建一个BMP / PNG文件。

我可以动态创建透明度几何吗?例如,我可以从头开始绘制位图透明度,然后将其加载到UpdateLayeredWindow中吗?

我还需要与Windows 7兼容(尽管它支持EOL)。

后续行动: 尝试绘制透明的GDI +区域,但不起作用:


    void ApplicationDlg::Highlight(const CRect& rect)
    {
        CRect wndRect;
        GetWindowRect(&wndRect);
        Gdiplus::Rect wndRectPlus(wndRect.left,wndRect.top,wndRect.Width(),wndRect.Height());
        Gdiplus::Region wndRegion(wndRectPlus);
    
        Gdiplus::Rect controlRectPlus(rect.left,rect.top,rect.Width(),rect.Height());
        Gdiplus::Region highlightRegion(controlRectPlus);
    
        wndRegion.Exclude(&highlightRegion);
    
        Gdiplus::SolidBrush transparentBrush(Gdiplus::Color(0,0));
        Gdiplus::SolidBrush darkenBrush(Gdiplus::Color(128,0));
    
        CDC* pDCScreen = m_WalkthroughDlg.GetDC();
        HDC hDC = CreateCompatibleDC(pDCScreen->m_hDC);
        HBITMAP hBmp = CreateCompatibleBitmap(hDC,wndRect.Height());
        HBITMAP hBmpOld = (HBITMAP)SelectObject(hDC,hBmp);
    
        Gdiplus::Graphics graphics(hDC);
        graphics.FillRegion(&darkenBrush,&wndRegion);
        graphics.FillRegion(&transparentBrush,&highlightRegion);
    
        BLENDFUNCTION blend = {0};
        blend.BlendOp = AC_SRC_OVER;
        blend.SourceConstantAlpha = 255;
        blend.AlphaFormat = AC_SRC_ALPHA;
        SIZE sizeWnd = {wndRect.Width(),wndRect.Height()};
        POINT ptSrc = {0,0};
        m_WalkthroughDlg.UpdateLayeredWindow(pDCScreen,NULL,&sizeWnd,CDC::FromHandle(hDC),&ptSrc,&blend,ULW_ALPHA); // TODO cleanup FromHandle refs
        m_WalkthroughDlg.BringWindowToTop();
    
        SelectObject(hDC,hBmpOld);
        DeleteObject(hBmp);
        DeleteDC(hDC);
    }

解决方法

您可以使用racle.c:2379: error: âcvâ undeclared (first use in this function) Oracle.c:2380: error: âitemsâ undeclared (first use in this function) Oracle.c:2382: error: âXS_VERSION_BOOTCHECKâ undeclared (first use in this function) Oracle.c:2388: warning: implicit declaration of function âPerl_newXSâ Oracle.c:2388: error: âXS_DBD__Oracle_constantâ undeclared (first use in this function) Oracle.c:2389: error: âXSANYâ undeclared (first use in this function) Oracle.c:2518: error: âXS_DBD__Oracle_ORA_OCIâ undeclared (first use in this function) Oracle.c:2519: error: âXS_DBD__Oracle_ora_env_varâ undeclared (first use in this function) Oracle.c:2523: error: âXS_DBD__Oracle__dr_dbixs_revisionâ undeclared (first use in this function) Oracle.c:2533: error: âXS_DBD__Oracle__db__loginâ undeclared (first use in this function) Oracle.c:2534: error: âXS_DBD__Oracle__db_selectall_arrayrefâ undeclared (first use in this function) Oracle.c:2535: error: âXS_DBD__Oracle__db_selectrow_arrayrefâ undeclared (first use in this function) Oracle.c:2545: error: âXS_DBD__Oracle__db_commitâ undeclared (first use in this function) Oracle.c:2546: error: âXS_DBD__Oracle__db_rollbackâ undeclared (first use in t heis function) ./Oracle.xsi:19: warning: implicit declaration of function âSvIVXâ ./Oracle.xsi:19: warning: implicit declaration of function âperl_get_svâ ./Oracle.xsi:19: error: lvalue required as unary â&â operand ./Oracle.xsi:19: warning: cast to pointer from integer of different size ./Oracle.xsi:19: error: âdbistate_tâ has no member named âcheck_versionâ ./Oracle.xsi:21: warning: implicit declaration of function âsv_setivâ ./Oracle.xsi:21: error: âGV_ADDMULTIâ undeclared (first use in this function) ./Oracle.xsi:24: warning: implicit declaration of function âora_initâ Oracle.c:2649: error: âXSRETURN_YESâ undeclared (first use in this function) Oracle.c:2367: warning: unused variable âPerl___notusedâ make: *** [Oracle.o] Error 1 https://docs.microsoft.com/en-us/cpp/mfc/reference/crgn-class?view=vs-2019

动态创建遮罩

它允许您组合区域(如果需要突出显示多个区域)。然后,您可以使用CRgn函数来更新FillRgn中使用的hdcSrc DC。

或者,如果突出显示为矩形,则可以在该UpdateLayeredWindow上绘制矩形。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...