Hi,

I'm having trouble getting my sendmessage function right. I want to send a click on a specific coordinate to the window.

I know this is the api:

[DllImport("user32.dll")]
        public static extern int SendMessage(
              int hWnd,      // handle to destination window
              uint Msg,       // message
              long wParam,  // first message parameter
              long lParam   // second message parameter
              );

1) The first problem that occurs is that my hWnd is an IntPtr and not an int. (I get my hWnd with findWindow). How can I resolve this?

2) I also want to ask if my lParam, which I need to set my coordinate too, if it is made properly?

This is a mix of what I found on the internet. However I don't know how the long result works?

public const uint WM_CLICK = 0x00F5;

public static long makeDWord(int LoWord, int HiWord)
        {
            long result = (LoWord + (HiWord << 16));
            return result;
        }  

long lParam = makeDWord(a, b);
//a is x-axis, b is y-axis
int click = SendMessage(hWnd, WM_CLICK, null, lParam);

Help is greatly appreciated.

1/. An IntPtr is a pointer to an int you can convert it easily to either int32 or int64 (int and long respectivly) see below:

int i = 10;
            IntPtr p = new IntPtr(i);
            int aInt = p.ToInt32();
            long aLong = p.ToInt64();

2/. All that code is doing is taking two Int32s (int) and sticking them together in an Int64 (long).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.