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
[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();
chrome.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);
This post has been edited by krazyshank: 02 February 2013 - 04:25 PM

New Topic/Question
Reply



MultiQuote



|