Example Code

Programatically Print Screen and Paste Into Picture Control

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This VI takes a screenshot of all active monitors and paste the image from the clipboard into a picture control on the front panel.


Description
The VI programmatically takes a screenshot by accessing the user32.dll and simulating a user processing the Print Screen button. Once a screenshot has been copied to the clipboard the image is retrieved using the Clipboard, GetImage method. This returns an array of points that we convert into a pix map that can be passed into a picture control.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Run VI and view the results

 

Additional Information or References
VI Block Diagram

 Block Diagram.png

 

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Yogesh.Sinare
Member
Member
on

Thank you David-A for sharing this helpful code.

With little modification I was able to fit in our requirement.

Just a point to add -

To get the active window screen print, enter 18 (x12) for second argument(i.e. MASK) to lib call.

It's that simple to get ALT-PRINT SCREEN!!

Regards

Yogesh Sinare

David-A
NI Employee (retired)
on

Glad you found it useful. And that's a good tip. Thanks for sharing!

RVallieu
Active Participant
Active Participant
on

It appears that 18 (x12) is not universal for ALT for the second argument.

Ryan Vallieu CLA, CLED
Senior Systems Analyst II
NASA Ames Research Center
RVallieu
Active Participant
Active Participant
on

Hmm - it is universal for ALT - I must be doing something wrong - as it is not working for me to snap only the selected top level window.

Ryan Vallieu CLA, CLED
Senior Systems Analyst II
NASA Ames Research Center