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

Handle+mouse_event

P: n/a
Hi,

how do I pass the handle of a control to the win32 api mouse_event. so
that it will create the click event on that application only even if there
is any other window in front of it. I dont what to set focus. I just want
the click event to happen in that window directly.

Regards
Abhishek
Jul 24 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Abhishek,

The Handle property on the control will return the handle that you are
looking for.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Abhishek" <sh***@activelement.comwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,

how do I pass the handle of a control to the win32 api mouse_event. so
that it will create the click event on that application only even if there
is any other window in front of it. I dont what to set focus. I just want
the click event to happen in that window directly.

Regards
Abhishek

Jul 24 '06 #2

P: n/a
Hi Abhishek,

Are you trying to send mouse input to a different process? You'll have to obtain the window handle by enumerating the windows in
the process and view the text and type to find the specific control. There a Win32 API functions that you can use such as
EnumWindows and EnumChildWindows.

To simulate a click in your own application obtain the handle of the control from the Control.Handle property.

In either case after you retrieve the handle pass it to the external SendMessage Win32 API function along with WM_LBUTTONUP.

(Note that a few controls in the framework have a PerformClick method, which will alleviate the need for interop if you can use
them.)

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application
only even if there is any other window in front of it. I dont what to set focus. I just want the click event to happen in that
window directly.

Regards
Abhishek

Jul 25 '06 #3

P: n/a
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt this
will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application
only even if there is any other window in front of it. I dont what to set focus. I just want the click event to happen in that
window directly.

Regards
Abhishek

Jul 25 '06 #4

P: n/a
Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the click
event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:Of**************@TK2MSFTNGP04.phx.gbl...
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's
handle using the Control.Handle property. I doubt this will work
cross-process but you could try to obtain the handle to a window in
another application using the EnumWindows or EnumChildWindows Win32 API
functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam,
int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl...
>Hi,

how do I pass the handle of a control to the win32 api mouse_event. so
that it will create the click event on that application only even if
there is any other window in front of it. I dont what to set focus. I
just want the click event to happen in that window directly.

Regards
Abhishek


Jul 25 '06 #5

P: n/a
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the Control
some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification to
the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a control on
the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:ea*************@TK2MSFTNGP05.phx.gbl...
Hi All

Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:Of**************@TK2MSFTNGP04.phx.gbl...
>Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...
>>Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
happen in that window directly.

Regards
Abhishek



Jul 25 '06 #6

P: n/a
Hi Dave,

i am trying to create a ingame brower window. for this my dll is creating
bmp's of the embedded browser which present on a win form. This DLL is
loaded by my proxy directx 9 dll which is called by the game. this give me
real time render. I can watch youtube video's in game without a single
frameskip. the next step for me is the recreate a ingame click on a location
x, y in my browser. so that the navigation happens seamlessly. they are both
one below each other in placement(start x and y for both ingame and out of
game is 0,0 for now).
below are the two functions that should be able to handle this. the
mouse_event work perfectly when the browser is visible on screen.but
otherwise it down not. which is why i wanted to know if you can pass the
handle of the browser like in SendMessage so that the click happens in that.

In sendmessage the form becomes formost but no click happens.
private const int MOUSEEVENTF_LEFTDOWN = 0x2;
private const int MOUSEEVENTF_LEFTUP = 0x4;
private const uint WM_LBUTTONUP = 0x202, WM_LBUTTONDOWN = 0x201;

public unsafe void createleftclick() {
int x = 8, y = 8;
int point = x + (y << 16);
SetCursorPos(8, 8);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
}

public void SendClick(int px, int py)
{
SetCursorPos(25, 25);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));
}

My directx dll will just call the function directly
Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully
understand the situation.

Do you have two applications running simultaneously and you are attempting
to get one application to send a mouse notification to the other? If so,
are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the unfocused
Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:ea*************@TK2MSFTNGP05.phx.gbl...
>Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:Of**************@TK2MSFTNGP04.phx.gbl...
>>Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window in
another application using the EnumWindows or EnumChildWindows Win32 API
functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam,
int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,

how do I pass the handle of a control to the win32 api mouse_event.
so that it will create the click event on that application only even if
there is any other window in front of it. I dont what to set focus. I
just want the click event to happen in that window directly.

Regards
Abhishek



Jul 25 '06 #7

P: n/a
I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully
understand the situation.

