代码如下:
::StartPage(printDC);framePrivate->spoolPages(printDC, page, page, graphicsContext);::EndPage(printDC);
其中printDC的类型是HDC
打印DC与普通显示DC有什么区别吗?有什么要注意的吗?

解决方案 »

  1.   

    我怎么存成文件也是失败呢?
    附上我的存储函数BOOL Hdc2BmpFile(HDC hdc,LPSTR szFilePath,DWORD dwHeight,DWORD dwWidth,int x,int y)   
    {   
    if( hdc == NULL || szFilePath == NULL)    
    return FALSE;   
    // Get dimensions    
    DWORD dwBPP, dwNumColors;    dwBPP = GetDeviceCaps(hdc, BITSPIXEL);   
    if(dwBPP=8) {   
    dwNumColors = 256;   
    } else {   
    dwNumColors = 0;   
    }    // Create compatible DC    
    HDC hdc2;   
    hdc2 = CreateCompatibleDC(hdc);    if(hdc2==NULL)   
    return FALSE;    // Create bitmap    
    HBITMAP bitmap;   
    BITMAPINFO bmpinfo;   
    LPVOID pBits;    bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);   
    bmpinfo.bmiHeader.biWidth = dwWidth;   
    bmpinfo.bmiHeader.biHeight = dwHeight;   
    bmpinfo.bmiHeader.biPlanes = 1;   
    bmpinfo.bmiHeader.biBitCount = (WORD) dwBPP;   
    bmpinfo.bmiHeader.biCompression = BI_RGB;   
    bmpinfo.bmiHeader.biSizeImage = 0;   
    bmpinfo.bmiHeader.biXPelsPerMeter = 0;   
    bmpinfo.bmiHeader.biYPelsPerMeter = 0;   
    bmpinfo.bmiHeader.biClrUsed = dwNumColors;   
    bmpinfo.bmiHeader.biClrImportant = dwNumColors;    bitmap = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);    if(bitmap==NULL)   
    return FALSE;    HGDIOBJ gdiobj;   
    gdiobj = SelectObject(hdc2, (HGDIOBJ)bitmap);    if((gdiobj==NULL) || (gdiobj==(void *)GDI_ERROR))    
    {   
    DeleteDC(hdc2);   
    return FALSE;   
    }    if (!BitBlt(hdc2, 0,0, dwWidth, dwHeight, hdc, x,y, SRCCOPY))    
    return FALSE;   
    RGBQUAD colors[256];   
    if(dwNumColors!=0)    
    {   
    dwNumColors = GetDIBColorTable(hdc2, 0, dwNumColors, colors);   
    }   
    // Fill in bitmap structures    
    BITMAPFILEHEADER bitmapfileheader;   
    BITMAPINFOHEADER bitmapinfoheader;    bitmapfileheader.bfType = 0x4D42;   
    bitmapfileheader.bfSize = ((dwWidth * dwHeight * dwBPP)/8) + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));   
    bitmapfileheader.bfReserved1 = 0;   
    bitmapfileheader.bfReserved2 = 0;   
    bitmapfileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));      bitmapinfoheader.biSize = sizeof(BITMAPINFOHEADER);   
    bitmapinfoheader.biWidth = dwWidth;   
    bitmapinfoheader.biHeight = dwHeight;   
    bitmapinfoheader.biPlanes = 1;   
    bitmapinfoheader.biBitCount = (WORD)dwBPP;   
    bitmapinfoheader.biCompression = BI_RGB;   
    bitmapinfoheader.biSizeImage = 0;   
    bitmapinfoheader.biXPelsPerMeter = 0;   
    bitmapinfoheader.biYPelsPerMeter = 0;   
    bitmapinfoheader.biClrUsed = dwNumColors;   
    bitmapinfoheader.biClrImportant = 0;    // Write bitmap to disk    
    HANDLE hfile;   
    DWORD dwBytes;    hfile = CreateFileA(szFilePath,GENERIC_WRITE,0,NULL,CREATE_NEW|TRUNCATE_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);   
    if(hfile==INVALID_HANDLE_VALUE)    
    {   
    DeleteObject(bitmap);   
    DeleteDC(hdc2);   
    return FALSE;   
    }    WriteFile(hfile,&bitmapfileheader,sizeof(BITMAPFILEHEADER), &dwBytes, NULL);   
    WriteFile(hfile,&bitmapinfoheader,sizeof(BITMAPINFOHEADER), &dwBytes, NULL);   
    if(dwNumColors!=0)   
    WriteFile(hfile,colors,sizeof(RGBQUAD)*dwNumColors,&dwBytes,NULL);    WriteFile(hfile,pBits,(dwWidth*dwHeight*dwBPP)/8,&dwBytes,NULL);    CloseHandle(hfile);    // Clean up     DeleteObject(bitmap);   
    DeleteDC(hdc2);    return TRUE;   
    }   
      

  2.   

    写文件发生错误,可用CFile的方法。