Help with Win32 APIs ChildWindowFromPoint and WindowFromPoint

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Ok, I am not really sure how to fully describe this problem but I will
do my best and maybe someone can help. First let me say I am not much
of a C# programmer (yet) have dione VB6 for years but am really just
starting with C#.

Anyway here is my problem. I have an app which needs to interact with
another application. To do this I have used some Win32 APIs (as
mentioned in the subject). The problem is I can not get these
functions to work. For whatever reason I am unable to get the
function ChildWindowFromPoint to work in either VB or C#. However I
can get WindowFromPoint to work in VB but not in C# with the exact
same arguments.

Here is my C# code:
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);

IntPtr UserIDhWnd = WindowFromPoint(884, 433);

This does not return the handle to the window at those
coordinates...not sure what the value it is returning is but it is not
the window handle I am looking for.

Here is the VB6 version of the same thing:
Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal
xPoint As _
Long, ByVal yPoint As Long) As Long

UserIDhWnd = WindowFromPoint(884, 433)

This code does work.

Can anyone tell me what I am doing wrong with my C# code.

Thanks,
Steve
 
Here is my C# code:
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);

IntPtr UserIDhWnd = WindowFromPoint(884, 433);

This does not return the handle to the window at those
coordinates...not sure what the value it is returning is but it is not
the window handle I am looking for.

I have to ask: how are you determing the value that UserIDhWnd contains
after you execute that line?
 
Here is my C# code:
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
IntPtr UserIDhWnd = WindowFromPoint(884, 433);
This does not return the handle to the window at those
coordinates...not sure what the value it is returning is but it is not
the window handle I am looking for.

I have to ask: how are you determing the value that UserIDhWnd contains
after you execute that line?

By looking at it in the locals window.

I managed to figure out the problem. The app is written in VS 2010
and the Projects "Platform target" was set to "Any CPU". This seems
to cause it to run as a 64 bit app. When I changed the Platform
Target to x86 it works fine.

Steve
 
Back
Top