By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

Ned help with marshaling (SendMessage, lparam, WM_MOUSEMOVE)

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <ry***@nni.com> wrote in message
news:0s********************@nni.com...
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

Nov 17 '05 #2

P: n/a
Ah, that works.

Thank You,
Ryan
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:Oy*************@TK2MSFTNGP15.phx.gbl...
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" <ry***@nni.com> wrote in message
news:0s********************@nni.com...
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


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.