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

    [RESOLVED] BitBlt issues with memory DC created from printer DC

    i have an issue with a fix i made to allow a flood filled object be printed...

    so, the full story is we were using the windows GDI FloodFill function, which we noticed doesnt work on printers, so what i found on the inet, was to create a memory DC, compatible with the printer DC, and make all my drawing operations on the memory DC, and then BitBlt it all at once to the printer DC (i had to change to use a recursive, color replacment flood fill function too, since the memory DC only allows what the main DC did)

    the problem is the memory DC seems to be a pixel or two bigger on the x and y, but i dont know what to do, when i get the selected bitmap from the memory DC, it shows it to be the correct size, i would like to use StretchBlt, but the values i have access to use as params for StretchBlt, make it no different than calling BitBlt

    heres my code:

    Code:
    HDC hMemPrnDC = CreateCompatibleDC (hPrnDC);
    HBITMAP hBitmap = CreateCompatibleBitmap (hPrnDC, iWidthLP, iHeightLP);
    HBITMAP hOldBitmap = SelectBitmap (hMemPrnDC, hBitmap);
    
        // paint the whole memory DC with the window color
    HBRUSH hBrush = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
    RECT rect;
        // add one to right and bottom, FillRect doesnt include the right and bottom edges
    SetRect (&rect, 0, 0, iWidthLP + 1, iHeightLP + 1);
        // NOTE: im doing this cause it starts out as all black
    FillRect (hMemPrnDC, &rect, hBrush);
    
        // delete object
    DeleteBrush (hBrush);
    
    //
    // do all my MoveToEx, LineTo, Ellipse, Arc, TextOut,
    // SetPixel, etc calls on hMemPrnDC here
    //
    
        // copy all the memory DC drawing data to the printer DC
    BitBlt (hPrnDC, 0, 0, iWidthLP, iHeightLP, hMemPrnDC, 0, 0, SRCCOPY);
    
        // select old bitmap, and clean up objects
    SelectBitmap (hMemPrnDC, hOldBitmap);
    DeleteBitmap (hBitmap);
    DeleteDC (hMemPrnDC);
    hMemPrnDC = NULL;
    here is a link to a PDF print where I draw straight to the printer DC: hPrnDC.pdf

    and here is the same but I draw to the memory DC then BitBlt it to the printer DC: hMemPrnDC.pdf

    now, I did enable my recursive flood fill function on the second, to show an example of what we are trying to achieve, it does the same without it, so that is not an issue

    as you can see, the bottom and right edge are cut off, I'm also concerned about the differences in font & line weight between the two, but not as much as the sizing mismatch

    NOTE: the filename printed at the top doesn't go through the memory DC, that is always drawn straight to the printer DC

    let me know if you need more info...

    thanks in advance!!!

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: BitBlt issues with memory DC created from printer DC

    Quote Originally Posted by winsim View Post
    the problem is the memory DC seems to be a pixel or two bigger on the x and y
    Typically, physical device context should operate on twips or some hi metric map mode, and know nothing about pixels.
    Best regards,
    Igor

  3. #3
    Join Date
    Sep 2013
    Posts
    2

    Re: BitBlt issues with memory DC created from printer DC

    I found a solution to my problem, more of a work-around, but it achieved the desired results...

    I only used the memory DC as a go between on the items that needed the recursive flood fill (GetPixel and SetPixel), so I draw them first to the memory DC, copy it all over to the printer DC and then draw everything else straight to the printer DC, seems to work just fine

    thanks for the help!

Tags for this Thread

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