首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当一个子窗口成为C++桌面应用程序的子窗口时,C# Windows桌面应用程序中会不停地闪烁?

当一个子窗口成为C++桌面应用程序的子窗口时,C# Windows桌面应用程序中会不停地闪烁?
EN

Stack Overflow用户
提问于 2015-06-20 19:44:50
回答 1查看 570关注 0票数 0

我在C++桌面应用程序中创建了图片控件的父控件,这是我的C#应用程序中一个面板控件的子控件。C++和C#应用程序是在各自的过程中运行的独立应用程序:

Various issues using SetParent to embed window into external process

Embedding HWND into external process using SetParent

我正在使用下面所示的代码来重新养育孩子。C#应用程序启动C++应用程序,将其传递给面板控件的Windows命令行,该命令行应该承载C++应用程序的图片控件。当我运行C#应用程序时,我确实看到了C++图片控件的大纲,它位于指定的C#控件上,该控件是C#应用程序的本机。

不过,我有以下问题:

1) C++和C#应用程序都在闪烁,就像它们每秒钟都被重新绘制很多次一样。

2) C++应用程序中的图片控件通常显示来自我的WebCam的视频提要。I BitBlt()从网络摄像头到C++图片控件的帧。如果没有重新为人父母的话,一切都会好起来,但我根本看不出任何框架。

注意事项:闪烁绝对是引入现在重新父母的子窗口的结果。如果我禁用那个操作,闪烁就不会发生。

有人知道出了什么问题吗?我怎样才能解决呢?下面是C++应用程序中的代码,用于重新养育和将C++主输入线程(拥有图片控件的线程)附加到属于C#应用程序主线程(拥有C#控件的线程)的输入线程:

代码语言:javascript
复制
// The following code executes in the wWinMain() function of the C++
//  app after the main dialog window and it's child controls have been
//  setup and initialized.  The value assigned to g_VideoHostContainerHWnd
//  was passed to the C++ app by the C# app that launched it, as a 
//  command line argument, using the Panel control's Handle property
//  converted to an unsigned integer.
g_OurMainThreadID = GetCurrentThreadId();

if (g_VideoHostContainerHWnd > 0)
{
    // Make our video stream window a parent of the designated window
    //  in the HiveMind client.

    // Get the window handle for the video stream window: IDC_PANEL_PICTURE.
    HWND videoStreamWindow =
        GetDlgItem(
        g_HwndDlg,
        IDC_PANEL_PICTURE);

    if (videoStreamWindow > 0)
    {
        // Get the thread ID for the thread that owns the video host container window.

         g_VideoHostThreadID = GetWindowThreadProcessId(
            g_VideoHostContainerHWnd,
            &g_VideoHostProcessID);

         if (g_VideoHostThreadID > 0)
         {
             // Make the video stream window a child of the HiveMindClient window.
             if (NULL == SetParent(videoStreamWindow, g_VideoHostContainerHWnd))
                 OutputDebugString(L"The reparenting of the video stream window FAILED.");
             else
                 OutputDebugString(L"The reparenting of the video stream window SUCCEEDED.");

             // Attach the our input thread to the thread ID for the process that launched us
             //  (i.e. - owns the video host window).
             if (AttachThreadInput(g_OurMainThreadID, g_VideoHostThreadID, true))
                 OutputDebugString(L"Attaching our input thread to the video host thread SUCCEEDED.");
             else
                 OutputDebugString(L"Attaching our input thread to the video host thread FAILED.");
         }
         else
         {
             OutputDebugString(L"The thread ID of the video host container's owner thread is ZERO.");
         } // else - if (g_VideoHostThreadID > 0)
    }
    else
        OutputDebugString(L"The video stream window handle is INVALID.");
} // if (g_VideoHostContainerHWnd > 0)
EN

回答 1

Stack Overflow用户

发布于 2021-08-16 14:04:28

我也遇到了这个问题,解决方案是父hwnd需要标志WS_CLIPCHILDREN。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30958181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档