Announcement

Collapse
No announcement yet.

SS_PRINTFUNC header/footer callback Fn for Farpoint's Spread

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SS_PRINTFUNC header/footer callback Fn for Farpoint's Spread

    Has anyone used the print preview functionality of Farpoint's
    Spread DLL? Could you post a prototype (simple sample?) of the
    SS_PRINTFUNC callback for creating page headers/footers?

    I've got a bare bones function working:

    Code:
    FUNCTION SS_PRINTFUNC%( BYVAL hDC&, BYVAL dCommand%, BYVAL nPageNum%, BYVAL lAppData&, lpPrintInfo AS SS_PRINTINFO)
    
       SELECT CASE dCommand%
          CASE %SS_PRINTCMD_HEADERLEN
             FUNCTION = 800            'Just to test
          CASE %SS_PRINTCMD_FOOTERLEN
             FUNCTION = 120            'Just to test
          CASE %SS_PRINTCMD_PRINTHEADER
          CASE %SS_PRINTCMD_PRINTFOOTER
       END SELECT
    
    END FUNCTION
    but I'm now venturing into new territory (for me). My goal is to
    define a header & footer using Arial 12pt & 10pt fonts and a few
    lines for borders.

    Any help would be most appreciated.



    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

  • #2
    Crud.

    There is something wrong with my function declaration. I
    cannot seem to access the elements of the lpPrintInfo UDT. I keep
    getting "This program has performed an illegal operation...." errors
    any time I try to access an element.

    I've translated :


    Code:
    short CALLBACK SS_PRINTFUNC(HDC hDC, short dCommand, short nPageNum, LONG lAppData, LPSS_PRINTINFO lpPrintInfo);

    into :


    Code:
    FUNCTION SS_PRINTFUNC%( BYVAL hDC&, BYVAL dCommand%, BYVAL nPageNum%, BYVAL lAppData&, lpPrintInfo AS SS_PRINTINFO)

    I've experimented with changing the lpPrintInfo declaration to an
    SS_PRINTINFO PTR and a BYVAL DWORD (which I then assign to a ptr).
    No luck with either method. Anyone have any ideas what I'm doing wrong?

    P.S. If I don't try to access the lpPrintInfo elements, I get no errors
    and dCommand% appears to contain the correct info.



    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

    Comment


    • #3
      Forgot to add my UDT translation. Maybe something wrong here???

      Code:
      typedef struct ss_printinfo
         {
         BOOL fIsPreview;
         HDC  hDCPrinter;
         RECT RectPreview;
         RECT RectPrinter;
         HWND hWndSpread;
         LONG lXtra;
         } SS_PRINTINFO, FAR *LPSS_PRINTINFO;
      
      
      was translated to
      
      
      TYPE ss_printinfo
        fIsPreview      AS LONG
        hDCPrinter      AS LONG
        RectPreview     AS RECT
        RectPrinter     AS RECT
        hWndSpread      AS LONG
        lXtra           AS LONG
      END TYPE

      ------------------
      Bernard Ertl
      Bernard Ertl
      InterPlan Systems

      Comment


      • #4
        Bern,
        I have never used the Print Preview but from what you are asking
        it appears you are mixing up the Spread Control and the Print Preview control??

        You would set headers and footers using the normal Spread control not the print
        preview one??

        James



        ------------------

        Comment


        • #5
          Hi James,

          I'm pretty sure I'm not confused. It works like this:

          1a) Define SS_PRINTFUNC% callback function
          1) Create a dialog
          2) Add a Spread control
          3) Customize Spread / add data
          4) Set print options using SSSetPrintOptions
          (set CODEPTR to callback in this step)
          5) Create new dialog
          6) Add Print Preview Control
          7) Bind Preview to Spread using SpvSethWndSpread

          The Preview control then uses the callback function identified
          in the print options (using the CODEPTR) to reserve space &
          display any headers or footers.

          The callback function is used by the Spread control when printing
          to the printer device (using SSPrint) and by the Preview control.

          I can currently view the preview and verify that it is reserving
          the space for the headers / footers which my callback function is
          specifying. The problem occurs when I try to access the UDT
          parameter.

          Any ideas?




          ------------------
          Bernard Ertl
          Bernard Ertl
          InterPlan Systems

          Comment


          • #6
            Bern,
            It is me that is confused....

            Maybe they are returning GlobalAlloc Handle??
            Try locking ???

            James



            ------------------

            Comment


            • #7
              hi james, et al.

              problem solved. the dll passes null pointers half the time.

              see...
              http://www.powerbasic.com/support/pb...ead.php?t=3787

              for my solution.

              thanks!


              ------------------
              bernard ertl
              Bernard Ertl
              InterPlan Systems

              Comment


              • #8
                After more wrangling, I think I've finally got a working skeleton
                for the SS_PRINTFUNC% callback. Here it is for anyone else who
                wants to print with Farpoint's Spread DLL.

                If you find errors in it or are able to improve it, please post
                a message and let me know. Thanks.

                Code:
                FUNCTION SS_PRINTFUNC%( BYVAL hDC&, BYVAL dCommand%, BYVAL nPageNum%, BYVAL lAppData&, BYVAL addrPrintInfo AS DWORD)
                
                
                   LOCAL hCurrentDC&, Dummy1&
                   LOCAL CurrentRect  AS RECT
                   LOCAL szTemp       AS ASCIIZ * 2400
                   LOCAL ptrPrintInfo AS SS_PRINTINFO PTR
                   LOCAL hFont        AS DWORD
                   LOCAL tFont        AS LOGFONT
                
                
                   IF addrPrintInfo > 0 THEN
                      ptrPrintInfo = addrPrintInfo
                      IF @ptrPrintInfo.fIsPreview <> 0 THEN
                         'Current device is Preview control
                         hCurrentDC& = hDC&
                         CurrentRect = @ptrPrintInfo.RectPreview
                         'Get 10 pt font for Printer Device
                         tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( @ptrPrintInfo.hDCPrinter, %LOGPIXELSY), 72)
                         'Scale font
                         Dummy1& = GetDeviceCaps( @ptrPrintInfo.hDCPrinter, %VERTRES)
                         tFont.lfHeight = (CSNG(tFont.lfHeight) *  _
                                 ((CurrentRect.nBottom - CurrentRect.nTop) / Dummy1&))
                      ELSE
                         'Printer device is current device
                         hCurrentDC& = @ptrPrintInfo.hDCPrinter
                         CurrentRect = @ptrPrintInfo.RectPrinter
                         tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( hCurrentDC&, %LOGPIXELSY), 72)
                      END IF
                   ELSE
                      'NULL pointer passed when DLL wants header/footer height
                      hCurrentDC& = hDC&
                      tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( hCurrentDC&, %LOGPIXELSY), 72)
                   END IF
                
                
                   tFont.lfWeight = 700  'Bold
                   tFont.lfQuality = %PROOF_QUALITY
                   tFont.lfFaceName = "Arial"
                   hFont = CreateFontIndirect( tFont)
                
                
                   SelectObject hCurrentDC&, hFont
                   SELECT CASE dCommand%
                      CASE %SS_PRINTCMD_HEADERLEN
                         'Set to 4 lines
                         szTemp = "H" + $CRLF + "H" + $CRLF + "H" + $CRLF + "H"
                         CurrentRect.nRight = 800  'Dummy width
                         FUNCTION = DrawText( hCurrentDC&, szTemp, -1, CurrentRect, %DT_CALCRECT OR %DT_WORDBREAK OR %DT_EXTERNALLEADING)
                      CASE %SS_PRINTCMD_FOOTERLEN
                         'Set to 5 lines
                         szTemp = "H" + $CRLF + "H" + $CRLF + "H" + $CRLF + "H" + $CRLF + "H"
                         CurrentRect.nRight = 800  'Dummy width
                         FUNCTION = DrawText( hCurrentDC&, szTemp, -1, CurrentRect, %DT_CALCRECT OR %DT_WORDBREAK OR %DT_EXTERNALLEADING) + 2
                      CASE %SS_PRINTCMD_PRINTHEADER
                         szTemp = "Super" + $CRLF + _
                                  "Duper" + $CRLF + _
                                  "Program"
                         DrawText hCurrentDC&, szTemp, -1, CurrentRect, %DT_LEFT OR %DT_NOPREFIX OR %DT_WORDBREAK
                         szTemp = "Client" + $CRLF + $CRLF + _
                                  "Data File Title"
                         DrawText hCurrentDC&, szTemp, -1, CurrentRect, %DT_CENTER OR %DT_NOPREFIX OR %DT_WORDBREAK
                         szTemp = "Report Name    " + $CRLF + $CRLF + _
                                  "User Name    "
                         DrawText hCurrentDC&, szTemp, -1, CurrentRect, %DT_RIGHT OR %DT_NOPREFIX OR %DT_WORDBREAK
                      CASE %SS_PRINTCMD_PRINTFOOTER
                         szTemp = "Report Criteria :" + $CRLF + $CRLF + $CRLF + $CRLF + _
                                  DATE$ + " @ " + TIME$
                         DrawText hCurrentDC&, szTemp, -1, CurrentRect, %DT_LEFT OR %DT_NOPREFIX OR %DT_WORDBREAK
                         szTemp = $CRLF +  $CRLF + $CRLF + $CRLF + _
                                  "Page"+STR$( nPageNum%)
                         DrawText hCurrentDC&, szTemp, -1, CurrentRect, %DT_CENTER OR %DT_NOPREFIX OR %DT_WORDBREAK
                         szTemp = "Legend :  None    " + $CRLF + $CRLF + $CRLF + $CRLF + _
                                  "cc: J. Doe, J. Smith    "
                         DrawText hCurrentDC&, szTemp, -1, CurrentRect, %DT_RIGHT OR %DT_NOPREFIX OR %DT_WORDBREAK
                   END SELECT
                   DeleteObject hFont
                
                
                END FUNCTION
                ------------------
                Bernard Ertl
                Bernard Ertl
                InterPlan Systems

                Comment


                • #9
                  Aye Caramba!

                  Well, my callback function skeleton as posted above only works
                  for print previews. I've had to make a few changes to get it to
                  work with the printer.

                  Here's the new & improved skeleton ...

                  Code:
                  FUNCTION SS_PRINTFUNC%( BYVAL hDC&, BYVAL dCommand%, BYVAL nPageNum%, BYVAL lAppData&, BYVAL addrPrintInfo AS DWORD)
                  
                  
                     LOCAL CurrentRect AS RECT
                     LOCAL szTemp AS ASCIIZ * 2400
                     LOCAL ptrPrintInfo AS SS_PRINTINFO PTR
                     LOCAL hFont AS DWORD
                     LOCAL ptrRI AS Report_Info PTR
                     LOCAL tFont AS LOGFONT
                  
                  
                     IF addrPrintInfo > 0 THEN
                        ptrPrintInfo = addrPrintInfo
                        IF @ptrPrintInfo.fIsPreview <> 0 THEN
                           CurrentRect = @ptrPrintInfo.RectPreview
                           'Get 10 pt font for Printer Device
                           tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( @ptrPrintInfo.hDCPrinter, %LOGPIXELSY), 72)
                           'Scale font
                           tFont.lfHeight = (CSNG(tFont.lfHeight) *  _
                                   ((CurrentRect.nBottom - CurrentRect.nTop) / _
                                   GetDeviceCaps( @ptrPrintInfo.hDCPrinter, %VERTRES)))
                           tFont.lfQuality = %DEFAULT_QUALITY
                        ELSE
                           CurrentRect.nRight = GetDeviceCaps( hDC&, %HORZRES)
                           CurrentRect.nBottom = GetDeviceCaps( hDC&, %VERTRES)
                           tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( hDC&, %LOGPIXELSY), 72)
                           tFont.lfQuality = %PROOF_QUALITY
                        END IF
                     ELSE
                        tFont.lfHeight = -MulDiv( 10, GetDeviceCaps( hDC&, %LOGPIXELSY), 72)
                        tFont.lfQuality = %PROOF_QUALITY
                     END IF
                  
                  
                     tFont.lfWeight = 700  'Bold
                     tFont.lfFaceName = "Arial"
                     hFont = CreateFontIndirect( tFont)
                     ptrRI = lAppData&
                  
                  
                     SelectObject hDC&, hFont
                     SELECT CASE dCommand%
                        CASE %SS_PRINTCMD_HEADERLEN
                           'Set to 4 lines
                           szTemp = "H" + REPEAT$( 3, $CRLF + "H")
                           CurrentRect.nRight = 800  'Dummy width
                           FUNCTION = DrawText( hDC&, szTemp, -1, CurrentRect, %DT_CALCRECT OR %DT_WORDBREAK OR %DT_EXTERNALLEADING)
                        CASE %SS_PRINTCMD_FOOTERLEN
                           'Set to 5 lines
                           szTemp = "H" + REPEAT$( 4, $CRLF + "H")
                           CurrentRect.nRight = 800  'Dummy width
                           FUNCTION = DrawText( hDC&, szTemp, -1, CurrentRect, %DT_CALCRECT OR %DT_WORDBREAK OR %DT_EXTERNALLEADING) + 2
                        CASE %SS_PRINTCMD_PRINTHEADER
                           CurrentRect.nRight = CurrentRect.nRight - 5
                           szTemp = "Super" + $CRLF + _
                                    "Duper" + $CRLF + _
                                    "Program"
                           DrawText hDC&, szTemp, -1, CurrentRect, %DT_LEFT OR %DT_NOPREFIX OR %DT_WORDBREAK
                           szTemp = "Client Name" + $CRLF + $CRLF + _
                                    "Title"
                           DrawText hDC&, szTemp, -1, CurrentRect, %DT_CENTER OR %DT_NOPREFIX OR %DT_WORDBREAK
                           szTemp = "Report Name    " + $CRLF +  $CRLF + _
                                    "User Name    "
                           DrawText hDC&, szTemp, -1, CurrentRect, %DT_RIGHT OR %DT_NOPREFIX OR %DT_WORDBREAK
                        CASE %SS_PRINTCMD_PRINTFOOTER
                           szTemp = "Report Criteria : " + $CRLF + $CRLF + $CRLF + $CRLF + _
                                    DATE$ + " @ " + TIME$
                           DrawText hDC&, szTemp, -1, CurrentRect, %DT_LEFT OR %DT_NOPREFIX OR %DT_WORDBREAK OR %DT_EXPANDTABS
                           szTemp = $CRLF +  $CRLF + $CRLF + $CRLF + _
                                    "Page" + STR$( nPageNum%)
                           DrawText hDC&, szTemp, -1, CurrentRect, %DT_CENTER OR %DT_NOPREFIX OR %DT_WORDBREAK
                           szTemp = $CRLF + $CRLF + $CRLF + $CRLF + "cc: John Doe    "
                           DrawText hDC&, szTemp, -1, CurrentRect, %DT_RIGHT OR %DT_NOPREFIX OR %DT_WORDBREAK OR %DT_EXPANDTABS
                     END SELECT
                     DeleteObject hFont
                  
                  
                  END FUNCTION
                  ------------------
                  Bernard Ertl

                  [This message has been edited by Bern Ertl (edited May 30, 2001).]
                  Bernard Ertl
                  InterPlan Systems

                  Comment


                  • #10
                    You are not supposed to delete an object selected into a Device context,
                    unless of course you want to create a resource leak.
                    Create another variable:
                    Code:
                      hFontOld AS LONG
                    When you Select your font into the device context:
                    Code:
                      hFontOld = SelectObject(hDC&, hFont)
                    When you Destroy your GDI objects:
                    Code:
                      SelectObject hDC&, hFontOld
                      DeleteObject hFont
                    regards,


                    ------------------
                    [email protected]
                    :) IRC :)

                    Comment


                    • #11
                      Thanks Ian!

                      This is new ground for me....



                      ------------------
                      Bernard Ertl
                      Bernard Ertl
                      InterPlan Systems

                      Comment

                      Working...
                      X