Do you have two applications running simultaneously and you are attempting
to get one application to send a mouse notification to the other? If so,
are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the unfocused
Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:ea*************@TK2MSFTNGP05.phx.gbl...
>Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:Of**************@TK2MSFTNGP04.phx.gbl...
>>Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window in
another application using the EnumWindows or EnumChildWindows Win32 API
functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam,
int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,

how do I pass the handle of a control to the win32 api mouse_event.
so that it will create the click event on that application only even if
there is any other window in front of it. I dont what to set focus. I
just want the click event to happen in that window directly.

Regards
Abhishek



Jul 25 '06 #8

P: n/a
Hi abhishek,

Interesting idea but I have no idea what the browser is doing with your messages. Since it is a browser, after all, why not just
call ExecScript and perform a click in the actual browser using something like the following:

<script language="JavaScript">
function performClick(x, y) {
obj = document.elementFromPoint(x, y);
if (obj.click)
obj.click();"
}
</script>

MSDN object.click() method reference:
http://msdn.microsoft.com/library/de...hods/click.asp

If you are using the 2.0 framework's WebBrowser control:

browser.Document.InvokeScript("performClick", x, y);

For the ActiveX browser use the ExecScript method from IHTMLWindow2 to call the function.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:uT**************@TK2MSFTNGP05.phx.gbl...
Hi Dave,

i am trying to create a ingame brower window. for this my dll is creating bmp's of the embedded browser which present on a win
form. This DLL is loaded by my proxy directx 9 dll which is called by the game. this give me real time render. I can watch youtube
video's in game without a single frameskip. the next step for me is the recreate a ingame click on a location x, y in my browser.
so that the navigation happens seamlessly. they are both one below each other in placement(start x and y for both ingame and out
of game is 0,0 for now).
below are the two functions that should be able to handle this. the mouse_event work perfectly when the browser is visible on
screen.but otherwise it down not. which is why i wanted to know if you can pass the handle of the browser like in SendMessage so
that the click happens in that.

In sendmessage the form becomes formost but no click happens.
private const int MOUSEEVENTF_LEFTDOWN = 0x2;
private const int MOUSEEVENTF_LEFTUP = 0x4;
private const uint WM_LBUTTONUP = 0x202, WM_LBUTTONDOWN = 0x201;

public unsafe void createleftclick() {
int x = 8, y = 8;
int point = x + (y << 16);
SetCursorPos(8, 8);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
}

public void SendClick(int px, int py)
{
SetCursorPos(25, 25);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));
}

My directx dll will just call the function directly
Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:%2***************@TK2MSFTNGP02.phx.gbl...
>Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the Control
some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification to
the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a control
on the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:ea*************@TK2MSFTNGP05.phx.gbl...
>>Hi All

Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:Of**************@TK2MSFTNGP04.phx.gbl...
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,
>
how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
happen in that window directly.
>
Regards
Abhishek
>




Jul 25 '06 #9

P: n/a
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other post) but if it's non-zero that would indicate an error and
you should go from there.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:e$**************@TK2MSFTNGP03.phx.gbl...
>I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:%2***************@TK2MSFTNGP02.phx.gbl...
>Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the Control
some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification to
the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a control
on the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:ea*************@TK2MSFTNGP05.phx.gbl...
>>Hi All

Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:Of**************@TK2MSFTNGP04.phx.gbl...
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);
--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...
Hi,
>
how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
happen in that window directly.
>
Regards
Abhishek
>




Jul 25 '06 #10

P: n/a
its is returning zero!
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:en**************@TK2MSFTNGP05.phx.gbl...
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other
post) but if it's non-zero that would indicate an error and you should go
from there.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
>>I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
>>Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I
fully understand the situation.

Do you have two applications running simultaneously and you are
attempting to get one application to send a mouse notification to the
other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the
unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:ea*************@TK2MSFTNGP05.phx.gbl...
Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:Of**************@TK2MSFTNGP04.phx.gbl...
Hi Abhiishek,
>
Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window
in another application using the EnumWindows or EnumChildWindows Win32
API functions.
>
private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");
>
int x = 8, y = 8;
int point = x + (y << 16);
>
SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}
>
private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;
>
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int
wparam, int lparam);
>
>
--
Dave Sexton
>
"Abhishek" <sh***@activelement.comwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl.. .
>Hi,
>>
> how do I pass the handle of a control to the win32 api
>mouse_event. so that it will create the click event on that
>application only even if there is any other window in front of it. I
>dont what to set focus. I just want the click event to happen in that
>window directly.
>>
>Regards
>Abhishek
>>
>
>




