Click here to Skip to main content
Click here to Skip to main content

A better Zoomin utility

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

Introduction

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.

License

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

Share

About the Author

Joseph M. Newcomer

United States United States
No Biography provided

Comments and Discussions

 
GeneralAnother Zoom program PinmemberLee Alexander23-Jun-05 3:54 
GeneralAnd another Zoomin... PinsussAnonymous21-Jun-05 7:59 
GeneralRe: And another Zoomin... PinmemberJoseph M. Newcomer21-Jun-05 8:06 
GeneralDoes it work with MediaPlayer PinsitebuilderUwe Keim17-Jun-05 12:04 
GeneralRe: Does it work with MediaPlayer PinmemberJoel Holdsworth17-Jun-05 14:02 
GeneralRe: Does it work with MediaPlayer PinmemberToby Opferman24-Jun-05 12:52 
GeneralRe: Does it work with MediaPlayer PinmemberJoseph M. Newcomer24-Jun-05 16:36 
GeneralRe: Does it work with MediaPlayer PinmemberToby Opferman24-Jun-05 20:19 
If you want to see something cool, do a performance timer on only the BitBlt command. You'll notice that most of the time if you're dealing with cached software LVB's that it's less than a ms. However, if you're forced to read from the card as such with playing a video or with windowed DX/OGL you'll get a much slower BitBlt such as 9ms, 12ms and even slower depending on usually just the video card and bus but the video driver software can also play into it.
 
8bc7c0ec02c0e404c0cc0680f7018827ebee
GeneralRe: Does it work with MediaPlayer PinmemberJoseph M. Newcomer17-Jun-05 19:00 
GeneralRe: Does it work with MediaPlayer PinmemberRage20-Jun-05 6:50 
GeneralRe: Does it work with MediaPlayer PinsitebuilderMichael Dunn22-Jul-05 13:44 
AnswerRe: Does it work with MediaPlayer [modified] PinmemberSynetech12-Aug-06 13:12 
GeneralAdditional ZoomIn PinmemberBlake Miller17-Jun-05 5:03 
GeneralRe: Additional ZoomIn PinmemberJoseph M. Newcomer17-Jun-05 7:17 
GeneralRe: Additional ZoomIn PinmemberBlake Miller17-Jun-05 7:36 
GeneralNice! PinmemberThatsAlok17-Jun-05 3:25 
GeneralRe: Nice! PinmemberStlan17-Jun-05 4:04 
GeneralRe: Nice! PinmemberStlan17-Jun-05 4:11 
GeneralRe: Nice! PinmemberThatsAlok17-Jun-05 20:34 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 17 Jun 2005
Article Copyright 2005 by Joseph M. Newcomer
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid