有更好的解决方案吗? [英] Is there a better solution to this?

查看:185
本文介绍了有更好的解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在尝试监视不再受支持的第三方应用程序.
我目前在计时器中设置了SetTimer(1,1,NULL),该计时器监视像素何时更改颜色.使用计时器,我已经能够捕获95%-97%的更改.
这是我在计时器功能中使用的:

Hello All,
I am trying to monitor a third party application that is not supported anymore.
I currently have a process in a timer thats been set as SetTimer(1,1,NULL) that monitors a pixel as to when it changes color. Using the timer I have been able to capture 95 - 97% of the changes.
This is what I am using in the timer function:

static int Count=0;
CString Test;
HWND Monitoring_App = FindWindow(ClassName,NULL);
HDC hDC = GetDC(Monitoring_App);
COLORREF Color2Test = GetPixel(hDC,x,y);
ReleaseDC(Monitoring_App,hDC);
DeleteDC(hDC);
if(Color2Test == RGB(r,g,b))
{
Count++;
Test.Format("%d", Count);
m_CountText.SetWindowText(Test);
}
SetTimer(1,1,NULL);


有一个更好的方法吗?
我可能是错的,如果我使用线程来监视更改而不是使用计时器,我是否有可能捕获剩余的5%-3%?
我对线程一无所知.
再次对任何好或坏的建议(永远不会坏,我们都可以从中学习)将大加赞赏.


Is there a better way to do this?
I could be wrong, will it be possible for me to capture the remainng 5 - 3 %, if I use a thread to monitor the change instead of the timer?
I have no clue about threads.
Once again any suggetions good or bad (there is never bad, we get to learn from them) will be greatly appreciated.

推荐答案

好吧,

您采用的这种方法称为轮询.臭名昭著有两个原因-
(a)即使没有什么要报告的内容,也会使用cpu资源.
(b)在两次轮询事件之间发生多个目标事件时,您将丢失数据.

我想到的一个选择是对窗口进行子类化.

这将需要一些有关程序内部工作方式的知识.

对窗口进行子类化的结果是,您将在事件发生之前就知道该事件,但是直到下一个事件发生之前,您都不会收到其他通知.如果您想对新数据做任何事情,而不仅仅是计算变化的时间,那么这会使逻辑复杂化.

如果我知道它是什么,我会使用OllyDbg或IDA Pro来查看该程序.
Okay then,

This method that you''ve employed is known as polling. It is notorious for two reasons -
(a) cpu resources are used even when there''s nothing new to report.
(b) when more than 1 target event occurs between polling events, you lose data.

An option that come to mind is that of subclassing the window.

It will require some knowledge of how the program works internally.

Subclassing the window has the consequence that you''ll know of the event before it happens, but won''t get another notification until just before the next event happens. This will complicate logic somewhat if you want to do anything with the new data, other than just count the times it changes.

I''d look at the program using OllyDbg or IDA Pro if I knew what it was.


将dll注入到旧版应用程序中,也许使用CreateRemoteThread [ GetWindowLongPtr [ SetWindowLongPtr [ ^ ].

然后,您将能够在调用原始Windows过程之后为要监视的窗口处理每个WM_PAINT消息.

最好的问候
Espen Harlinn
Inject a dll into the legacy application, perhaps using CreateRemoteThread[^] or by listing your dll under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs registry key.

Once you have code running inside the process you can get the original procedure for the window you want to monitor using the GetWindowLongPtr[^] and the replace it with your own procedure using SetWindowLongPtr[^].

You will then be able to handle each WM_PAINT message for the window you want to monitor after you have called the original windows procedure.

Best regards
Espen Harlinn


这篇关于有更好的解决方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