Jul 26 '06 #11

P: n/a
cant use the script :(

Since this will just create a event on a link. bit of there is flash open
then? I will get the object of the flash and the click will not happen on
the button that is in the flash. also mouseovers and other stuff will not
happen. I need to create actual in game browser with all the bell and
whistles there is also the issue of scrollbars that need to be dragged

so my best bet is to use something like sendmessage, which is returning
zero. maybe there is a click happening just not at 30,30 the point i am
sending the cursor to.

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:en**************@TK2MSFTNGP05.phx.gbl...
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other
post) but if it's non-zero that would indicate an error and you should go
from there.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
>>I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
>>Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I
fully understand the situation.

Do you have two applications running simultaneously and you are
attempting to get one application to send a mouse notification to the
other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the
unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:ea*************@TK2MSFTNGP05.phx.gbl...
Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:Of**************@TK2MSFTNGP04.phx.gbl...
Hi Abhiishek,
>
Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window
in another application using the EnumWindows or EnumChildWindows Win32
API functions.
>
private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");
>
int x = 8, y = 8;
int point = x + (y << 16);
>
SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}
>
private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;
>
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int
wparam, int lparam);
>
>
--
Dave Sexton
>
"Abhishek" <sh***@activelement.comwrote in message
news:eY**************@TK2MSFTNGP02.phx.gbl.. .
>Hi,
>>
> how do I pass the handle of a control to the win32 api
>mouse_event. so that it will create the click event on that
>application only even if there is any other window in front of it. I
>dont what to set focus. I just want the click event to happen in that
>window directly.
>>
>Regards
>Abhishek
>>
>
>




Jul 27 '06 #12

P: n/a
Hi Abhishek,

Well you still might be able to use scripting if the Flash object model supports simulating a mouse click at a certain point. Check
if Flash also supports raising a mouse over event and scrolling from script while your at it.
so my best bet is to use something like sendmessage, which is returning zero. maybe there is a click happening just not at 30,30
the point i am sending the cursor to.
You must send the point to the SendMessage function. It doesn't matter where the cursor is actually located on the screen for
SendMessage with WM_LBUTTONDOWN.

To verify that SendMessage is working, since it is after all returning zero, why don't you replace the browser with a Button and in
a Click event handler show a MessageBox. Try to click the button with SendMessage. If it works then I suspect the problem is with
the browser and script might be your only option.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:OT*************@TK2MSFTNGP05.phx.gbl...
cant use the script :(

Since this will just create a event on a link. bit of there is flash open then? I will get the object of the flash and the click
will not happen on the button that is in the flash. also mouseovers and other stuff will not happen. I need to create actual in
game browser with all the bell and whistles there is also the issue of scrollbars that need to be dragged

so my best bet is to use something like sendmessage, which is returning zero. maybe there is a click happening just not at 30,30
the point i am sending the cursor to.

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:en**************@TK2MSFTNGP05.phx.gbl...
>Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other post) but if it's non-zero that would indicate an error and
you should go from there.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:e$**************@TK2MSFTNGP03.phx.gbl...
>>>I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:%2***************@TK2MSFTNGP02.phx.gbl...
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the
Control some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification
to the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a
control on the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message news:ea*************@TK2MSFTNGP05.phx.gbl...
Hi All
>
Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.
>
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
>
>
This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));
>
regards
Abhishek
>
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message news:Of**************@TK2MSFTNGP04.phx.gbl...
>Hi Abhiishek,
>>
>Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
>this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows
>or EnumChildWindows Win32 API functions.
>>
>private void SimulateClick(Control ctrl)
>{
>if (ctrl == null)
> throw new ArgumentNullException("ctrl");
>>
>int x = 8, y = 8;
>int point = x + (y << 16);
>>
>SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
>SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
>}
>>
>private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;
>>
>[DllImport("user32.dll")]
>public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);
>>
>>
>--
>Dave Sexton
>>
>"Abhishek" <sh***@activelement.comwrote in message news:eY**************@TK2MSFTNGP02.phx.gbl...
>>Hi,
>>>
>> how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
>>application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
>>happen in that window directly.
>>>
>>Regards
>>Abhishek
>>>
>>
>>
>
>




