void CWindowDlg::DoCapture(LONG hWnd)
{
    CComPtr<ITextCaptureX7> pCapture;
    HRESULT hr = pCapture.CoCreateInstance(CLSID_TextCaptureX);
    if(FAILED(hr) || !pCapture)
    {
        AfxMessageBox(IDS_ERR_CREATE_CAPTURE_OBJ, MB_OK | MB_ICONERROR);
        return;
    }

    CComPtr<IFontDisp> pFont;
    CComBSTR bstrRes;
    try
    {
        pCapture->FormattedText = m_bUseFormatting ? ATL_VARIANT_TRUE : ATL_VARIANT_FALSE;
        DWORD dwStart = ::GetTickCount();;
        if(0 == m_nType)
            bstrRes = (BSTR)pCapture->CaptureWindowWithFont(hWnd, &pFont);
        else
            bstrRes = (BSTR)pCapture->GetFullTextAA(hWnd);

        DWORD dwEnd = ::GetTickCount();

        m_strDuration.Format(IDS_DURATION, dwEnd-dwStart);

        //fill the values
        m_strResult = bstrRes;
        m_strFont.Empty();
        m_nFontSize = 0;
        if(bstrRes.Length() > 0)
        {
            LOGFONT lf;
            theApp.DecodeFont(pFont, m_strFont, m_nFontSize, lf);
            ModifyFont(lf);
        }
    }
    catch(_com_error e)
    {
        //display error
        CComQIPtr<IErrorInfo> pErrInfo = e.ErrorInfo();
        CString strErr = e.ErrorMessage();
        if(pErrInfo)
        {
            CComBSTR bstrErr;
            if(S_OK == pErrInfo->GetDescription(&bstrErr))
                strErr = bstrErr;
        }
        AfxMessageBox(strErr, MB_OK | MB_ICONERROR);
    }
    catch(...)
    {
        //display error
        AfxMessageBox(IDS_CAPTURE_ERROR, MB_OK | MB_ICONERROR);
    }
}