有更好的解决方案吗?

编程入门 行业动态 更新时间:2024-10-26 12:33:05
本文介绍了有更好的解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我正在尝试监视不再受支持的第三方应用程序. 我目前在计时器中设置了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 [ ^ ]或通过在HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft下列出您的dll \ Windows NT \ CurrentVersion \ Windows \ AppInit_DLLs注册表项. 在过程中运行代码后,您可以使用 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

更多推荐

有更好的解决方案吗?

本文发布于:2023-11-29 01:45:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解决方案

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!