Is there a way to delete the Alt+PrtScr image from Windows?
#3
I just figured out a windows API work-around...

Code: (Select All)
REM This utility will make store screen shots in the local directory.
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION FindWindowA& (BYVAL ClassName AS _OFFSET, WindowName$) 'handle by title
    FUNCTION GetKeyState% (BYVAL nVirtKey AS LONG) 'reads Windows key presses independently
    FUNCTION ShowWindow& (BYVAL hwnd AS LONG, BYVAL nCmdShow AS LONG) 'minimize or maximize
END DECLARE

SCREEN _NEWIMAGE(370, 90, 32)
_SCREENMOVE 0, 0

DO
    CLS
    _KEYCLEAR
    PRINT " Alt + PrtScr to screenshot active window."

    DO
        _LIMIT 10
    LOOP UNTIL GetKeyState(44) = 0

    DO
        _LIMIT 10
        IF GetKeyState(18) AND GetKeyState(44) THEN EXIT DO
    LOOP

    CLS: PRINT " Working..."

    img& = _CLIPBOARDIMAGE
    IF img& < -1 THEN
        ' Find the next sequential available screenshot number.
        DO
            num = num + 1
            num$ = LTRIM$(STR$(num))
            IF _FILEEXISTS("screenshot(" + num$ + ").bmp") = 0 THEN EXIT DO
        LOOP
        screenshot$ = "screenshot(" + num$ + ")"

        SaveImage img&, screenshot$

        IF img& < -1 THEN _FREEIMAGE img&

        DO
            i = i + 1
            IF _FILEEXISTS("screenshot(" + num$ + ").bmp") THEN
                PRINT: PRINT " Image saved..."
                _DELAY 1
                EXIT DO
            ELSE
                IF i = 10 THEN
                    PRINT: PRINT "Unable to capture screen image."
                    BEEP
                    END
                END IF
            END IF
        LOOP

    END IF
LOOP

SUB SaveImage (image AS LONG, filename AS STRING)
    ' Subroutine code by Rob, AKA Galleon Dragon available in QB64 Phoenix Wiki.
    bytesperpixel& = _PIXELSIZE(image&)
    IF bytesperpixel& = 0 THEN PRINT "Text modes ungsupported!": END
    IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
    x& = _WIDTH(image&)
    y& = _HEIGHT(image&)
    b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
    IF bytesperpixel& = 1 THEN
        FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
            cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
            b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
        NEXT
    END IF
    MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
    lastsource& = _SOURCE
    _SOURCE image&
    IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
    FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
        r$ = ""
        FOR px& = 0 TO x& - 1
            c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
            IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
        NEXT px&
        d$ = d$ + r$ + padder$
    NEXT py&
    _SOURCE lastsource&
    MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
    b$ = b$ + d$ ' total file data bytes to create file
    MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
    IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
    f& = FREEFILE
    OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
    OPEN filename$ + ext$ FOR BINARY AS #f&
    PUT #f&, , b$
    CLOSE #f&
END SUB

Rho, I think I did try -1 to no avail, but in case I only tried zero, I'll re-code it and let you know...

Pete
If eggs are brain food, Biden takes his scrambled.
Reply


Messages In This Thread
RE: Is there a way to delete the Alt+PrtScr image from Windows? - by Pete - 06-06-2022, 11:17 PM



Users browsing this thread: 2 Guest(s)