[HELP] Print Preview

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Num3.


Can anyone help with this one?
After solving the direct print problem i got i bit stuck with printing to a bitmap a placing it on a window for print preview...

I get a fully black bitmap:cry:

Grrrr.....

--
Kind Regards
Rui Carvalho

Old programmers never die... They branch into a subroutine...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Is this what you need?:

Code: Select all

Procedure PaintHook(hwndDlg, uMsg, wParam, lParam)
  result = #FALSE
  If uMsg=#WM_PSD_FULLPAGERECT
    *rc.RECT = lParam
    hDC = GetDC_(WindowID())
    mDC = CreateCompatibleDC_(hDC)
    ReleaseDC_(WindowID(), hDC)
    ImageWidth = ImageWidth()
    ImageHeight = ImageHeight()
    hBitmap = CreateCompatibleBitmap_(hDC, ImageWidth, ImageHeight)
    SelectObject_(mDC, hBitmap)
    OldObject = SelectObject_(mDC, UseImage(0))
    width = *rc\right-*rc\left
    height = (width*ImageHeight)/ImageWidth
    StretchBlt_(wParam, 0, 0, width, height, mDC, 0, 0, ImageWidth, ImageHeight, #SRCCOPY)
    SelectObject_(mDC, OldObject)
    DeleteDC_(mDC)
    result = #TRUE
  EndIf
  ProcedureReturn result
EndProcedure

Structure PAGESETUPDLG
    lStructSize.l
    hwndOwner.l
    hDevMode.l
    hDevNames.l
    Flags.l
    ptPaperSize.POINT
    rtMinMargin.RECT
    rtMargin.RECT
    hInstance.l
    lCustData.l
    lpfnPageSetupHook.l
    lpfnPagePaintHook.l
    lpPageSetupTemplateName.l
    hPageSetupTemplate.l
EndStructure

#IDM_FILE_PAGESETUP = 0
If OpenWindow(0, 128, 96, 320, 256, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "Bitmap print preview example")
  If CreateGadgetList(WindowID())
    CreateImage(0, WindowWidth(), WindowHeight())
    StartDrawing(ImageOutput())
    Box(0, 0, WindowWidth(), WindowHeight(), $ff0000)
    FrontColor(0, 0, 0)
    DrawingMode(1)
    DrawingFont(LoadFont(0, "Times New Roman", 24))
    Locate(64, 64)
    DrawText("Print preview")
    DrawingFont(LoadFont(0, "Verdana", 8))
    Locate(32, 128)
    DrawText("BTW, it would be nice to have")
    Locate(32, 140)
    DrawText("an equivalent to GetTextExtent32_()")
    Locate(32, 152)
    DrawText("in PB.")
    StopDrawing()
    ButtonImageGadget = ButtonImageGadget(#IDM_FILE_PAGESETUP, 0, 0, WindowWidth(), WindowHeight(), UseImage(0))
    Repeat
      EventID = WaitWindowEvent()
      If EventID=#PB_EventGadget And EventGadgetID()=#IDM_FILE_PAGESETUP
        ;In this example, the PSD_MARGINS value directs the function
        ;to set the initial margin values as specified in the rtMargin member.
        ;In this case, the initial and returned margin values are expressed in
        ;thousands of an inch.
        ;The initial paper size is the paper size specified in the device mode identified
        ;by the hDevMode member of the PAGESETUPDLG structure, or by the
        ;default printer's device mode if no printer was specified.
        psd.PAGESETUPDLG;    // common dialog box structure
        psd\lStructSize = SizeOf(PAGESETUPDLG)
        psd\hwndOwner = WindowID()
        psd\hDevMode = #NULL;    // don't  forget to free or store hDevMode
        psd\hDevNames = #NULL;  // don't forget to free or store hDevNames
        psd\Flags = #PSD_INTHOUSANDTHSOFINCHES|#PSD_MARGINS|#PSD_ENABLEPAGEPAINTHOOK; 
        psd\rtMargin\top = 1000
        psd\rtMargin\left = 1250
        psd\rtMargin\right = 1250
        psd\rtMargin\bottom = 1000
        psd\lpfnPagePaintHook = @PaintHook()
        If PageSetupDlg_(psd)
          ;    // check paper size and margin values here
        EndIf
      EndIf
    Until EventID=#PB_EventCloseWindow
  EndIf
EndIf
End
El_Choni
Post Reply