簡體   English   中英

當子窗口成為 C# 桌面應用程序的子窗口時,C++ Windows 桌面應用程序中的持續閃爍?

[英]Constant flickering in C++ Windows desktop app when a child window is made the child of a C# desktop app?

我已經使用以下 SO 帖子中的信息在我的 C++ 桌面應用程序中創建圖片控件的父級,在我的 C# 應用程序中創建面板控件的子級。 C++ 和 C# 應用程序是在自己的進程中運行的獨立應用程序:

使用 SetParent 將窗口嵌入外部進程的各種問題

使用 SetParent 將 HWND 嵌入到外部進程中

我正在使用下面顯示的代碼進行重新養育。 C# 應用程序啟動 C++ 應用程序,在命令行上將面板控件的 Windows 句柄傳遞給它,該控件應該承載 C++ 應用程序的圖片控件。 當我運行 C# 應用程序時,我確實在 C# 應用程序本機的指定面板控件上看到了 C++ 圖片控件的輪廓。

但是,我遇到了以下問題:

1) C++ 和 C# 應用程序閃爍得非常厲害,就像它們每秒都被重繪多次一樣。

2) C++ 應用程序中的圖片控件通常顯示來自我的網絡攝像頭的視頻源。 I BitBlt() 將來自網絡攝像頭的幀轉換為 C++ 圖片控件。 它在沒有重新養育的情況下工作正常,但有了它,我根本看不到任何框架。

注意:閃爍絕對是繪制到現在重新設置父級的子窗口中的結果。 如果我禁用該操作,則不會發生閃爍。

有誰知道出了什么問題,我該如何解決? 這是 C++ 應用程序中的代碼,它執行重新父級並將 C++ 主輸入線程(擁有圖片控件的線程)附加到屬於 C# 應用程序的主線程(擁有圖片控件的線程)的輸入線程面板控制):

// 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)

我也遇到了這個問題,解決方法是父hwnd需要標志WS_CLIPCHILDREN。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM