1

我曾尝试用谷歌搜索 COleControl、IOleInPlaceSite 等许多键......但我仍然对此一无所知。我知道当activex控件处于非活动状态时,容器不会为activex控件创建窗口!所以 rect 将与 Ondraw 不同!如何使控件在同一个地方?在 ReportViewer 中我可以控制二维码的位置!但是当我将它打印到 PDF 时,它总是在纸的左上角!感谢您的帮助!

`
void CQRControlCtrl::OnDraw(CDC* pDC, const CRect& rcBounds, const CRect& rcInvalid)
{
    if(*m_DataText == NULL )
        m_DataText = L"";       

    LPWSTR szText = m_DataText.GetBuffer(m_DataText.GetLength());   

    int nSize = m_qSize;
    int nMargin = m_qMargin;

    BOOL bPrinting = pDC->IsPrinting();

    if (!pDC)
        return;

    double PixelsPermmX = (*pDC).GetDeviceCaps(LOGPIXELSX);
    double PixelsPermmY = (*pDC).GetDeviceCaps(LOGPIXELSY);

    pDC->SetMapMode(MM_ANISOTROPIC);
    pDC->SetWindowExt(48,48);   
    pDC->SetViewportExt(PixelsPermmX,PixelsPermmY); 

    HBITMAP hbitmap = GetHBitmapW(szText, nMargin, nSize, QR_ECLEVEL_M);    

    CBitmap *pBitmap=CBitmap::FromHandle(hbitmap);
    BITMAP bitmap;
    GetObject(hbitmap,sizeof(BITMAP),&bitmap);

    int nHeight = bitmap.bmHeight;
    int nWidth = bitmap.bmWidth;

    CRect rect;
    this->GetRectInContainer(rect);

    CDC MemDC;      
    MemDC.CreateCompatibleDC(pDC);  
    MemDC.SelectObject(pBitmap);    

    pDC->StretchBlt(rect.left,rect.top,nWidth,nHeight,&MemDC,0,0,nWidth,nHeight,SRCCOPY);
}`
4

0 回答 0