1 Replies - 164 Views - Last Post: 02 February 2013 - 04:28 PM Rate Topic: -----

#1 krazyshank  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 21-December 12

Latching my form to the top right of an external process

Posted 02 February 2013 - 04:24 PM

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);

Is This A Good Question/Topic? 0
  • +

Replies To: Latching my form to the top right of an external process

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,463
  • Joined: 12-June 08

Re: Latching my form to the top right of an external process

Posted 02 February 2013 - 04:28 PM

Please avoid opening duplicate topics. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1