Jul 27 '06 #13

P: n/a
Hi Dave

Thanks for all the help finally got it working.
the issue was not with sendmessage. the issue was the since the browser was
a activex control the normal browsername.handle did not work here. I had to
first use getwindow and GetClassName to find out the handle and then use
that in sendmessage.

but thanks a lot. it really helped.

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uV*************@TK2MSFTNGP05.phx.gbl...
Hi Abhishek,

Well you still might be able to use scripting if the Flash object model
supports simulating a mouse click at a certain point. Check if Flash also
supports raising a mouse over event and scrolling from script while your
at it.
>so my best bet is to use something like sendmessage, which is returning
zero. maybe there is a click happening just not at 30,30 the point i am
sending the cursor to.

You must send the point to the SendMessage function. It doesn't matter
where the cursor is actually located on the screen for SendMessage with
WM_LBUTTONDOWN.

To verify that SendMessage is working, since it is after all returning
zero, why don't you replace the browser with a Button and in a Click event
handler show a MessageBox. Try to click the button with SendMessage. If
it works then I suspect the problem is with the browser and script might
be your only option.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:OT*************@TK2MSFTNGP05.phx.gbl...
>cant use the script :(

Since this will just create a event on a link. bit of there is flash open
then? I will get the object of the flash and the click will not happen on
the button that is in the flash. also mouseovers and other stuff will
not happen. I need to create actual in game browser with all the bell and
whistles there is also the issue of scrollbars that need to be dragged

so my best bet is to use something like sendmessage, which is returning
zero. maybe there is a click happening just not at 30,30 the point i am
sending the cursor to.

regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:en**************@TK2MSFTNGP05.phx.gbl...
>>Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other
post) but if it's non-zero that would indicate an error and you should
go from there.

--
Dave Sexton

"Abhishek" <sh***@activelement.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl.. .
Hi Abhishek,
>
Is your 'game' by any chance tying up the UI Thread? You'd have to
call Application.DoEvents() in that case to allow the Control some
time to process your mouse notifications, however a better program
architecture would be more appropriate.
>
Actually, after reviewing your post a second time I'm not so sure I
fully understand the situation.
>
Do you have two applications running simultaneously and you are
attempting to get one application to send a mouse notification to the
other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and
you are attempting to send a mouse notification to a control on the
unfocused Form?
>
Please clarify. I'd like to help if I can.
>
--
Dave Sexton
>
"Abhishek" <sh***@activelement.comwrote in message
news:ea*************@TK2MSFTNGP05.phx.gbl...
>Hi All
>>
>Getting the handle of the contol is not the problem. if I have a game
>running then the mouse event does not function (with mouse_event).
>the sendmessage is not working at all, the application gets focus but
>the click event is not happening.
>>
>SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
>SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
>>
>>
>This is the mouse_event
>mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
>mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));
>>
>regards
>Abhishek
>>
>"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
>news:Of**************@TK2MSFTNGP04.phx.gbl. ..
>>Hi Abhiishek,
>>>
>>Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
>>control's handle using the Control.Handle property. I doubt this
>>will work cross-process but you could try to obtain the handle to a
>>window in another application using the EnumWindows or
>>EnumChildWindows Win32 API functions.
>>>
>>private void SimulateClick(Control ctrl)
>>{
>>if (ctrl == null)
>> throw new ArgumentNullException("ctrl");
>>>
>>int x = 8, y = 8;
>>int point = x + (y << 16);
>>>
>>SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
>>SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
>>}
>>>
>>private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;
>>>
>>[DllImport("user32.dll")]
>>public static extern int SendMessage(IntPtr hwnd, uint msg, int
>>wparam, int lparam);
>>>
>>>
>>--
>>Dave Sexton
>>>
>>"Abhishek" <sh***@activelement.comwrote in message
>>news:eY**************@TK2MSFTNGP02.phx.gbl.. .
>>>Hi,
>>>>
>>> how do I pass the handle of a control to the win32 api
>>>mouse_event. so that it will create the click event on that
>>>application only even if there is any other window in front of it.
>>>I dont what to set focus. I just want the click event to happen in
>>>that window directly.
>>>>
>>>Regards
>>>Abhishek
>>>>
>>>
>>>
>>
>>
>
>




Jul 28 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.