[译]CatchCulator
By robot-v1.0
本文链接 https://www.kyfws.com/applications/catchculator-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 10 分钟阅读 - 4772 个词 阅读量 0[译]CatchCulator
原文地址:https://www.codeproject.com/Articles/11993/CatchCulator
原文作者:Mircea Puiu
译文由本站 robot-v1.0 翻译
前言
A tool used to catch and combine values output by different applications.
用于捕获和组合不同应用程序输出的值的工具.
介绍(Introduction)
您是否需要在同一台机器上并行运行多个应用程序,同时需要监视它们的数值输出,有时还需要组合结果以得出重要结论?好吧,几周前发生在我身上.我实际上正在运行两个独立的应用程序,这些应用程序正在获取数据,并且每个应用程序都在整个屏幕上显示值的"音调",这时我意识到我只需要进行一些小的计算,而只涉及这两个应用程序显示的几个值.使用MS计算器的工作没什么大不了的,因为显示的值一直在变化,并且不时地停止应用程序,以便我可以进行计算,这浪费了很多时间.(Have you had a requirement to run more than one application in parallel on the same machine while needing to watch their numerical outputs and sometimes to combine the results in order to draw some important conclusion? Well, it happened to me a couple of weeks ago. I was actually running two independent applications that were acquiring data and each displaying “tones” of values all over the screen, when I realized I was needing some small computation involving only a few of the values displayed by the two applications. Working with the MS Calculator was not much of a deal, as the displayed values were continuously changing, and stopping the applications from time to time so that I could get my computations, resulted in a big waste of time.)
然后我问自己:(I then asked myself:)如何获得所需的结果,而又不必一直停止并重新启动应用程序,而不必一次又一次地按下计算器上的相同操作(how could I get the results I want without stopping and restarting the applications all the time, without being necessary to key down the same operations on the calculator again and again)(无聊,你知道吗?)((boring, you know?))甚至无需查看那些应用程序显示的值?(and even without having to look at the values displayed by those applications?)(有时,工程师确实喜欢充满数据的屏幕).((sometimes, engineers do enjoy screens full of data).)
这是解决方案:(And here is the solution: the)CatchCulator(CatchCulator).一个小型的工具,具有很大的改进潜力,可帮助我快速干净地完成工作.(. A small tool, with great potential for improvement, helping me get the job done fast and clean.)
使用CatchCulator(Working with the CatchCulator)
我编写了一个基于对话框的小型应用程序,它在两个编辑控件中显示两个值,以表达我的想法,并运行它的两个或多个实例.在现实生活中,您将通过观察发现使用所需的任何应用程序:输出值必须通过(I wrote a small dialog based application displaying two values within two edit controls in order to present my idea, and running two or more instances of it. In real life, you will use whatever applications you need, with one observation: the output values must come out through) CEdit
和/或(and / or) CStatic
派生对象.(derived objects.)
假设您已经启动了应用程序(需要观察其数据),则必须启动CatchCulator.它出现在屏幕上,并带有一个"箭头"工具箱,您将用它来精确定位您感兴趣的显示值.只需将箭头(蓝色箭头实际上是对话框标题栏的可见部分)拖到上方您感兴趣的值,然后单击"尝试"按钮.由CatchCulator捕获的值将显示在该按钮下.可能会发生(Assuming now that you already started the applications, the data of which you need to observe, you must start the CatchCulator. It comes up on the screen accompanied by an “arrow” toolbox which you are going to use in pin-pointing the displayed values you are interested in. Simply drag the arrow (the blue arrow is actually the visible part of dialog’s title bar) over the value you are interested in and click the Try button. The value captured by the CatchCulator will be displayed under that button. It may happen that the) CEdit
或者(or the) CStatic
您指向的对象可能是在(object, which you are pointing to, could have been created over a) CStatic
例如帧,实际上您正在捕获属于帧的标题.在这种情况下,单击"隐藏"按钮,不需要的对象将被隐藏(不用担心,包含该控件的应用程序不会发生任何不良情况).再次单击"尝试"按钮(在某些情况下可能需要重复该操作).如果显示的值是您所需要的,则单击Catch按钮,以便CatchCalculator知道您的选择.(frame for example, and actually you are catching the caption belonging to the frame. In that case, click the Hide button and the unwanted object will be hidden (do not worry, nothing bad will happen to the application containing that control). Click again the Try button (you may need to repeat the operation in certain cases). If the shown value is what you need, then click the Catch button, so that the CatchCalculator becomes aware of your choice.)
捕获该值之后,将自动恢复以前隐藏的项目的可见性状态.捕获值后,CatchCulator会为其分配一个名称,以便以后可以将其引用为变量.(After catching the value, the visibility status of the previously hidden item(s) is restored automatically. Once you have caught a value, the CatchCulator assigns a name to it, so that you can refer it later as a variable.)
保留默认名称或重命名默认名称,使其与监视值的含义更相关.要重命名该变量,请单击鼠标并选择其名称,片刻之后再单击一次(这是一个正常的行为(It’s up to you to keep the default name or rename it to be more related to the meaning of the monitored value. To rename the variable, select its name with a mouse click and after a short while, click it again (this is the normal behaviour of a) CTreeCtrl
对象,实际上由CatchCulator的代码使用).捕获变量后,您可以继续告诉CatchCulator如何处理这些变量.这意味着您必须提供一些描述计算的脚本.如您可能已经观察到的,CatchCulator具有三个显示.每个显示都有分配的计算脚本.要编辑脚本,请在按住CTRL键的同时右键单击所需的显示.脚本规则非常简单,仅对语法进行简单检查.主要,您必须记住,脚本桅杆的每一行都有一个(object, which is actually used by CatchCulator’s code). Once you have finished with catching the variables, you can proceed to telling the CatchCulator what to do with those variables. This means you have to provide some scripts describing the calculation. As you may have already observed, the CatchCulator is endowed with three displays. Each display has a calculation script assigned. To edit the script, right-click the desired display while keeping the CTRL key pressed. The scripting rules are very simple and only simple checks are performed for the syntax. Mainly, you must keep in mind that every line of script mast have a)**名称(name)**用尖括号括起来,(closed in angular brackets and)**两个操作数(two operands)**以(separated by an)**操作(operation)**符号.对于当前版本的CatchCulator,仅支持基本的四个操作:*,/,+,-.根据对该工具的兴趣,我将为其他操作和功能提供将来的支持.分配给计算结果的名称可以进一步用作变量.点击(*symbol. For the current version of the CatchCulator, only the basic four operations are supported: , /, +, -. Depending on the interest on this tool, I will provide future support for other operations and functions. The name assigned to a calculation result can be used further as a variable. Click the)*更新脚本(Update script)*只要您更改脚本,按钮就可以生效.(button whenever you alter your script in order for the modification to become effective.)
默认情况下,任何计算结果都显示为小数点后5位数字.您可以通过使用一种与语法类似的语法来指定自己的显示格式.(By default, the result of any calculation is displayed as a number with 5 digits after the decimal point. You can specify your own display format by using a syntax similar to the one used by the) sprintf()
功能,观察到只有(function, with the observation that only the) %f
要么(or) %lf
在此工具的情况下,规范是有意义的.(specification makes sense in the case of this tool.)
要更改显示格式,请在按住SHIFT键的同时右键单击所需的显示.通过在格式规范中包含说明字符串,可以使显示的结果更清晰.要显示整数,请选择(To change the display format, right-click the desired display while keeping the SHIFT key pressed. By including an explanation string within your format specification, you can make the displayed result more clear. To display integer numbers, choose the) %.0lf
规范.(specification.)
即使已编辑脚本,也可以随时修改分配给捕获值的变量名.这些名称的任何更改将自动反映在脚本中.如果您将名称保留为空字符串,它将反映为(The variable names assigned to the caught values can be modified at any time, even after the scripts have been edited. Any change in those names will be automatically reflected in the scripts. If you leave a name as an empty string, it will be reflected as)*无名(NoName)*在脚本中.请记住,变量名称不必使用重复项,因为在这种情况下,仅会考虑名称的首次出现.(in the scripts. Keep in mind that you don’t have to use duplicates for the variable names, as only the first appearance of the name in that case will be considered.)
有两种模式可用于显示计算结果:(Two modes are available for showing the results of the calculations: the)**手册(manual)**模式和(mode and the)**计时器(timer)**模式.在手动模式下,单击相应的显示会更新每个显示(mode. In the manual mode, each display is updated when you click the corresponding)**d(D)**按钮.的(button. The)d(D)按钮仅在手动模式下启用.要切换模式,请单击时钟按钮.在定时器模式下,显示屏会定期更新,而无需您的干预.默认更新时间为100毫秒.要更改此值,请点击带有问号的时钟按钮((buttons are enabled only in the manual mode. To toggle the modes, click the clock button. In the timer mode, the displays are periodically updated with no intervention from your side. The default update time is 100 milliseconds. To change this value, click the the clock button with a question mark ()?(?)),仅在计时器模式下启用.(), which is enabled only in the timer mode.)
其他可用命令是:(Other available commands are:)
- 右键单击显示-清除显示(right click a display - clear the display)
- 点击(click the)**蓝色箭头(blue arrow)**按钮-显示收集器(如果先前已关闭)(button - show the catcher (if previously closed))
- 点击(click the)**红色X(red X)**按钮-删除所有捕获(button - remove all the catches)
- 点击(click the)**禁止X(barred X)**按钮-删除选定的渔获(button - remove the selected catch) 定义脚本后,可以将受监视的应用程序发送到任务栏,以便仅将CatchCulator显示的信息保留在计算机的显示屏上.(Once you have defined the scripts, you can send the monitored application to the task bar so that you keep only the information shown by the CatchCulator on the display of your computer.)
背后的代码(The code behind)
捕捉价值(Catching the value)
捕捉过程开始时,捕捉器的箭头指向屏幕上所需值的位置.包含该点的窗口的句柄是通过调用获得的(When the catching process starts, the catcher is positioned with the point of its arrow over the desired value on the screen. The handle of the window containing that point is obtained by a call to) WindowFromPoint(ptAt)
哪里(where) ptAt
是一个(is a) CPoint
在屏幕坐标中存储箭头点位置的对象.此手柄((object storing the position of the point of the arrow in screen coordinates. This handle () hParent
)然后用于获取指向窗口的文本:() is then used to get the text of the pointed window:)
HWND hParent;
char chText[256];
::GetWindowText(hParent, chText, 255);
如果返回的文本为空字符串,则窗口可能是(If the returned text is a null string, there is the possibility that the window be of) CEdit
类(或派生).因此,CatchCulator尝试读取此类控件的第一行(因为它可能是多行):(class (or derived). Therefore, the CatchCulator attempts to read the first line of such a control (as it may be a multi-line one):)
CEdit *pEdit;
int N;
pEdit = (CEdit *)FromHandle(hParent);
N = pEdit->GetLine(0, chText, 255);
chText[N] = 0; // null termination
结果文本(如果有)显示在捕获器的"尝试"按钮下.(The resulting text (if any) is displayed under the Try button of the catcher.)
根据脚本进行计算(Calculating according to the scripts)
脚本的每一行都描述了一个计算单元,通过(Each line of the script describes a calculation unit, implemented through the) Calculation
类:(class:)
class Calculation
{
public:
Calculation() { result = 0; opL = ""; opR = ""; }
~Calculation() {}
CString resultName;
CString operation;
CString opL; // 1-opName, 2-opName (1 for caught var, 2 for computed value)
CString opR; // or 3-value (for constant value)
double result;
};
分配给计算结果的名称存储在(The name assigned to the calculation result is stored in) resultName
,而操作按原样(,/,+,-)存储在(, while the operation is stored as it is (, /, + ,-) in) operation
.根据操作数(左和右),将考虑以下三种情况之一:(. Depending on the operands (left and right), one of the following three cases is to be considered:)
- 操作数是被捕获的(监视变量)的名称(the operand is a name of a caught (monitored variable))
- 操作数是脚本中先前计算的值的名称(the operand is the name of a previously computed value in the script)
- 操作数是一个常量值(一个数字)(the operand is a constant value (a number))
每个运算结果存储在(Each operation result is stored in)
result
初始化为0.计算单位存储在(which is initialized to 0. The calculation units are stored within a)CList
目的:(object:)
CList <Calculation, Calculation> m_listToDo;
整个计算是在(The whole computation is performed within the) CCatchCulatorDlg::ProcessScript(CStaticDisplay *pDisplay)
函数,它将指向相关显示的指针作为参数.操作数的值按以下方式获得:如果操作数是监视值的名称,则(function, which takes a pointer to the related display as parameter. The values for the operands are obtained as follows: if the operand is the name of a monitored value, the) CCatchCulatorDlg::ValueOf(char *varName)
以该名称作为参数调用;如果名称已分配给计算值,则(is invoked with that name as parameter; if the name was assigned to a computed value, the) CStaticDisplay::ComputedValue(char *varName)
调用该名称作为参数传递;或者,如果操作数是数字的字符串表示形式,则(is invoked with that name passed as parameter; or if the operand is the string representation of a number, the) sscanf()
函数被调用.结果值用作指定操作的操作数.操作结果存储在(function is invoked. The resulting values are used as operands for the indicated operation. The result of the operation is stored in the) result
当前成员(member of the current) Calculation
单元.依次通过(unit. The units are processed one after the other by going through the) m_listToDo
清单.最后一个单元保留最终结果(list. The last unit holds the final result in its) result
数据成员,实际上由相关的显示显示.(data member, which is actually shown by the related display.)
历史(History)
- 创建于:2005年10月.(Created: October, 2005.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 Windows Visual-Studio Dev 新闻 翻译