Page 1 of 3

Printscreen on Windows 7

Posted: Fri Nov 19, 2010 1:26 am
by skiman
I'm using the following to take a printscreen to the clipboard. It seems as this isn't working anymore on Windows 7.

DLLFUNCTION keybd_event(mvkey,nscan,flags,xtra) USING STDCALL FROM USER32.DLL

PROCEDURE PrintScreen()
keybd_event(PS_SNAPSHOT,1,0,0)
RETURN

After calling this procedure, the screendump was saved to the clipboard. On Windows 7 this is a big black bitmap.

Anyone who has a printscreen which is doing the same and working on Windows7?

Re: Printscreen on Windows 7

Posted: Fri Nov 19, 2010 9:33 am
by rdonnay
Chris -

Try this. I tested it on XP. I don't have my Win 7 computer here at the moment, but I suspect it will work.

Roger

Code: Select all

FUNCTION Main()

SaveScreen2Clipboard()

RETURN nil

PROC appsys ; return

FUNCTION SaveScreen2ClipBoard()

LOCAL oBitmap, oXbp, oSourcePS, oClipBoard

oXbp := AppDeskTop()

oSourcePS := oXbp:LockPS()
oBitmap := GraSaveScreen( oSourcePS, {0,0}, oXbp:currentSize() )

oClipBoard := XbpClipBoard():new():create()
oClipBoard:open()
oClipBoard:setBuffer(oBitMap)
oClipBoard:close()
oClipBoard:destroy()

RETURN nil

Re: Printscreen on Windows 7

Posted: Fri Nov 19, 2010 10:01 am
by skiman
Hi Roger,

No, this isn't working on my Windows 7 64 Bit. The result is a black window.
On my XP it is working without problem.

Re: Printscreen on Windows 7

Posted: Fri Nov 19, 2010 3:04 pm
by Auge_Ohr
hi,

did you have a "clipbrd.exe" on your Win7 PC ?

i have test Roger´s Code, but no Luck under Win7 32bit
btw. if i "press" PrintScreen it work

while GraSaveScreen() is just a UDF, here Code i use

Code: Select all

FUNCTION GraSaveScreen( oSourcePS, aPos, aSize ) 
L[code]OCAL oBitmap   := XbpBitmap():new():create( oSourcePS ) 
LOCAL oTargetPS := XbpPresSpace():new():create() 
LOCAL aSourceRect[4], aTargetRect 

  aSourceRect[1] := aSourceRect[3] := aPos[1] 
  aSourceRect[2] := aSourceRect[4] := aPos[2] 
  aSourceRect[3] += aSize[1] 
  aSourceRect[4] += aSize[2] 

  aTargetRect    := {0, 0, aSize[1], aSize[2]} [code]
[/code]

oBitmap:presSpace( oTargetPS )
oBitmap:make( aSize[1], aSize[2] )

GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )

RETURN oBitmap[/code]

edit : sorry i have to correct, Roger´s Code does get "manuell" PrintScreen into "clipbrd.exe"

this Code does work on my Win7 32bit

Code: Select all

#INCLUDE "xbp.ch"
#INCLUDE "Gra.ch"
#INCLUDE "DLL.ch"
#INCLUDE "Appevent.ch"

#define VK_SNAPSHOT     0x2C
#define KEYEVENTF_KEYUP 0x2

DLLFUNCTION keybd_event(mvkey,nscan,flags,xtra) USING STDCALL FROM USER32.DLL

FUNCTION Main()
 keybd_event(VK_SNAPSHOT, 0, 0, 0)
 keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)

* keybd_event(VK_SNAPSHOT,1,0,0)
 SLEEP(100)
 SaveScreen2Clipboard()

RETURN nil

PROC appsys ; return
edit : correction ... "sometimes" it work ... depends on how many "Windows" i have open ...

... hm .. a SLEEP(100) between keybd_event() and SaveScreen2Clipboard() "seems" to help

Re: Printscreen on Windows 7

Posted: Sat Nov 20, 2010 3:06 am
by skiman
Hi Jimmy,

No, it isn't working on My Windows 7 64 Bit.

Re: Printscreen on Windows 7

Posted: Sat Nov 20, 2010 10:41 am
by Auge_Ohr
skiman wrote:No, it isn't working on My Windows 7 64 Bit.
as i say : did you have "Clipbrd.exe" on your PC ?

Re: Printscreen on Windows 7

Posted: Sun Nov 21, 2010 4:24 am
by skiman
Hi,

When I press printscreen and do a paste in Paint, the window appears. So I suppose it should work.

Anyway, I can't ask this kind of questions to my customers. I thought that there would be an easy solution for this rather simple task. It seems as it is not that simple. :(

Re: Printscreen on Windows 7

Posted: Sun Nov 21, 2010 11:36 am
by Auge_Ohr
skiman wrote:When I press printscreen and do a paste in Paint, the window appears. So I suppose it should work.
i know this, but i "think" it is not the same as XbpClipBoard()

as i say i have download "Clipbrd.RAR" for some Reason and this work for me.
to verify i must deinstall it so try it yourself on your Machine.

Re: Printscreen on Windows 7

Posted: Tue Nov 23, 2010 11:30 am
by Cliff Wiernik
I will test on my Win7 64bit program and my print screen to printer process I use. I think it works but will validate just to be certain.

Cliff.

Re: Printscreen on Windows 7

Posted: Sat Nov 27, 2010 12:12 am
by skiman
Hi Cliff,

Have you found some time to test your printscreen function?