[译]更好的Zoomin实用程序
By robot-v1.0
本文链接 https://www.kyfws.com/applications/a-better-zoomin-utility-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2453 个词 阅读量 0[译]更好的Zoomin实用程序
原文地址:https://www.codeproject.com/Articles/10708/A-better-Zoomin-utility
原文作者:Joseph M. Newcomer
译文由本站 robot-v1.0 翻译
前言
A better Zoomin utility.
更好的Zoomin实用程序.
介绍(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.)
太多次了,我需要一个拾色器.我还需要捕获屏幕上的图像片段以放入其他程序中,例如图标.问题在于ZoomIn不支持我需要做的大多数事情.(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.)
Zoomin怎么了?(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:)
为了创建此图像,我将顶部旋转控件控制的图像大小设置为64像素.然后我拿起了选择器工具,(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.)
在四处移动时,右上方显示一个RGB值.此外,还显示了实际的R,G和B颜色.这代表了放置光标的实际点(尽管您可能看不到它,但是在选择器工具的中间有一个小小的白点代表了光标的热点位置).在扩展图像上看到的方式是,中心处的虚线正方形是扩展的热点.从边缘延伸的线仅是为了使其有趣.(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.)
捕获图像后,将鼠标移到RGB显示屏上,将使鼠标下方像素的实际像素值进入RGB显示.(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?)
像我的大多数示例一样,这旨在显示有关使用Windows和/或MFC的一些想法.此代码中包含的想法是:(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:)
- 创建一个覆盖整个桌面窗口的窗口DC.(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.)
- 有一个"选择器"工具(就像您从Spy ++可以识别的那样).(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.)
本文中表达的观点是作者的观点,绝不代表Microsoft,也未得到Microsoft的认可.(The views expressed in this essay are those of the author, and in no way represent, nor are they endorsed by, Microsoft.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 Windows Visual-Studio Dev 新闻 翻译