Results 1 to 8 of 8

Thread: Drawing a resource bmp to a printer

  1. #1
    guest Guest

    Default Drawing a resource bmp to a printer

    I want to draw a bitmap held as a resource in the exe to a printer. The help file implies I only need do the following but it doesn't work. Am I missing something?

    hbmp = ISLoadResourceBitmap(hinst,"IDB_BETA",NULL);
    ISDrawHBITMAP(hdcPrt,hbmp,10,10,50,50,NULL);

    thanks for any help.

  2. #2
    Join Date
    Mar 2006
    Location
    Raleigh, NC
    Posts
    1,356

    Default RE: Drawing a resource bmp to a printer

    >I want to draw a bitmap held as a resource in the exe to a printer.
    >The help file implies I only need do the following but it doesn't
    >work.

    what happens?
    is the HBITMAP valid?
    can the printer handle BitBlt?

    try calling IS3GetLastError after each call.


    --
    chris losinger
    smallest@smalleranimals.com
    Chris Losinger
    Smaller Animals Software, Inc

  3. #3
    guest Guest

    Default RE: Drawing a resource bmp to a printer

    Chris,
    calling ISGetLastError I get:

    0 after ISLoadResourceBitmap and the handle is not null
    37 after ISDrawHBITMAP

    then GetDeviceCaps(hDC,RASTERCAPS); returns 28313 which ANDs with RC_BITBLT to indicate it should be ok.

    Dave


  4. #4
    Join Date
    Mar 2006
    Location
    Raleigh, NC
    Posts
    1,356

    Default RE: Drawing a resource bmp to a printer

    >37 after ISDrawHBITMAP

    how big is that bitmap?

    the IS3DrawHBITMAP function works like this:

    1. create a memory-based DC based on the DC you passed in
    2. call ::SelectObject to select the HBITMAP you passed in into that memory-DC
    3. BitBlt from the memory-DC to the output DC
    4. de-select your HBITMAP from the memory DC

    the IS_ERR_SELECTOBJ error happens when step 2 fails.

    here's the code (it's just the standard BitBlt operation that you can find anywhere) :

    Code:
       if (hBmp==NULL) 
       {
          m_error=IS_ERR_BADPARAM;
          return FALSE;
       }
       
       int iCaps = ::GetDeviceCaps(outDC, RASTERCAPS);
       if ((iCaps & RC_BITBLT) != RC_BITBLT)
       {
          m_error=IS_ERR_NODEVOP;
          return FALSE;
       }
       
       // select our palette - on 16 and 24-bit displays, palettes have no effect.
       if (hPal==NULL)
          hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
       
       HPALETTE hOldPal;
       hOldPal = ::SelectPalette(outDC, hPal, FALSE);
       ::RealizePalette(outDC);
       
       // create a DC to select our HBITMAP into
       HDC hMemDC;
       hMemDC = ::CreateCompatibleDC(outDC);
       if (hMemDC==NULL) 
       {
          m_error=IS_ERR_DC;
          ::SelectPalette(outDC, hOldPal, FALSE);
          return FALSE;
       }
       
       // let the memDC play, too
       SelectPalette(hMemDC, hPal, FALSE);
       
       // select HBITMAP into our DC
       HBITMAP olh=(HBITMAP )::SelectObject(hMemDC,hBmp);
       if (olh==NULL)
       {
          m_error=IS_ERR_SELECTOBJ;
          ::SelectPalette(outDC, hOldPal, FALSE);
          ::DeleteDC(hMemDC);
          return FALSE;
       }
    
       // copy to screen
       if (!::BitBlt(outDC,
          xPos, yPos,
          outWidth, outHeight,
          hMemDC,
          srcXStart, srcYStart,
          SRCCOPY))
       {
          m_error = IS_ERR_BITBLT;
       }
       
       // clean up
       ::SelectPalette(outDC, hOldPal, FALSE);
       ::SelectObject(hMemDC,olh);
       ::DeleteDC(hMemDC);
    you might try calling ::GetLastError (not IS3GetLastError) after the SelectObject call, to see if Windows can tell you anything else about what happened.

    --
    chris losinger
    smallest@smalleranimals.com
    Chris Losinger
    Smaller Animals Software, Inc

  5. #5
    guest Guest

    Default RE: Drawing a resource bmp to a printer

    Chris,

    I've tried your code and the problem is SelectObject. GetLastError returns 87 - Invalid Parameter. It's got me puzzled. The bitmap is only 70x17 pixels and was created in VS6 using Insert Bitmap in the resource editor.

    Dave

  6. #6
    Join Date
    Mar 2006
    Location
    Raleigh, NC
    Posts
    1,356

    Default RE: Drawing a resource bmp to a printer

    is the resource named "IDB_BETA" (with quotes) or is IDB_BETA a numeric value?

    as a test, i added a Bitmap resource to my test app by right-clicking the project's resource tree, choosing "Insert...", then selecting "Bitmap...", then "New...", browsing out and selecting a .BMP file. then i changed the resource name from IDB_BITMAP1 (the default, which is a numeric value) to "IDB_BITMAP1" (including the quotes).

    then i ran this code, and it worked:
    Code:
       CClientDC dc(this);
       HINSTANCE hisnt = AfxGetInstanceHandle();
       HBITMAP hbmp = ISLoadResourceBitmap(hisnt,"BITMAP1",NULL);
       ISDrawHBITMAP(dc.m_hDC,hbmp,10,10,50,50,NULL);
       DeleteObject(hbmp);
    --
    chris losinger
    smallest@smalleranimals.com
    Chris Losinger
    Smaller Animals Software, Inc

  7. #7
    guest Guest

    Default RE: Drawing a resource bmp to a printer

    If you don't want to include the quotes then you can use the MAKEINTRESOURCE Macro to turn the value IDB_BETA, ex: MAKEINTRESOURCE(IDB_BETA), into the usable form for the GDI calls used by the ISLoadResourceBitmap function.

    - Timothy

  8. #8
    guest Guest

    Default RE: Drawing a resource bmp to a printer

    Chris,
    I used your code in a test app and it worked fine. But I still can't get it to work with a printer DC although I can TextOut ok to it. Thanks for looking at it.
    cheers
    Dave Risley

Posting Permissions

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