如何把一个饼状的比例图打印出来

解决方案 »

  1.   

    为什么我运行http://www.vcfan.com/vc/down_children.asp?child_name=codes_kongjian&page=2
    第1335(编号)中的程序,工具条上打印图标是灰色的,运行不了
      

  2.   

    为什么我运行http://www.vcfan.com/vc/down_children.asp?child_name=codes_kongjian&page=2
    第1335(编号)中的程序,工具条上打印图标是灰色的,运行不了
      

  3.   

    1、在  OnPreparePrinting(CPrintInfo* pInfo)中 CBitmap bm;
    CBitmap *pOld;
    int Width,Height;
    CDC tdc;
    BITMAP btm;
    DWORD size;
    CDC dc;

    RECT Rect;

    m_ChartWnd.GetWindowRect(&Rect);

    RECT rToolBar;
    RECT rMyBar;       
    pFrame->m_wndToolBar.GetWindowRect(&rToolBar);
    pFrame->m_wndMyBar1.GetWindowRect(&rMyBar);
    // this->GetWindowRect(&Rect);
    m_ChartWnd.GetWindowRect(&Rect);
            
    if (pInfo->m_bPreview)
    {
    Rect.bottom +=rToolBar.bottom;
    Rect.top += rToolBar.bottom;
    Rect.left += rMyBar.right;
    Rect.right += rMyBar.right;
    }

    dc.CreateDC("DISPLAY",NULL,NULL,NULL);

    Width=Rect.right-Rect.left;
    Height=Rect.bottom-Rect.top;

    bm.CreateCompatibleBitmap(&dc,Width,Height);

    tdc.CreateCompatibleDC(&dc);
    pOld=tdc.SelectObject(&bm);

    tdc.BitBlt(  0 ,  0 ,  Width,  Height,  &dc,   Rect.left   ,   Rect.top    ,   SRCCOPY);
    //BOOL  BitBlt(int x,int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop );

    tdc.SelectObject(pOld);
    bm.GetBitmap(&btm);
    size=btm.bmWidthBytes*btm.bmHeight;
    LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);

    /////////////////////////////////////////////
    BITMAPINFOHEADER bih;
    bih.biBitCount=btm.bmBitsPixel;
    bih.biClrImportant=0;
    bih.biClrUsed=0;
    bih.biCompression=0;
    bih.biHeight=btm.bmHeight;
    bih.biPlanes=1;
    bih.biSize=sizeof(BITMAPINFOHEADER);
    bih.biSizeImage=size;
    bih.biWidth=btm.bmWidth;
    bih.biXPelsPerMeter=0;
    bih.biYPelsPerMeter=0;
    ///////////////////////////////////

    GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);

           

    if (OpenClipboard())      //hWnd为程序窗口句柄
    {
    //清空剪贴板
    EmptyClipboard();
    //把屏幕内容粘贴到剪贴板上,bm为刚才的屏幕位图句柄
    SetClipboardData(CF_BITMAP, bm);
    //关闭剪贴板
    CloseClipboard();

    }

    if(IsClipboardFormatAvailable(CF_BITMAP))
    {
    if(OpenClipboard())
    {
    m_hbitmap = (HBITMAP)::GetClipboardData(CF_BITMAP);
    CloseClipboard();
    }
    }2、在 OnPrint(CDC *pDC, CPrintInfo *pInfo)中 TEXTMETRIC tm;
    CFont font;
    CSize textSize;
    int cyChar;

    // Create the font we will be using
    font.CreatePointFont(240, "Arial", pDC);
    CFont *pOldFont=pDC->SelectObject(&font);

    //Set Margin
    rectPage.top+=rectPage.bottom/48;
    rectPage.bottom-=rectPage.bottom/48;
    rectPage.left+=200;
    rectPage.right-=200;

    // Get Text size in order to center
    pDC->GetTextMetrics(&tm);
    textSize=pDC->GetTextExtent(sTitleHeader);
    cyChar = tm.tmHeight;

    // Draw Text (centered)
    pDC->TextOut(((rectPage.right+rectPage.left)/2)-(textSize.cx/2), rectPage.top, sTitleHeader);
    rectPage.top += cyChar + cyChar / 4;

    // Draw header line divider
    pDC->MoveTo(rectPage.left, rectPage.top);
    pDC->LineTo(rectPage.right, rectPage.top);

    // Go to next line
    rectPage.top += cyChar / 4;

    if(m_hbitmap)
    {
    BITMAP bm;
    ::GetObject(m_hbitmap, sizeof(BITMAP), &bm);
    CSize chartSize(bm.bmWidth, bm.bmHeight);

    CDC dcMemory,dcScreen;
    dcScreen.Attach(::GetDC(NULL));

    // create "from" device context and select the loaded bitmap into it
    dcMemory.CreateCompatibleDC(&dcScreen);
    dcMemory.SelectObject(m_hbitmap);

    // Print at 85% size within left/right margin 
    CSize printSize;
    printSize.cx=(int)(rectPage.right*.85);
    printSize.cy=printSize.cx/chartSize.cx*chartSize.cy;
    CRect rect(0,0,printSize.cx,printSize.cy);

    // Print chart centered
    pDC->StretchBlt( ((rectPage.right+rectPage.left)/2)-(printSize.cx/2), rectPage.top, printSize.cx, printSize.cy, &dcMemory, 0, 0, chartSize.cx, chartSize.cy, SRCCOPY);
    dcMemory.DeleteDC();
    }
    // Revert and Destroy


    pDC->SelectObject(pOldFont);
    font.DeleteObject();
      

  4.   

    该代码可以打印对话框上显示的饼图吗?
    OnPreparePrinting,OnPrint在CDialog中不能用吧?