[译]颜色预览和选择器小程序
By robot-v1.0
本文链接 https://www.kyfws.com/applications/colour-preview-and-picker-applet-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 13 分钟阅读 - 6373 个词 阅读量 0[译]颜色预览和选择器小程序
原文地址:https://www.codeproject.com/Articles/2579/Colour-preview-and-picker-applet
原文作者:PJ Arends
译文由本站 robot-v1.0 翻译
前言
A simple applet that lets you preview how various font and background colours interact. Has the added ability of being able to pick any colour from the screen.
一个简单的小程序,可让您预览各种字体和背景颜色的交互方式.具有能够从屏幕上选择任何颜色的附加功能.
- 下载源文件-50 Kb(Download source files - 50 Kb)
- 下载静态链接的可执行文件-122 Kb(Download Static Linked Executable - 122 Kb)
介绍(Introduction)
这是一个简单的小程序,可用于预览各种彩色字体和背景颜色如何相互影响.它还具有从屏幕上任何位置选择颜色的能力.(This is a simple applet that can be used to preview how various coloured font and background colours interact with each other. It also has the ability to pick colours from anywhere on the screen.)
这个程序是基于科林`戴维斯的(This app is based on Colin Davies') CornerColor测试(CornerColor Test) 不幸的是,当我尝试在Win2000机器上运行它时,出现了一些问题.我不但不理会忙于他最新项目的科林,反而认为我可以自己编写自己的版本.(which, unfortunately, had a few problems when I tried to run it on my Win2000 machine. Rather than bother Colin, who is very busy with his latest project, I thought I would have a go at writing my own version.)
学分(Credits)
- **科林`戴维斯(Colin Davies)**最初的想法,以及他在开发此应用程序时提供的帮助和建议.(for the original idea, plus the help and suggestions he gave indeveloping this app.)
- **约瑟夫`纽科默博士(Dr Joseph Newcomer)**为了他(for his) CImageButton类(CImageButton class) .(.)
- **基思规则(Keith Rule)**为了他(for his) CMemDC类(CMemDC class) .(.)
- 其他各种建议和测试.(Various others for suggestions and testing.)
使用颜色小程序(Using the Colour applet)
注意:所有设置都保存在注册表下的注册表项下:(Note : All settings are saved in the registry under the key :)
HKEY_CURRENT_USER
\Software
\PJ Arends
\Colour
\Settings
主视窗(Main Window)
控制(CONTROL) | 功能(FUNCTION) |
---|---|
彩色滑块(Colour Sliders) | 通过移动滑块来调整各种颜色强度.您可以使用向上和向下箭头键进行调整,并使用向左和向右键在滑块之间切换.这些控件没有快捷键,但是可以从其关联的编辑控件中轻松对其进行控制.(Adjust the various colour intensities by moving the sliders. You can use the up and down arrow keys for adjustments, and use the left and right keys to switch between sliders. There are no shortcut keys to these controls, but they can be easily controlled from their associated edit controls.) |
编辑控件(Edit Controls) | 在编辑控件中手动输入颜色值.您可以使用向上和向下箭头键来增加或减少编辑控件中的值.以下快捷键将把焦点设置到编辑控件上(Manually enter the colour values in the edit controls. You can use the up and down arrow keys to increase or decrease the value in the edit controls. The following shortcut key strokes will set the focus to the edit controls) |
- Alt-R红色编辑控件(Alt-R Red edit control)
- Alt-G绿色编辑控件(Alt-G Green edit control)
- Alt-B蓝色编辑控件(Alt-B Blue edit control) | |前景单选按钮(Foreground Radio-button)|滑块可调整样本前景的颜色.(The sliders adjust the colour of the sample foreground.)快捷键:Alt-F(Shortcut key : Alt-F)
| |背景单选按钮(Background Radio-button)|滑块调整样本背景的颜色.(The sliders adjust the colour of the sample background.)快捷键:Alt-K(Shortcut key : Alt-K)
| |选择颜色按钮(Pick Colour Button)|使用鼠标从屏幕上选择颜色.找到所需的颜色后,按Control-Alt-P,将关闭" Pick Colour"选项,以保存颜色.(Use the mouse to pick colours from the screen. Once you find the colour you like, press Control-Alt-P and the “Pick Colour” option will be turned off, saving the colour.)
- 快捷键(Alt-P)-(Shortcut key (Alt-P) -)Start
- 快捷键(Control-Alt-P)-(Shortcut key (Control-Alt-P) -)Stop | |放大复选框(Magnify Checkbox)|与" Pick Colour"一起使用.从屏幕选择颜色时,光标将包含在屏幕周围跟随光标的小放大窗口内.使用键盘上的箭头键可以更好地控制光标.通过单击鼠标左键或按Enter或Esc键关闭放大窗口.(Used with “Pick Colour”. When picking a colour from the screen, the cursor will be contained within a small magnifying window that follows the cursor around the screen. Use the arrow keys on the keyboard for finer control over the cursor. Close the magnifying window with either a left mouse button click, or pressing the enter or escape keys.)快捷键:Alt-M(Shortcut key : Alt-M)
| |十六进制复选框(Hexadecimal Checkbox)|在十进制和十六进制之间切换强度显示数字.(Toggle the intensity display numbers between decimal and hexadecimal.)快捷键:Alt-H(Shortcut key : Alt-H)
| |Web安全复选框(Web Safe Checkbox)|将颜色限制为216种Web安全颜色.(Restricts the colours to the 216 web safe colours.)快捷键:Alt-W(Shortcut key : Alt-W)
| |复位按钮(Reset Button)|将文本和背景色重置为系统默认值.(Reset the text and background colours to the system defaults.)快捷键:Alt-S(Shortcut key : Alt-S)
| |复制按钮(Copy Button)|将颜色值复制到剪贴板.(Copy the colour values to the clipboard.)快捷键:Alt-C(Shortcut key : Alt-C)
| |选项按钮(Options Buttons)|弹出显示选项对话框.(Brings up the display options dialog.)快捷键:Alt-O(Shortcut key : Alt-O)
| |箭头按钮(Arrow Buttons)|将颜色程序窗口移到角落.这些按钮没有关联的快捷键(Move the Colour program window into a corner. There are no shortcut keys associated with these buttons)|
颜色选项对话框(Colour Options Dialog)
控制(CONTROL) | 功能(FUNCTION) |
---|---|
确定按钮(OK Button) | 关闭对话框,保存并应用设置(Closes the dialog, saves and applies the settings)快捷键:输入(Shortcut key : Enter) |
| |取消按钮(Cancel Button)|关闭对话框,恢复为旧设置(Closes the dialog, reverts to old settings)快捷键:Escape(Shortcut key : Escape)
| |默认按钮(Default Button)|将所有控件设置为其默认值(Sets all the controls to their default values)快捷键:Alt-D(Shortcut key : Alt-D)
| |始终在最前面复选框(Always On Top Checkbox)|主窗口将始终位于屏幕上所有其他窗口的顶部.(The main window will always stay on top of all other windows on the screen.)快捷键:Alt-A(Shortcut key : Alt-A)
| |窗口大小编辑框(Window Size Editbox)|放大镜窗口两边的长度(即输入100将为您提供100像素乘100像素的窗口)(The length of the sides of the magnifier window (i.e. Entering 100 will give you a 100 pixel by 100 pixel window))快捷键:Alt-Z(Shortcut key : Alt-Z)
| |显示的像素数(Pixels Shown Editbox)|放大镜窗口中跨高像素的数量(即输入9将在窗口中显示9像素乘9像素的网格)(The number of pixels across and high in the magnifier window (i.e. Entering 9 will show a grid 9 pixels by 9 pixels in the window))快捷键:Alt-P(Shortcut key : Alt-P)
| |形状单选按钮(Shape Radiobutton)|示例窗口中将显示一个形状而不是文本(The sample window will have a shape in it instead of text)快捷键:Alt-H(Shortcut key : Alt-H)
| |矩形单选按钮(Rectangle Radiobutton)|形状将是一个矩形(The shape will be a rectangle)快捷键:Alt-R(Shortcut key : Alt-R)
| |三角形单选按钮(Triangle Radiobutton)|形状将是三角形(The shape will be a triangle)快捷键:Alt-N(Shortcut key : Alt-N)
| |椭圆单选按钮(Ellipse Radiobutton)|形状将是椭圆形(The shape will be an ellipse)快捷键:Alt-E(Shortcut key : Alt-E)
| |高度编辑框(Height Editbox)|形状的高度(以像素为单位)(The height of the shape in pixels)快捷键:Alt-G(Shortcut key : Alt-G)
| |宽度编辑框(Width Editbox)|形状的宽度(以像素为单位)(The width of the shape in pixels)快捷键:Alt-W(Shortcut key : Alt-W)
| |文字单选按钮(Text Radiobutton)|示例窗口中将包含文本而不是形状(The sample window will have text in it instead of a shape)快捷键:Alt-T(Shortcut key : Alt-T)
| |示例单选按钮和编辑框(Sample Radiobutton and Editbox)|文本将是在编辑框中输入的用户定义的文本(The text will be the user defined text entered in the edit box)快捷键:Alt-M(Shortcut key : Alt-M)
| |光标屏幕坐标(Cursor Screen Coordinates)|文本将是鼠标光标的屏幕坐标(The text will be the screen coordinates of the mouse cursor)快捷键:Alt-S(Shortcut key : Alt-S)
| |字体按钮(Font Button)|弹出字体选择对话框以选择用于显示文本的字体(Brings up the font selection dialog to select the font used to display the text)快捷键:Alt-F(Shortcut key : Alt-F)
|
|十进制格式编辑框(Decimal Format Editbox)|十进制输出的格式字符串.格式化字符串应遵循与MFC中使用的格式化字符串相同的规则(The formatting string for decimal output. The formatting string should follow the same rules as the formatting strings used in the MFC) CString::Format
功能,除了用数字代替" d"或" i"作为占位符,您必须用" r"或" R"代表红色,用" g"或" G"代表绿色,蓝色为" b"或" B".(function except instead of using a ’d' or ‘i’ as a place holder for numbers, you have to use a ‘r’ or ‘R’ for the Red colour,a ‘g’ or ‘G’ for the green colour, and a ‘b’ or ‘B’ for the blue colour.)例如,如果RGB值为171\222\106,且格式字符串为(不包括引号):“红色=%r,绿色=%g,蓝色=%b”,则输出将为"红色=171,绿色" =222,蓝色=106"(i.e. If the RGB values are 171, 222, 106, and the format string is (not including quotes) : “Red = %r, Green = %g, Blue = %b”, the output will be “Red = 171, Green = 222, Blue = 106”)
快捷键:Alt-C(Shortcut key : Alt-C)
|
|十六进制格式编辑框(Hexadecimal Format Editbox)|十六进制输出的格式字符串.格式化字符串应遵循与MFC中使用的格式化字符串相同的规则(The formatting string for hexadecimal output. The formatting string should follow the same rules as the formatting strings used in the MFC) CString::Format
函数,对于十六进制数字中的小写字母,使用小写字母" r"," g"或" b"代替" x",并使用大写字母" R"," G"或" B"代替" X"来使用十六进制数字中的大写字母.(function except use lowercase ‘r’, ‘g’ or ‘b’ instead of ‘x’ for lowercase letters in the hexadecimal number, and use uppercase ‘R’, ‘G’, or ‘B’ instead of ‘X’ to use uppercase letters in the hexadecimal number.)例如,如果RGB值为AB,DE,6A,且格式字符串为(不包括引号):“红色=0x%08R,蓝色为%b,好吗?",则输出为"红色=0x000000AB,蓝色为6a,好吗?(i.e. If the RGB values are AB, DE, 6A, and the format string is (not including quotes) : “Red = 0x%08R and Blue is %b, Ok?”, the output will be “Red = 0x000000AB and Blue is 6a, Ok?")
快捷键:Alt-X(Shortcut key : Alt-X)
|
兴趣类别(Classes of Interest)
CMagnifierWindow类(CMagnifierWindow class)
的(The) CMagnifierWindow
class是Color应用程序用来显示屏幕放大部分的简单类.虽然放大镜窗口在屏幕上,但它将保持在鼠标光标的中心.您可以使用鼠标或键盘上的箭头键在屏幕上移动光标和放大镜窗口.单击鼠标左键,或者使用” Enter"或” Escape"键将隐藏放大镜窗口.(class is a simple class that is used by the Colour app to show a magnified portion of the screen.While the magnifier window is on the screen, it will remain centered on the mouse cursor. You can move the cursor, and the magnifier window,around the screen using the mouse or the arrow keys on the keyboard. A left mouse button click, or the ‘Enter" or ‘Escape’ keys willhide the magnifier window from view.)
要在自己的应用程序之一中使用课程,请添加文件(To use the class in one of your own apps, add the files)*放大镜窗口(MagnifierWindow.h)*和(and)*MagnifierWindow.cpp(MagnifierWindow.cpp)*到您的项目.只需在代码中声明该类的实例,即可调用(to your project.Simply declare an instance of the class in your code, call the) Create()
成员函数创建窗口,调用(member function to create the window, callthe) ShowMagnifier()
使用放大镜的功能,以及(function to use the magnifier, and the) HideMagnifier()
停止使用该功能.当用户通过单击或使用键盘隐藏放大镜窗口时,该窗口将发布用户定义的消息(function to stop using it.When the user hides the magnifier window by clicking or using the keyboard, the window will post a user defined message) WMU_HIDEMAGNIFIER
这在(which is defined in the)*放大镜窗口(MagnifierWindow.h)*头文件.(header file.)
放大镜的操作非常简单.在里面(The operation of the magnifier is quite simple. In the) ShowMagnifier()
功能,将拍摄整个屏幕的快照并将其保存在屏幕尺寸的位图中,该位图在存储设备上下文中仍处于选中状态,并且通过调用(function a snapshot is taken of the entire screenand saved in a screen size bitmap that is left selected in a memory device context, and the window is shown using a call to the) ShowWindow(SW_SHOW)
功能.当窗口在屏幕上移动时,要放大的屏幕部分将使用(function. As the window moves around the screen, the portion of the screen that is to be magnified isdrawn into the magnifier window using the) StretchBlt()
功能.然后,在(function. Then, in the) HideMagnifier
函数,位图和存储设备上下文被破坏,并且通过调用来隐藏窗口(function,the bitmap and memory device context are destroyed, and the window is hidden with a call to the) ShowWindow(SW_HIDE)
功能.(function.)
CMagnifierWindow类的成员函数(CMagnifierWindow class member functions)
CMagnifierWindow::CMagnifierWindow()
类构造函数会初始化类成员,但不会创建实际的窗口,您必须调用(The class constructor initializes the class members but does not create the actual window, you have to call the) Create()
功能来做到这一点.构造函数不带任何参数,并且不返回任何值.(function to do that. The constructor takes no parameters, and does not return any value.)
BOOL CMagnifierWindow::Create (int size, int pixels, CWnd* pParentWnd)
的(The) Create()
函数会创建实际的放大镜窗口,但将其隐藏起来.的(function creates the actual magnifier window, but leaves it hidden from view. The) Create()
如果成功创建窗口,函数将返回非零值;如果创建失败,则函数将返回零.(function returns a nonzero value if it is successful in creating the window, and it returnszero if it fails.)
参量(Parameters)
int size -
放大镜窗口的大小(以像素为单位)(The size of the magnifier window in pixels)int pixels
-放大镜窗口中显示的像素数(- The number of pixels to be shown in the magnifier window)CWnd *pParentWnd
-指向放大镜窗口父窗口的指针.这是将收到的窗口(- A pointer to the magnifier window’s parent window. This is the window that will receive the)WMU_HIDEMAGNIFIER
用户隐藏放大镜窗口时显示的消息(message when the user hides the magnifier window)BOOL CMagnifierWindow::ShowMagnifier()
的(The) ShowMagnifier()
功能在屏幕上显示放大镜窗口.函数返回(function shows the magnifier window on the screen. The function returns) TRUE
成功,以及(on success, and) FALSE
失败.该函数不带任何参数(on failure. The function does not take any parameters)
void CMagnifierWindow::HideMagnifier()
的(The) HideMagnifier()
函数从屏幕上删除放大镜窗口,但不破坏它.该函数不带任何参数,也不返回任何值.(function removes the magnifier window from the screen, but it does not destroy it.The function takes no parameters, and does not return any value.)
其他班(Other classes)
尽管其余的类没有什么特别的,但有些人可能对某些功能感兴趣.(While the rest of the classes are nothing special, some people may be interested in some of the functionality.)
的(The) CNumEdit
类((class ()NumEdit.cpp(NumEdit.cpp)和(and)NumEdit.h(NumEdit.h))是一个() is a) CEdit
派生类将输入的限制限制为0到255之间的十进制或十六进制数字.该类使用(derived class the limits it’s input todecimal or hexadecimal numbers between 0 and 255. The class uses the) EN_UPDATE
消息处理程序以验证输入到其中的数字.(message handler to validate the numbers entered into it.)
的(The) CColourSlider
类((class ()ColourSlider.cpp(ColourSlider.cpp)和(and)ColourSlider.h(ColourSlider.h))是一个简单的子类() is a simple subclass of a) CSliderCtrl
在轨迹栏中绘制渐变颜色.(that draws a gradient colour in the track bar.)
就是这样,我希望你们中的一些人觉得有用.(That’s it, I hope some of you find this useful.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Windows Win2K MFC Visual-Studio Dev 新闻 翻译