【问题标题】:How do I convert the background of Edit Control to transparent in mFC VC++?如何在 mFC VC++ 中将编辑控件的背景转换为透明?
【发布时间】:2019-03-18 08:28:43
【问题描述】:

Output is show in picture

我正在使用一个 CStatic 控件,其变量为“m_background”,ID 为 IDC_background。在此控件中,视频已在单击按钮时运行。还有第二个控件编辑控件,变量为“m_edit”,ID为IDC_edit。这个编辑框放置在静态控件上。我想在视频上显示编辑控件中编写的文本,同时我们通过单击具有编辑控件透明背景颜色的按钮播放视频。 但问题是在我们播放视频时,m_edit 控件出现了灰色/白色背景。我想在播放视频时以“m_edit”控件的透明背景在视频上显示文本。

BOOL CtestcodeDlg::OnInitDialog()//To set up the video in background and text above the video
{
    m_background.ModifyStyle(0, WS_CLIPSIBLINGS);   
    m_edit.SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0, 
         SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE|WS_EX_TRANSPARENT);
    return TRUE;  // return TRUE  unless you set the focus to a control
}

HBRUSH CtestcodeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) //To transparent the background of Edit box
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    HBRUSH m_default=CreateSolidBrush(RGB(0,0, 0));
    if(pWnd->GetDlgCtrlID() == IDC_edit)
    {
        pDC->SetTextColor(RGB(255,0,0));
        pDC->SetBkColor(TRANSPARENT);
        pDC->SetBkMode(TRANSPARENT);
    }
    return hbr;
}

void CtestcodeDlg::OnBnClickedButton1()////To run the video
{
    my_instance = libvlc_new(0, NULL);
    my_media_file = libvlc_media_new_location(my_instance, 
                               "rtsp://BigBuckBunny_115k.mov");
    my_player = libvlc_media_player_new_from_media(my_media_file);
    my_event_manager = libvlc_media_player_event_manager(my_player);
    libvlc_media_player_play(my_player);
    libvlc_audio_set_track(my_player ,-1);
    libvlc_media_player_set_hwnd(my_player, m_background);
    Sleep(1000); 
    _beginthread(test, 0, NULL);
    libvlc_audio_set_track(my_player ,-1);
}

【问题讨论】:

    标签: visual-c++ mfc


    【解决方案1】:

    尝试使用 SetLayeredWindowAttributes 函数,并使用您的 bk 颜色的 crKey。
    另外,我认为您的代码中的pDC->SetBkColor(TRANSPARENT); 是一个错误,它将 bk 颜色设置为黑色。尝试在没有此调用的情况下运行。

    【讨论】:

    • 我在没有这个调用的情况下运行程序但是 pDC->SetBkColor(TRANSPARENT);但这不起作用。
    猜你喜欢
    • 2012-10-08
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多