Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Latching my form to the top right of an external process

$
0
0
Hi, i'm trying to make an overlay for a game that will go on the top right of the game's window.
ive been researching possible ways to do this, and it seems the only way to get an external windows location is by using GetWindowRect(), so I tried that and its giving me the wrong output.

In my code I created a new process (chrome), and tried it on that, and I had a messagebox print the "rect.Top" and the "rect.Right" values of my chrome process. Every time I got random numbers that werent at all where chrome was.

How can I get this to work? or is there another way I can make my form "latch" on to another window in the top right of it?

My code
[CODE]
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
Process chrome = new Process();
rotmg.StartInfo.FileName = "chrome.exe";
rotmg.Start();
Thread.Sleep(1000);
IntPtr hWnd = chrome.Handle;
RECT rct = new RECT();
GetWindowRect(hWnd, ref rct);
MessageBox.Show(rct.Top + ", " + rct.Right);

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>