Page 1 of 1

Print a Windown using PrintScreen key

Posted: Fri Feb 01, 2008 10:01 am
by graves
Hi,
Getting code from some topics on this forum, this is my solution:

Code: Select all

Enumeration
  #nWin
  #nText
  #NStrg
EndEnumeration

Procedure PrintScreen()
    nWin = GetActiveWindow()
    hDcDesktop  = GetDC_(GetDesktopWindow_())
    wx = WindowX(nWin)
    wy = WindowY(nWin)
    ww = WindowWidth(nWin) + 5
    wh = WindowHeight(nWin) + 25

    nImg = CreateImage(#PB_Any, ww, wh)
    hDC  = StartDrawing(ImageOutput(nImg))
      BitBlt_(hDC, 0, 0, ww, wh, hDcDesktop, wx, wy, #SRCCOPY)
    StopDrawing()
    ReleaseDC_(GetDesktopWindow_(), hDcDesktop)
    SetClipboardImage(nImg)

    if PrintRequester()
      StartPrinting(StringField(GetFilePart(ProgramFilename()),1,"."))
      StartDrawing(PrinterOutput())
        lmar = PrinterPageWidth() / 6
        tmar = lmar / 2
        pw   = lmar * 5
        lmar = lmar / 2
        ph   = pw * wh / ww
        DrawImage(ImageID(nImg),lmar,tmar, pw, ph)
      StopDrawing()
      StopPrinting()
    endif
    FreeImage(nImg)
EndProcedure


  OpenWindow(#nWin, 0, 0, 200, 100, "THE PRINT TEST", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  CreateGadgetList(WindowID(#nWin))
  TextGadget(#nText, 10, 20, 180, 20, "This is a Text for the Print Test")
  StringGadget(#nStrg, 10, 45, 180, 20, "This is a String Text for the Print Test")

  Repeat
    select WaitWindowEvent()
      case #PB_Event_CloseWindow : break
      case #WM_KEYUP: if EventwParam() = #VK_SNAPSHOT: PrintScreen(): endif
    endselect
  Forever
  CloseWindow(#nWin)
  END

Posted: Fri Feb 01, 2008 5:25 pm
by Rook Zimbabwe
I usually hold down the SHIFT button and then press the Print Screen... But this looks interesting.

Posted: Fri Feb 01, 2008 9:00 pm
by Mistrel
Rook Zimbabwe wrote:I usually hold down the SHIFT button and then press the Print Screen... But this looks interesting.
What does shift do? Alt-PrtSc copies only the active window.