Print Screen Command?

For other topics related to the FreeBASIC project or its community.
N6DC
Posts: 2
Joined: Aug 03, 2019 7:09

Print Screen Command?

Postby N6DC » Aug 03, 2019 7:15

In the old DOS BASICs, there was a convenient "Print Screen" command that allowed whatever was on the monitor to be printed to the printer. This command was typically activated by pressing the "PrtScr" key, sometimes preceded by the Shift Key.

This feature was very convenient and I have a fair number of BASIC programs that rely on this. Is there a similar command in FreeBasic, or at least a convenient work-around?

V/R,
Alex
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: Print Screen Command?

Postby BasicScience » Aug 11, 2019 22:31

I just save the screen to a BMP file. You can the print, edit, or perform any other modification.

Code: Select all

BSave "ScreenShot.BMP", 0
N6DC
Posts: 2
Joined: Aug 03, 2019 7:09

Re: Print Screen Command?

Postby N6DC » Aug 25, 2019 1:26

Right, and thanks for that response. Prior to my post, I had tried my Windows snipping tool for this purpose, but found it to be cumbersome in that it did not allow the snipped image to be sent directly to the printer (as the original MS-DOS PrtScrn so conveniently did). Instead, I had to save it to a graphics file, open that file in my image editor, make necessary adjustments, and then finally send the image to the printer.

After some searching, I was able to fine a better snipping tool. This is Gadwin PrintScreen. Even in its free demo version, it's very convenient in that it allows the snipped image to be directly sent to the printer (without the need for opening a separate image editor). The Pro version (which is very inexpensive) allows image editing within the program. It's still not quite as convenient as the the old MS-DOS PrtScrn, but it's a very capable and acceptable work-around. I highly recommend it to interested users.

V/R,
Alex
dodicat
Posts: 6641
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Print Screen Command?

Postby dodicat » Aug 25, 2019 17:25

I found this code.
press the Print Screen key.
or
Alt + Print Screen if you want only a window printed.
your image is now on the clipboard.
Now run this code to view it and print it.

Code: Select all

 CONST w = 800
CONST _h = 600

#INCLUDE "fbgfx.bi"
#INCLUDE ONCE "windows.bi"

DECLARE FUNCTION get_clip() AS HBITMAP
DECLARE FUNCTION set_clip(bitmap AS STRING) AS HBITMAP

SCREENRES w, _h, 32
'set_clip("bild.bmp")

DIM AS BITMAPINFO BitmapInfo
DIM AS HDC display_dc      = GetDC( NULL )
DIM AS HDC bitmap_dc       = CreateCompatibleDC( display_dc )
DIM AS HBITMAP bitmap      = CreateCompatibleBitmap( display_dc, w, _h )
DIM AS HGDIOBJ null_bitmap = SelectObject( bitmap_dc, bitmap )

bitmap = get_clip()


DIM AS fb.image PTR optr = IMAGECREATE( w, _h )
optr->pitch = optr->WIDTH * 4
WITH BitmapInfo.bmiHeader
   .biSize     = SIZEOF(BITMAPINFOHEADER)
   .biWidth    = w
   .biHeight   = -_h
   .biPlanes   = 1
   .biBitCount = 32
END WITH

getdibits( bitmap_dc, bitmap, 0, _h, optr + 1, @BitmapInfo, DIB_RGB_COLORS )

SelectObject( bitmap_dc, null_bitmap )
DeleteDC( display_dc )
DeleteDC( bitmap_dc )
DeleteObject( bitmap )

PUT(0, 0), optr
bsave "picture.bmp",optr
IMAGEDESTROY(optr)
shell "mspaint /p picture.bmp"
sleep
kill "picture.bmp"
end


FUNCTION set_clip(bitmap AS STRING) AS HBITMAP
        DIM hBmp AS HANDLE
        hBmp = LoadImage(0, bitmap, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
        OpenClipboard(0)
        EmptyClipboard()
        SetClipboardData(CF_BITMAP, CopyImage(hBmp, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG))
        CloseClipboard()
        RETURN NULL
END FUNCTION

FUNCTION get_clip() AS HBITMAP
        DIM hBmp AS HANDLE
        IF IsClipboardFormatAvailable(CF_BITMAP) = 0 THEN
            RETURN NULL
        ENDIF
        IF OpenClipboard(0) = 0 THEN
            RETURN NULL
        ENDIF
        FUNCTION = GetClipboardData(CF_BITMAP)
        CloseClipboard()
END FUNCTION 

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests