Print a Windown using PrintScreen key
Posted: Fri Feb 01, 2008 10:01 am
Hi,
Getting code from some topics on this forum, this is my solution:
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