Click here to Skip to main content
12,355,050 members (65,926 online)
Click here to Skip to main content
Add your own
alternative version

Stats

29.1K views
4K downloads
77 bookmarked
Posted

ScreenTool

, 24 Jun 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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. You may select the output image format from the combobox loaded with all GDI+ supported image formats. 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)

Known Issues

When saving as GIF I noticed the image quality was not the best. I believe this can be fixed by using the GDI+ EncoderParameters object when calling Image->Save() in the CMainDlg::SaveImageAs() function. An example of this can be found directly below in the unused (commented out) function CMainDlg::SaveImageAsJpeg().  

History  

  • 2012-06-23 - File Version 1.0.0.2
    • Added image type combobox  
    • Changed rubber band image selection operation to eliminate problem with desktop icons and various applications with the method described here.  
  • 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)

Share

About the Author

JJMatthews
Software Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionCopying to Clipboard - Additional Function Pin
JeffBilkey20-Nov-13 15:07
memberJeffBilkey20-Nov-13 15:07 
AnswerRe: Copying to Clipboard - Additional Function Pin
JJMatthews23-Nov-13 8:39
memberJJMatthews23-Nov-13 8:39 
GeneralRe: Copying to Clipboard - Additional Function Pin
JeffBilkey23-Nov-13 13:26
memberJeffBilkey23-Nov-13 13:26 
GeneralRe: Copying to Clipboard - Additional Function Pin
JJMatthews24-Nov-13 21:45
memberJJMatthews24-Nov-13 21:45 
QuestionProblems Capturing From Google Earth Pin
JeffBilkey10-Nov-13 18:44
memberJeffBilkey10-Nov-13 18:44 
AnswerRe: Problems Capturing From Google Earth Pin
JJMatthews13-Nov-13 1:20
memberJJMatthews13-Nov-13 1:20 
QuestionNo code Pin
Richard MacCutchan24-Jun-12 3:12
mvpRichard MacCutchan24-Jun-12 3:12 
AnswerRe: No code Pin
JJMatthews24-Jun-12 3:47
memberJJMatthews24-Jun-12 3:47 
QuestionGreat Tool Pin
JeffBilkey21-Jun-12 1:34
memberJeffBilkey21-Jun-12 1:34 
AnswerRe: Great Tool Pin
JJMatthews22-Jun-12 1:51
memberJJMatthews22-Jun-12 1:51 
GeneralRe: Great Tool Pin
JeffBilkey22-Jun-12 16:49
memberJeffBilkey22-Jun-12 16:49 
GeneralRe: Great Tool Pin
JJMatthews24-Jun-12 7:02
memberJJMatthews24-Jun-12 7:02 
Questionrepaint problem Pin
Member 144042312-Jun-12 5:20
memberMember 144042312-Jun-12 5:20 
AnswerRe: repaint problem Pin
JJMatthews19-Jun-12 20:19
memberJJMatthews19-Jun-12 20:19 
QuestionSome Explanations Pin
Chandru08023-Oct-11 23:04
memberChandru08023-Oct-11 23:04 
Questionscreentool Pin
Roger6523-Oct-11 5:21
memberRoger6523-Oct-11 5:21 
QuestionSnipping tool Pin
PBoucher7221-Oct-11 5:36
memberPBoucher7221-Oct-11 5:36 
AnswerRe: Snipping tool Pin
JJMatthews21-Oct-11 6:35
memberJJMatthews21-Oct-11 6:35 
GeneralRe: Snipping tool Pin
Nemanja Trifunovic24-Oct-11 5:08
memberNemanja Trifunovic24-Oct-11 5:08 
SuggestionBetter save as PNG Pin
mluri21-Oct-11 1:16
membermluri21-Oct-11 1:16 
GeneralRe: Better save as PNG Pin
mluri21-Oct-11 1:42
membermluri21-Oct-11 1:42 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 24 Jun 2012
Article Copyright 2011 by JJMatthews
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid