Clipboard problem

J

James Park

I'm trying to use:

keybd_event(VK_SNAPSHOT, 0, 0, 0);
keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);

to take a screenshot, and use:

Clipboard::GetImage();

to retrieve it, but it returns a nullptr. It's strange though because I know
the screenshot is taken since I can paste just fine in mspaint. If I press
print screen manually, the GetImage() method works as it should. I'm using
VC++ Express 2k5 August CTP. Help would be much appreciated.
 
D

David Lowndes

I'm trying to use:
keybd_event(VK_SNAPSHOT, 0, 0, 0);
keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);

to take a screenshot, and use:

Clipboard::GetImage();

to retrieve it, but it returns a nullptr. It's strange though because I know
the screenshot is taken since I can paste just fine in mspaint. If I press
print screen manually, the GetImage() method works as it should.

James,

I'm wondering if there's some timing issue coming into effect.

Have you tried splitting up the keyboard event creation of the screen
shot and the call to GetImage so they're 2 manually instigated events
(say 2 separate push buttons on a form), and see if that makes any
difference.

Dave
 
J

James Park

David Lowndes said:
James,

I'm wondering if there's some timing issue coming into effect.

Have you tried splitting up the keyboard event creation of the screen
shot and the call to GetImage so they're 2 manually instigated events
(say 2 separate push buttons on a form), and see if that makes any
difference.

Well, one of the problems was that I didn't leave enough time between the
keystroke and the clipboard query, but there were other issues as well. For
some reason, using the code during a BackgroundWorker::DoWork failed, but
using it during a Form::Load worked. Another problem was that as I ran the
code in a loop a nullptr would come up if I switched the active window as it
was taking the shots. So the code was working like I wanted, but when I
alt-tabbed from an app window to VS, it'd give me a NullReferenceException,
and I'd grumble thinking it happened on the first pass. The problem worked
the other way too (i.e. from VS/system tray looping ss'ing app to
full-screen game), and the exception actually would occur on the first pass
and confuse me even more. It took me a long time to get my program working
though everything feels rather fragile, and I still don't get why things are
the way they are.
 
A

Atul

For some reason, using the code during a BackgroundWorker::DoWork failed,
but using it during a Form::Load worked.

I think this can be cured by calling Application.OleRequired for the
background thread.

-Atul, Sky Software http://www.ssware.com
Shell MegaPack For ActiveX & .Net - Windows Explorer Like Shell UI Controls
 
J

James Park

Atul said:
I think this can be cured by calling Application.OleRequired for the
background thread.

Thanks for the suggestion. Unfortunately, it didn't work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top