如何绘制图形/文本上的其他应用程序的顶部 [英] How to draw graphics/text on top of another application
问题描述
我要增强的应用程序,但目前还没有3:E团体提供的API。
所以基本上这个想法是绘制图形/文本上的应用程序窗口的顶部。
I want to enhance an application, but there is no 3:e party API available. So basically the idea is to draw graphics/text on top of the applications windows.
有问题Z序,裁剪,并指挥鼠标点击或者我的应用程序或其他应用程序。
There are problems with z order, clipping, and directing mouse clicks either to my application or the other application.
这是什么做的?
例的形象在这里的一种优雅的方式。这是我的应用程序需要添加额外的信息到交易应用程序的窗口交易程序。
[URL = http://img104.imageshack.us/my。 PHP?形象= windowontop.png ] [/ URL]
Example image here. It is a trading application where my application wants to add extra information into the trading application's windows. [URL=http://img104.imageshack.us/my.php?image=windowontop.png][/URL]
推荐答案
有没有好的方法可以做到这一点,但一个方法可能对你的工作就是用勾调用SetWindowsHookEx(...)来添加GetMsgProc,吸引您的叠加响应WM_PAINT消息有问题的应用程序。其基本思想是,你绘制图形应用程序完成了自己的绘画之后
There are no nice ways to do this, but one approach that may work for you is to hook the application in question using SetWindowsHookEx(...) to add a GetMsgProc, which draws your overlay in response to WM_PAINT messages. The basic idea is that you're drawing YOUR graphics right after the application finishes its own drawing.
在您的主应用程序:
....
HMODULE hDllInstance = LoadLibrary("myFavoriteDll");
HOOKPROC pOverlayHook = (HOOKPROC)GetProcAddress(hDllInstance, "OverlayHook");
SetWindowsHookEx(WH_GETMESSAGE, pOverlayHook, hDllInstance, threadId);
关在DLL中的某个地方:
Off in a DLL somewhere:
LRESULT CALLBACK OverlayHook(int code, WPARAM wParam, LPARAM lParam)
{
//Try and be the LAST responder to WM_PAINT messages;
//Of course, if some other application tries this all bets are off
LRESULT retCode = CallNextHookEx(NULL, code, wParam, lParam);
//Per GetMsgProc documentation, don't do anything fancy
if(code < 0) return retCode;
//Assumes that target application only draws when WM_PAINT message is
//removed from input queue.
if(wParam == PM_NOREMOVE) return retCode;
MSG* message = (MSG*)lParam;
//Ignore everything that isn't a paint request
if(message->message != WM_PAINT) return retCode;
PAINTSTRUCT psPaint;
BeginPaint(message->hwnd, &psPaint);
//Draw your overlay here
...
EndPaint(message->hwnd, &psPaint);
return retCode;
}
这是所有的Win32所以你的C#代码会的P / Invoke重,相应地相当难看。您的DLL必须不受管理,以及(如果你打算注入到比你自己以外的进程),使之成为一个甚至令人讨厌的解决方案。
This is all win32 so your C# code will be p/invoke heavy and correspondingly quite ugly. Your DLL must be unmanaged as well (if you intend to inject into a process other than your own), making this an even nastier solution.
这将解决您的问题与z顺序和裁剪的问题,因为你渲染到窗口本身。但是,如果您的目标应用程序Winproc传中的任何绘画以外的响应WM_PAINT的崩溃;这并不是一个完全少见occurence。
This would solve your issue with z-order and clipping issues, as you're rendering into the window itself. However, if the application you're targeting does any drawing outside of the WinProc responding to WM_PAINT things fall apart; this is not an entirely uncommon occurence.
这篇关于如何绘制图形/文本上的其他应用程序的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!