1. 在dialog上设置一个label或者其他控件,设置好位置和尺寸
  2. 获取opencv创建的窗口句柄
  3. 将两者关联到一起

void EmbedCvWindow( HWND pWnd, CString strWndName, int w, int h )
{
    cvNamedWindow(strWndName, 0);
    HWND hWnd = (HWND) cvGetWindowHandle(strWndName);
    HWND hParent = ::GetParent(hWnd);
    ::SetParent(hWnd, pWnd); // 嵌入到pWnd窗口
    ::ShowWindow(hParent, SW_HIDE);
    ::SetWindowPos(pWnd, NULL, 0,0, w,h, SWP_NOMOVE | SWP_NOZORDER);
    cvResizeWindow(strWndName, w,h);
}

bool CDlgMainMonitor::InitWindows(void)
{
    CWnd *pWnd = GetDlgItem(IDC_Video);
    CRect rc;
    pWnd->GetWindowRect(rc);
    EmbedCvWindow(pWnd->m_hWnd, "video", rc.Width(),rc.Height());

    CWnd *pWnd1 = GetDlgItem(IDC_STATIC_Pic1);
    CRect rc1;
    pWnd->GetWindowRect(rc1);
    EmbedCvWindow(pWnd1->m_hWnd, "Tracking", rc1.Width(),rc1.Height());

    return true;
}

更多推荐