2

I would like to get the mouse coords relative to another window (window client area), the window is not part of my application.

I would prefer to do this without delving into the Win32 API and dll imports, but I'm not sure if it's possible.

The basic idea is: My C# WPF app will have the users focus, when the user presses a hot key(CTRL + C) the app will get the coords relative to the client area of an earlier specified window. It's just a quick app I need to make for in-house development assistance.

Drahcir
  • 11,772
  • 24
  • 86
  • 128
  • if it was in your own window, how are you switching between client relative and screen absolute coordinates? if you do that in managed mode is there any method which accepts the windows handle of the base window to be considered? if not then you should probably use the win 32 APIs, there is nothing bad in that :) – Davide Piras Nov 07 '12 at 17:00
  • There are only two calls you would need to make into the Win32 DLL's, it wouldn't be too bad (and is the only solution I am aware of). There is a good start here: http://stackoverflow.com/questions/1364440/how-to-get-and-set-window-position-of-another-application-in-c-sharp Give it a shot and update your post if you run into any trouble. The only downside is that you end up with a Windows-only solution, but that may be acceptable for your needs. – jheddings Nov 07 '12 at 17:07

1 Answers1

0

If you have the process name / ID, you can get the handle by calling System.Diagnostics.Process.MainWindowHandle. When you have the handle, use System.Windows.Forms.Control.FromHandle(handle).PointToClient(p) to get the coordinates of screen point p relative to the position of the other window.

pascalhein
  • 5,700
  • 4
  • 31
  • 44