Board index » cppbuilder » Printing screen on a laser printer

Printing screen on a laser printer

I earlier received some help on printing a screen generated by a Turbo C
program on an Epson dot matrix printer.  I was pointed to some programs
in the technical information database that could do this.    I am
wondering if  there is any way I can print out the screen to a laser

Matthew Smith


Re:Printing screen on a laser printer

Hi Matthew,

> I am wondering if  there is any way I can print out the screen to a laser
> printer?

You can do a screen capture to get a bitmap of the screen, then use the
StretchDIBits() API function to send the image to the printer.  Here's a utility
function to capture the screen, translated from code originally posted by  Joe
C. Hecht...

void __fastcall CaptureScreen(Graphics::TBitmap *Bitmap)
    HDC HScreenDC = GetDC(0);
    Bitmap->Handle = CreateCompatibleBitmap(HScreenDC,

    int result = GetDeviceCaps(HScreenDC, RASTERCAPS);
    if (result & RC_PALETTE)
        int palette_size = GetDeviceCaps(HScreenDC, SIZEPALETTE);
        if (palette_size == 256)
            int size = sizeof(LOGPALETTE) + 256 * sizeof(PALET{*word*249}TRY);
            LPLOGPALETTE lplogpal =
                (LPLOGPALETTE) new unsigned char[size];
            lplogpal->palVersion = 0x300;
            lplogpal->palNumEntries = 256;
            GetSystemPalet{*word*249}tries(HScreenDC, 0, 256,
            Bitmap->Palette = CreatePalette(lplogpal);
            delete [] lplogpal;

    BitBlt(Bitmap->Canvas->Handle, 0, 0, Bitmap->Width,
           Bitmap->Height, HScreenDC, 0, 0,

    ReleaseDC(0, HScreenDC);


To get a DIB of the Bitmap, then send it to the printer, have a look at this

Good luck!

Damon Chandler
Answers to <Commonly Asked Questions>

Other Threads