1 Replies - 304 Views - Last Post: 02 February 2013 - 09:04 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
[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


Is This A Good Question/Topic? 0
  • +

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

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,420
  • Joined: 05-May 12

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

Posted 02 February 2013 - 09:04 PM

Typically when you run Chrome, there is more than one instance of the chrome.exe process. Are you sure you are getting the right instance?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1