Example Code

Programmatically take a screenshot and save it to file (CVI)

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

  • LabWindows/CVI

Code and Documents

Attachment

Description

Overview
This example code demonstrates how to getting the entire screen image.

 
Description
Based on some example code found on msdn library and on the Internet, I developed this sample program that makes use of some Win32 APIs to take a screenshot of the screen and save it to file.

I successfully managed to pass image information from Win32 functions to CVI native functions in order to leverage CVI ability to save images in various formats. In this example a .PNG file is created, but simply using the appropriate function a .JPG, .BMP or .TIF file could be created.

 

Requirements

  1. LabWindows/CVI 2012SP1


Steps to Implement or Execute Code

  1. Incorporate Screenshot () function into existing code to add this functionality to an application. Function takes a variable to return to the caller any error found in Win32 functions. Errors in CVI native functions, if any, are returned as the return code from the function.
  2. Add User32.lib library to the project
  3. Include windows.h in the file where the function is pasted.

Note: I am currently using full release of CVI; I cannot be sure this code will work for base version of the IDE since some WIN32 functions are not available in such a release and I cannot test the code against it.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?

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

Comments
CVIBri
Member
Member
on

Thanks! saved me the time of having to look up the win32 calls

RobertoBozzolo
Proven Zealot
Proven Zealot
on

You're welcome!

Feel free to rate this example if you found it useful.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?