Overlay text on some else's window - HUD

时光毁灭记忆、已成空白 提交于 2019-12-14 00:33:58

问题


I am interested in writing an application that overlays a small heads up display (HUD) over another application, in VB.NET. What is an example of this?

I will need to enumerate all open windows to find the window that I want, and then overlay some text in a specific position on the window. If the user moves that window, my text will need to follow. (I will probably be painting the text in a loop over and over).

Edit: nobody answered my original query - I added C# to the keywords to see if any of gurus in that language might have an answer.


回答1:


You can use WinApi to enumerate windows. You can start googling with

[DllImport("user32.dll")]
public static extern int EnumWindows(EnumWindowsProc ewp, int lParam);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, ref WapiRect lpRect);

When you have found your window and has its handle, there is no problem to plot on it with something like

Graphics g = Graphics.FromHwnd(win.Handle);
g.FillRectangle(new SolidBrush(Color.White), 0, 0, 1000, 1000);

But to overlay... One possible solution is to create own border less form(it can be made even transparent) and place your text on it. Then just place this special form on top of another application.



来源:https://stackoverflow.com/questions/1562863/overlay-text-on-some-elses-window-hud

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!