Ned help with marshaling (SendMessage, lparam, WM_MOUSEMOVE)

R

Ryan Ross

Hello,

I need some help with the SendMessage method. I've imported it into C# with
the following statement:

[DllImport("user32.dll", SetLastError=true)]

public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, long wparam,
int lparam);

and the following for sending the message:

User32.SendMessage(WindowObject_Basic_GDI_Handle, User32.WM_MOUSEMOVE,
User32.MK_LBUTTON, MakeLParam(X, Y));

and below for constructing the lparam:

private int MakeLParam(int LoWord, int HiWord)


{

//System.Diagnostics.Debug.WriteLine("LoWord: " + LoWord2(((HiWord << 16) |
(LoWord & 0xffff))));

return (int) ((HiWord << 16) | (LoWord & 0xffff));


}

Unfortunately, whenever I send a WM_MOUSEMOVE message to a window
(Notepad.exe), the lparam parameter doesn't mike it there!

Spy++ reports X and Y coordinates of 0. (Everything else makes it there ok).

Does anyone have ideas what kind or marshaling I need to do, or if I am
sending the correct data?

Thanks,

Ryan
 
M

Mick Doherty

wparam should be int not long.

I prefer to use IntPtr though which would allow you to send a long value.

[DllImport("user32.dll", SetLastError=true)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wparam,
IntPtr lparam);

SendMessage(this.Handle, 0x200, (IntPtr)(long)0x1, (IntPtr)MakeLParam(X,Y));
 
R

Ryan Ross

Ah, that works.

Thank You,
Ryan


"Mick Doherty"
wparam should be int not long.

I prefer to use IntPtr though which would allow you to send a long value.

[DllImport("user32.dll", SetLastError=true)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr
wparam, IntPtr lparam);

SendMessage(this.Handle, 0x200, (IntPtr)(long)0x1,
(IntPtr)MakeLParam(X,Y));

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Ryan Ross said:
Hello,

I need some help with the SendMessage method. I've imported it into C#
with the following statement:

[DllImport("user32.dll", SetLastError=true)]

public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, long
wparam, int lparam);

and the following for sending the message:

User32.SendMessage(WindowObject_Basic_GDI_Handle, User32.WM_MOUSEMOVE,
User32.MK_LBUTTON, MakeLParam(X, Y));

and below for constructing the lparam:

private int MakeLParam(int LoWord, int HiWord)


{

//System.Diagnostics.Debug.WriteLine("LoWord: " + LoWord2(((HiWord << 16)
| (LoWord & 0xffff))));

return (int) ((HiWord << 16) | (LoWord & 0xffff));


}

Unfortunately, whenever I send a WM_MOUSEMOVE message to a window
(Notepad.exe), the lparam parameter doesn't mike it there!

Spy++ reports X and Y coordinates of 0. (Everything else makes it there
ok).

Does anyone have ideas what kind or marshaling I need to do, or if I am
sending the correct data?

Thanks,

Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top