Click here to Skip to main content
13,737,037 members
Click here to Skip to main content
Add your own
alternative version


55 bookmarked
Posted 17 Jun 2005

A better Zoomin utility

, 17 Jun 2005
Rate this:
Please Sign up or sign in to vote.
A better Zoomin utility.


This project came about as the result of a question in one of the newsgroups. Someone was asking about how to write a color-picker.

Far too many times, I've needed a color-picker. I've also needed to capture pieces of images on the screen to put into other programs, such as icons. The problem is that ZoomIn doesn't support most of what I need to do.

What's wrong with Zoomin?

  • I have to get the image right the first time. If I don't have it selected properly, I can't nudge it over.
  • I have to get the scaling right. Otherwise I might get too much of the image, or not enough.
  • Once having gotten the image, I can't select a piece of it.
  • Copy-to-clipboard copies the image in the Zoomin window, not the actual pixels that were on the screen..

The original questioner had posed some complicated ways of dealing with the problem, such as using timers and hook functions. These aren't necessary.

This project produces an image much like the one below:

In order to create this, I set the image size, controlled by the spin control at the top, to 64 pixels. I then took the picker tool, , and dragged it over the screen until I was over the light bulb in the heading of a page. I wasn't quite where I wanted, so I used the "nudge" arrows to move it around a bit.

While moving around, there is an RGB value displayed at the top right. In addition, the actual R, G and B colors are shown. This represents the actual point where the cursor is placed (although you probably can't see it, there is a little tiny white dot in the middle of the picker tool that represents the cursor hotspot position). The way this is seen on the expanded image is that the dotted square in the center is the hotspot, expanded. The lines extending from the edges are just to make it interesting to find.

The ? key in the middle will display a box around the area that is selected.

The copy icon button, , will copy the contents of the selection to the clipboard.

However, there are additional features.

Once the image is captured, moving the mouse over it will put into the RGB display the actual pixel value for the pixel under the mouse.

Clicking and dragging within the image area will select a sub-region. This will then be marked with a selection rectangle. Note that the old rectangle does not disappear until the new one is created. This is deliberate, so you can see the old selection while making a new, larger or smaller, selection.

This is shown in the figure below. Note that this image is smaller. I did that by resizing the dialog. In this example, there is a selection box around the base of the lamp.

What's interesting about this code?

Like most of my examples, this is intended to show some ideas about using Windows and/or MFC. Ideas that are included in this code are:

  • Creation of a window DC that covers the entire desktop window.
  • Grabbing a piece of the window and saving it as a local bitmap.
  • Selecting a piece of that bitmap.
  • Rubber-banding selection box.
  • Displaying color swatches.
  • Copying a bitmap to the clipboard.
  • Having a "picker" tool (much like you would recognize from Spy++).
  • Noting that you can in some cases interchange cursors and icons, which is what I did here.
  • Creating a CWnd-derived popup window (the implementation of the ? button).
  • Having a window that can be created and which will disappear on its own (the ? button's display window).
  • The use of the implicit SetBkMode(OPAQUE) to create lines that are alternating colors, so the line shows up whether the background is light or dark.
  • Computing points in logical space and translating them to device space (the array of points used to draw the highlighting square in the first image). Note that the horizontal and vertical lines are actually a "fractional pixel" in logical space, and there is a trick to accomplishing that.
  • Owner-draw buttons (those arrow buttons, and the copy button).

There isn't much code here, but the code that is here illustrates several useful techniques.

The views expressed in this essay are those of the author, and in no way represent, nor are they endorsed by, Microsoft.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Joseph M. Newcomer
United States United States
PhD, Computer Science, Carnegie Mellon University, 1975
Certificate in Forensic Science and the Law, Duquesne University, 2008

Co-Author, [i]Win32 Programming[/i]

You may also be interested in...


Comments and Discussions

GeneralAnother Zoom program Pin
Lee Alexander23-Jun-05 2:54
memberLee Alexander23-Jun-05 2:54 
GeneralAnd another Zoomin... Pin
Anonymous21-Jun-05 6:59
memberAnonymous21-Jun-05 6:59 
GeneralRe: And another Zoomin... Pin
Joseph M. Newcomer21-Jun-05 7:06
memberJoseph M. Newcomer21-Jun-05 7:06 
GeneralDoes it work with MediaPlayer Pin
Uwe Keim17-Jun-05 11:04
sitebuilderUwe Keim17-Jun-05 11:04 
GeneralRe: Does it work with MediaPlayer Pin
Joel Holdsworth17-Jun-05 13:02
memberJoel Holdsworth17-Jun-05 13:02 
GeneralRe: Does it work with MediaPlayer Pin
Toby Opferman24-Jun-05 11:52
memberToby Opferman24-Jun-05 11:52 
GeneralRe: Does it work with MediaPlayer Pin
Joseph M. Newcomer24-Jun-05 15:36
memberJoseph M. Newcomer24-Jun-05 15:36 
GeneralRe: Does it work with MediaPlayer Pin
Toby Opferman24-Jun-05 19:19
memberToby Opferman24-Jun-05 19:19 
GeneralRe: Does it work with MediaPlayer Pin
Joseph M. Newcomer17-Jun-05 18:00
memberJoseph M. Newcomer17-Jun-05 18:00 
GeneralRe: Does it work with MediaPlayer Pin
Rage20-Jun-05 5:50
memberRage20-Jun-05 5:50 
GeneralRe: Does it work with MediaPlayer Pin
Michael Dunn22-Jul-05 12:44
sitebuilderMichael Dunn22-Jul-05 12:44 
AnswerRe: Does it work with MediaPlayer [modified] Pin
Synetech12-Aug-06 12:12
memberSynetech12-Aug-06 12:12 
GeneralAdditional ZoomIn Pin
Blake Miller17-Jun-05 4:03
memberBlake Miller17-Jun-05 4:03 
GeneralRe: Additional ZoomIn Pin
Joseph M. Newcomer17-Jun-05 6:17
memberJoseph M. Newcomer17-Jun-05 6:17 
GeneralRe: Additional ZoomIn Pin
Blake Miller17-Jun-05 6:36
memberBlake Miller17-Jun-05 6:36 
GeneralNice! Pin
ThatsAlok17-Jun-05 2:25
memberThatsAlok17-Jun-05 2:25 
GeneralRe: Nice! Pin
Stlan17-Jun-05 3:04
memberStlan17-Jun-05 3:04 
GeneralRe: Nice! Pin
Stlan17-Jun-05 3:11
memberStlan17-Jun-05 3:11 
GeneralRe: Nice! Pin
ThatsAlok17-Jun-05 19:34
memberThatsAlok17-Jun-05 19:34 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180920.1 | Last Updated 17 Jun 2005
Article Copyright 2005 by Joseph M. Newcomer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid