饼图的打印问题 如何把一个饼状的比例图打印出来 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为什么我运行http://www.vcfan.com/vc/down_children.asp?child_name=codes_kongjian&page=2第1335(编号)中的程序,工具条上打印图标是灰色的,运行不了 为什么我运行http://www.vcfan.com/vc/down_children.asp?child_name=codes_kongjian&page=2第1335(编号)中的程序,工具条上打印图标是灰色的,运行不了 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(); 该代码可以打印对话框上显示的饼图吗?OnPreparePrinting,OnPrint在CDialog中不能用吧? 子窗口相互sendmessage问题。 请教“关于CreatePopupMenu如何自动销毁”的问题 ? 生成数据集出错 如何保存Date Time Picker中的时间值到外部设定“.ini”文件? Message问题 如何知道全局钩子dll里的全局变量在所有进程间都共享? 菜鸟求助 “对象不支持该方法”!为什么啊? DCOM对象的问题 笨死了 请教:CString + CString 到底结果是什么,怎么工作的? InitInstance加入两行代码后无法使用...找不出问题... 马上给分 请问如何在工具栏按钮的右边加上文字,象ie的工具栏的搜索按钮一样
第1335(编号)中的程序,工具条上打印图标是灰色的,运行不了
第1335(编号)中的程序,工具条上打印图标是灰色的,运行不了
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();
OnPreparePrinting,OnPrint在CDialog中不能用吧?