Click here to Skip to main content
Licence CPOL
First Posted 21 Oct 2011
Views 7,408
Downloads 1,429
Bookmarked 30 times

ScreenTool

By | 23 Oct 2011 | Article
Screenshot Tool

Introduction

This program takes screenshots a variety of ways. It was written to help technical writers.

  • Saves screenshots as jpegs to destination directory with configurable file suffix.
  • Enables user to take a screenshot by drawing a rubber band anywhere on the screen.
  • Enables user to select any window any take a screenshot (spy++ style window selection).
  • Intercepts the printsceen and the alt+printscreen key(s).

Background

This application began as a request from a fellow programmer to figure out the best way to draw a rubber band on the desktop and take a screenshot of the area in the drawn box. After trying a variety of techniques to accomplish this, I ended up using the low-level mouse hook method (SetWindowsHookEx(WH_MOUSE_LL,...). My colleague was then inundated with other work. I decided to turn the test project into a useful tool on my own time.

Using the Code

Using the application is very simple. There are 2 main ways to select an area/window and take a screenshot. To draw a rubberband, press the "Draw" button, to use the Spy++ style window selector method, press the "Select" button. On the main dialog, there are configurable parameters such as line width which is used when drawing/selecting. The output directory is configurable as well as a file prefix. Currently all images are saved as jpegs using GDI+. All output files are created in the destination directory using the prefix and a date/time stamp for the file name. You can also choose whether or not to minimize the application to the system tray while drawing/selecting. All parameters are stored/loaded from the registry.

The application was written using VS2003 (MFC7). You will find the majority of the code in the "MainDlg.cpp" file. The code demonstrates usage of the following Win32 functions:

  • SetWindowsHookEx(WH_MOUSE_LL, ... 
  • SetWindowsHookEx(WH_KEYBOARD_LL, ... 
  • CreateDIBSection(... 
  • SHGetSpecialFolderLocation(hWnd, CSIDL_DESKTOP, ... 
  • Shell_NotifyIcon(... 
  • SHBrowseForFolder(... 

Points of Interest

The rubber band drawing code was taken/modified from the MFC CDockContext class:

CDockContext::DrawFocusRect(BOOL bRemoveRect)

Future Development

If a programmer so desired, it wouldn't take much work to implement the saving of screenshots into other image formats. The function:

int CMainDlg::GetEncoderClsid(const WCHAR* format, CLSID* pClsid)

was taken from a MSDN example. It enumerates all available GDI+ supported output image formats and could be easily modified to create a filter list for a save file dialog.

Known Issues

When drawing a rubber band over desktop icons and some windows, they are not repainted correctly. I have so far been unable to come up with a solution for this that will work on all windows and desktop icons.

History

  • 2011-10-21 - File Version 1.0.0.1
    • Initial CodeProject Release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

JJMatthews

Software Developer (Senior)

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSome Explanations PinmemberChandru08023:04 23 Oct '11  
Questionscreentool PinmemberRoger655:21 23 Oct '11  
QuestionSnipping tool PinmemberPBoucher725:36 21 Oct '11  
AnswerRe: Snipping tool PinmemberJJMatthews6:35 21 Oct '11  
GeneralRe: Snipping tool PinmemberNemanja Trifunovic5:08 24 Oct '11  
SuggestionBetter save as PNG Pinmembermluri1:16 21 Oct '11  
GeneralRe: Better save as PNG Pinmembermluri1:42 21 Oct '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 24 Oct 2011
Article Copyright 2011 by JJMatthews
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid