Board index » cppbuilder » Printing a TreeView

Printing a TreeView

I would like to print a TreeView.
I tried with a PaintTo(Printer()...
It worked but it was about 1 cm x 1 cm on the page !!!
Is there a way to scale it or another way to print it the size I want?
Thanx for any help
 

Re:Printing a TreeView


Hi Styves,

Quote
> I would like to print a TreeView.
> I tried with a PaintTo(Printer()...
> It worked but it was about 1 cm x 1 cm on the page !!!
> Is there a way to scale it or another way to print it the size I want?

Instead of using the PaintTo() method to draw the TreeView directly to the
printer's device context, go through an intermediate bitmap which can be scaled
via StretchDIBits().  You can calculate the scaling factors using a function
similar to the following...

void GetScale(float &xSPR, float &ySPR)
{
    // get the printer name, driver, and port in one buffer
    char buffer[MAX_PATH];
    GetProfileString("windows", "device", "no printer",
                     buffer, MAX_PATH);

    AnsiString Abuffer(buffer);
    AnsiString Device, Driver, Port;

    // parse the buffer to extract individual properties
    Device = Abuffer.SubString(1, Abuffer.Pos(",") - 1);
    Abuffer = Abuffer.SubString(Abuffer.Pos(",") + 1,
                                Abuffer.Length() - Abuffer.Pos(","));
    Driver = Abuffer.SubString(1, Abuffer.Pos(",") - 1);
    Port = Abuffer.SubString(Abuffer.Pos(",") + 1,
                             Abuffer.Length() - Abuffer.Pos(","));

    // create a printer device context
    HDC HPrinterDC = CreateDC(Driver.c_str(), Device.c_str(),
                              Port.c_str(), NULL);
    float fXPrinter, fYPrinter;
    fXPrinter = (float)GetDeviceCaps(HPrinterDC, LOGPIXELSX);
    fYPrinter = (float)GetDeviceCaps(HPrinterDC, LOGPIXELSY);
    DeleteDC(HPrinterDC);

    // get the screen's device context
    HDC HScreenDC = GetDC(0);
    float fXScreen, fYScreen;
    fXScreen = (float)GetDeviceCaps(HScreenDC, LOGPIXELSX);
    fYScreen = (float)GetDeviceCaps(HScreenDC, LOGPIXELSY);
    ReleaseDC(0, HScreenDC);

    xSPR = fXScreen / fXPrinter;
    ySPR = fYScreen / fYPrinter;

Quote
}

Also, have a look at the following CAQ...

http://bcbcaq.freeservers.com/print_graphics.html

Good luck!

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Other Threads