Hi,
If I send a screenshot to the Clipboard, how can I then print it using code?
Brian
Hi Brian,
Just couldn't resist to remind you of this:
http://www.ionicwind.com/forums/index.php?topic=6422.msg46911#msg46911
Good luck!
Egil,
I'm glad you did, because I had forgotten that one!
Brian
OK, this code sends a perfect copy of the active window to the Clipboard. It then loads MSPaint correctly, but does not insert a Ctrl+V to place the Clipboard graphic into Paint
A manual Ctrl+V does work. Any ideas, anyone?
'Simulates leftAlt + PrintScrn buttons to send a bitmap to the Clipboard
IF GetKeyboardState(keyState)<>0
keybd_event(VK_LMENU,0xA4,0,0) 'left Alt press
keybd_event(VK_SNAPSHOT,0x2C,0,0) 'Print Screen press
keybd_event(VK_LMENU,0xA4,KEYEVENTF_KEYUP,0) 'left Alt release
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0) 'Print Screen release
ENDIF
'Load MSPaint
SYSTEM "mspaint.exe"
'Try and insert a Ctrl+V into Paint - nothing happens
UINT hWnd=FindWindow(NULL,"Untitled - Paint") 'This makes sure your program is running
IF hWnd<>0
UINT aWnd=GetForegroundWindow()
IF (aWnd<>hWnd) 'See if the foreground window is yours
Sleep(1000) 'Allow time for the other window to become active
IF GetKeyboardState(keyState)<>0
keybd_event(VK_CONTROL,0x1D,KEYEVENTF_EXTENDEDKEY,0)
keybd_event(0x56,0x2F,KEYEVENTF_EXTENDEDKEY,0)
keybd_event(VK_CONTROL,0x1D,KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP,0)
keybd_event(0x56,0x2F,KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP,0)
ENDIF
ENDIF
ENDIF
Brian
Just a note: I think I have cracked it using some code from way back by Sapero. I will post the whole lot when I have tested it some more
Brian
Hi Brian,
Looks like you have a great time!
That's what I remembered when I took up coding again after such a long time.
But now I've become so rusty that I almost felt I had to learn everything all over again.
Looking forward to see your code.
Egil
Egil, you may be disappointed, as the program is a re-hash of my Times Table application. I have always promised myself to get it working correctly, ie, saving a screenshot, and now I have. Important milestone for me
Brian
I always learn something by studying other peoples code, so don' worry.
Just downloaded your Times Table application, and plan to have a look at it this afternoon.
Never tried clipboard routines myself, so maybe your code can come in handy some day.
Egil
Egil,
Well, my Clipboard routine to save the window as a bitmap worked perfectly. My problem was actually getting and printing the bitmap from the Clipboard. So this version doesn't use the Clipboard at all - sorry
But it does do what I intended it to do, so that's a bonus
Brian