cv::Mat paint in MFC

void CWnd::OnPaint()
{
    CPaintDC dc(this); // device context for painting
                       // TODO: Add your message handler code here
                       // Do not call CWnd::OnPaint() for painting messages

    if (!m_cvImage.empty()) {
        CRect rect;
        GetClientRect(&rect);
        BITMAPINFO bmi = { 0 };
        bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
        bmi.bmiHeader.biCompression = BI_RGB;
        bmi.bmiHeader.biWidth = m_cvImage.cols;
        // note that bitmaps default to bottom-up, use negative height to
        // represent top-down
        //
        bmi.bmiHeader.biHeight = m_cvImage.rows * -1;
        bmi.bmiHeader.biPlanes = 1;
        bmi.bmiHeader.biBitCount = 24; // 32 if you use RGBQUADs for the bits
        SetStretchBltMode(dc, STRETCH_HALFTONE);
        StretchDIBits(dc,
            0, 0,
            rect.Width(), rect.Height(),
            0, 0,
            bmi.bmiHeader.biWidth, abs(bmi.bmiHeader.biHeight),
            m_cvImage.data,
            &bmi,
            DIB_RGB_COLORS,
            SRCCOPY);
    }
}