CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2001
    Posts
    47

    Bitmap print using CreateDC/StartDoc/EndDoc

    By the way, I hate converting VB 3.0 to 6.0

    Can anyone tell me how I can print a bitmap that exists on a form in my app to a specified location on a page? This is the code I have so far (pardon the lack of Dims, I didn't think they were necessary):

    lf.lfHeight = yfntSm%
    lf.lfWidth = xFntSm%
    lf.lfEscapement = 0 ' normal
    lf.lfWeight = 400
    lf.lfFaceName = "Times New Roman" + Chr$(0)
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS
    lf.lfClipPrecision = OUT_DEFAULT_PRECIS
    lf.lfQuality = DEFAULT_QUALITY
    lf.lfPitchAndFamily = DEFAULT_PITCH Or FF_DONTCARE
    lf.lfCharSet = DEFAULT_CHARSET

    hFont = CreateFontIndirect(lf) 'Create the font
    di.cbSize = 20 ' Size of DOCINFO structure
    di.lpszDocName = "My Document" ' Set name of print job (Optional)


    Printer.TrackDefault = true 'Use default printer
    hPrintDC = CreateDC(Printer.DriverName, Printer.DeviceName, 0, 0)

    result = StartDoc(hPrintDC, di) 'Start a new print document
    result = StartPage(hPrintDC) 'Start a new page

    ' Select our font structure and save previous font info
    hOldfont = SelectObject(hPrintDC, hFont)

    ' Print some sample text
    result = TextOut(hPrintDC, 1000, 1000, "Hello World", 11)

    (Right here, I'd like to print frmSig!picSignature, which is a PictureBox, to the page. How do I do that!??)

    result = EndPage(hPrintDC) 'End the page
    result = EndDoc(hPrintDC) 'End the print job
    result = DeleteDC(hPrintDC) 'Delete the printer device context
    result = DeleteObject(hFont) 'Delete the font object

    I'm interfacing with various DLLs to access the Windows API, but I don't know which functions in the API that I need to print the bitmap. Any suggestions would be great!

    Thank you!!

    killRoy


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Bitmap print using CreateDC/StartDoc/EndDoc

    Here is a sample routine that uses StretchBlt to copy a picturebox to either another picturebox OR to a printer depending on what tgt is pointing to.
    tgt is a hdc. l,t,w,h are Left top width height for the stretchBlt.

    public Declare Function StretchBlt Lib "gdi32" (byval hdc as Long, byval X as Long, byval Y as Long, byval nWidth as Long, byval nHght as Long, byval hSrcDC as Long, byval XSrc as Long, byval YSrc as Long, byval nSrcWidth as Long, byval nSrcHeight as Long, byval dwRop as Long) as Long
    public Declare Function BitBlt Lib "gdi32" (byval hDestDC as Long, byval X as Long, byval Y as Long, byval nWidth as Long, byval nHeight as Long, byval hSrcDC as Long, byval XSrc as Long, byval YSrc as Long, byval dwRop as Long) as Long

    public Sub CopyPictureToTarget(Src as PictureBox, tgt as Variant, l, t, w, h)
    ' Do some Magic
    Dim hMemoryDC as Long
    Dim hOldBitMap as Long
    '
    ' Do some Magic
    hMemoryDC = CreateCompatibleDC(Src.hdc)
    hOldBitMap = SelectObject(hMemoryDC, Src.Picture)
    '
    ' Copy picture to the target hdc
    lret = StretchBlt(tgt, l, t, w, h, _
    hMemoryDC, 0, 0, Src.ScaleWidth, _
    Src.ScaleHeight, SRCAND)
    '
    If lret = 0 then Stop
    ' Restore the magic
    hOldBitMap = SelectObject(hMemoryDC, hOldBitMap)
    ' Cleanup
    lret = DeleteDC(hMemoryDC)

    End Sub





    John G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured