473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Handle+mouse_event

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
13 4874
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
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joshua Weston | last post by:
I am new to C++ and I am very interested in becoming proficient. This post is two-fold. One, I am having problems with this small test program. It is meant to allow user input to control a "@"...
0
by: yaktipper | last post by:
WH_JOURNALPLAYBACK and WH_JOURNALRECORD These hooks are difficult to get working in C#, but after much piecing together of various code snippets from different language examples across the Net,...
2
by: wesmanjunk | last post by:
Does anyone know how to generate mouse click in another application? using C# and Windows XP.. The Idea it to click ok buttons on a form where you know the position of all the buttons, or you...
36
by: aam | last post by:
how can i set up vb.net to interact with a game i'm playing online ? the game is a java applet. i'm trying to write a program using a winform to assist me with this game.i tried using sendkeys but...
4
by: Abhishek | last post by:
Hi, I have a activex web browser embedded in a windows form and on a click of a form button i need the mouse to go the position for example 100, 100 and click the link that will be there on that...
8
by: Dr1ZZ | last post by:
Hi, I'm currently working on a bot for a game. It works like this: 1: Take a picture of the current playing field 2: Do the calculations on what i gotta do (best move) 3: Use sendmessage...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.