PostMessage does not work in CF

M

mottebelke

I want to use PostMessage to send a WM_LBUTTONUP message to a control
to simulate the clicking on that control.
The problem I have is that the function always returns an error: 87 -
Invalid parameter. This is even the case when I change the message to
WM_CLOSE for example.
I can't see where I went wrong.

[DllImport("coredll.dll")]
public static extern bool PostMessage
(
IntPtr hWnd, // handle to destination window
Int32 Msg, // message
Int32 wParam, // first message parameter
Int32 lParam // second message parameter
);

----

IntPtr hwnd=0;
if (storeObsButton != null)
{
// get hwnd of control
storeObsButton.Capture = true;
hwnd = GetCapture();
storeObsButton.Capture = false;
}

bool lngResult;
if (hwnd != IntPtr.Zero)
{
lngResult = PostMessage(hwnd, WM_LBUTTONUP, 0, 0);
}

----
 
P

Peter Foot [MVP]

Have you considered using the built-in
Microsoft.WindowsCE.Forms.MessageWindow.PostMessage method?

Also check your defined windows message constants, and check your hwnd is
valid.

Peter
 
M

mottebelke

Yes, I tried the managed PostMessage, but that gave me the same result.
I checked the message constants as well, and they look fine:

public const Int32 WM_LBUTTONDOWN = 0x0201;
public const Int32 WM_LBUTTONUP = 0x0202;
 
M

mottebelke

Ilya said:
I'd say by the way of exclusion we can assume hWnd is not valid.

Well, then why does SendMessage work with the exact same handle and
message constants?

And no, I can't use SendMessage, because in some scenarios the button
click handler waits on other input which I have to enter
programmatically as well.


I'll have another look at mouse_event tomorrow, but I gave that a try
already today with no luck.
 
M

mottebelke

Daniel said:
mouse_event example here:
http://www.danielmoth.com/Blog/2004/11/mouseevent.html

If you are still having troubles with your PostMessage why not post a full
repro.

Cheers
Daniel

I tried your example, but it still doesn't work.

Something I didn't mention yet, and which might be the problem cause is
that I want to click a button in another application than where I'm
running the PostMessage/mouse_event from.
I use Reflection to start the 'external' application and then use the
GetMethod, GetProperty and Invoke functions to control it (get the
handles, find the controls, etc.).

Does PostMessage/mouse_event work when you're trying it on a different
application started with reflection?
 

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