Re: printing in win

new topic     » goto parent     » topic index » view thread      » older message » newer message

>Jesse Kint  wrote:
>
>> i need some help does any one have a library/ solution
>> on how to print in win32.
>
>Another thing on my to-do list. And it looks like I'll have to look into
>postscript if I want to support it on the Linux platform. Bleah.
For text you can use the lately posted 'printdlg.ew'-routines [I don't knwo
who posted them] when you want to print bitmaps you may use the UNTESTED
code below. It needs win32lib.ew to run and you have probably to make same
routines / constant / vars in your win32lib.ew global. As soon as I have
time I will release the complete wrappers. To get the hdc you have to use
the PrintDialog in the 'printdlg.ew'-routines. I hope I've nothing left out.

Martin Schut

P.S. The code seems only to work for 1-bit bitmaps (monochrome bitmaps)

-------------- PARTIAL TESTED CODE -----------------

constant
    iCreateCompatibleDC = linkFunc(gdi32, "CreateCompatibleDC", {C_POINTER},
C_POINTER),
    iSelectObject = linkFunc(gdi32, "SelectObject", {C_POINTER, C_POINTER},
C_POINTER),
    iDeleteDC = linkFunc(gdi32, "DeleteDC", {C_POINTER}, C_POINTER),
    iStretchBlt = linkFunc(gdi32, "StretchBlt", {C_POINTER, C_INT, C_INT,
C_INT, C_INT, C_POINTER, C_INT, C_INT, C_INT, C_INT, C_LONG}, C_INT),
    iGetBitmapDimension = linkFunc(gdi32, "GetBitmapDimensionEx",
{C_POINTER, C_POINTER}, C_INT)

function CreateCompatibleDC(atom hdc)
    return c_func(iCreateCompatibleDC, {hdc})
end function

function SelectObject(atom hdc, atom object)
    return c_func(iSelectObject, {hdc, object})
end function

global function DeleteDC(atom hdc)
    return c_func(iDeleteDC, {hdc})
end function

function StretchBlt(atom hdcDest, integer nXOriginDest, integer
nYOriginDest,
    integer nWidthDest, integer nHeightDest, atom hdcSrc, integer
nXOriginSrc, integer nYOriginSrc,
    integer nWidthSrc, integer nHeightSrc, atom dwRop)

    return c_func(iStretchBlt, {hdcDest, nXOriginDest, nYOriginDest,
nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc,
nHeightSrc, dwRop})
end function

global procedure BitmapOut(atom hdc, integer x, integer y, integer width,
integer height, atom bmp)
    atom ok
    atom hdcMem, bmpInfo
    integer posX, posY

    bmpInfo = allocate_struct(SIZEOF_BITMAP)
    if not c_func(xGetObject, {bmp, SIZEOF_BITMAP, bmpInfo}) then
        return
    end if

    hdcMem = CreateCompatibleDC(hdc)
    posY = y
    posX = floor(x - (width / 2))

    ok = SelectObject(hdcMem, bmp)
    ok = StretchBlt(hdc, posX, posY, width, height, hdcMem, 0, 0,
fetch(bmpInfo, bmWidth), fetch(bmpInfo, bmHeight), SRCCOPY)

    ok = DeleteDC(hdcMem)
    free(bmpInfo)
end procedure

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu