IonicWind Software

IWBasic => General Questions => Topic started by: Brian on May 03, 2023, 05:34:32 AM

Title: Clipboard
Post by: Brian on May 03, 2023, 05:34:32 AM
Hi,

If I send a screenshot to the Clipboard, how can I then print it using code?

Brian
Title: Re: Clipboard
Post by: Egil on May 03, 2023, 08:43:00 AM
Hi Brian,
Just couldn't resist to remind you of this:
http://www.ionicwind.com/forums/index.php?topic=6422.msg46911#msg46911

Good luck!
Title: Re: Clipboard
Post by: Brian on May 03, 2023, 11:22:48 AM
Egil,

I'm glad you did, because I had forgotten that one!

Brian
Title: Re: Clipboard
Post by: Brian on May 04, 2023, 10:22:33 AM
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
Title: Re: Clipboard
Post by: Brian on May 05, 2023, 11:15:16 AM
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
Title: Re: Clipboard
Post by: Egil on May 07, 2023, 03:20:46 AM
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
Title: Re: Clipboard
Post by: Brian on May 08, 2023, 07:35:58 AM
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
Title: Re: Clipboard
Post by: Egil on May 10, 2023, 03:19:16 AM
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
Title: Re: Clipboard
Post by: Brian on May 10, 2023, 04:02:04 AM
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