Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem SendMessage MouseClick

1,470 views
Skip to first unread message

Thomas Kluge

unread,
Oct 26, 2001, 8:12:02 AM10/26/01
to
Hallo, how can help?

I wonna send a MoseClick to a Button via API
The Button is in a Window which is ChildWindow of an Application
Sendmessage(hwnd,WM_LBUTTONDOWN, &H1,lParam)
does not work
funktioniert nicht.
He expected in lParam the MousePosition within the Button, if i get hWND the
Handle of the Button
Whatelse I try to process in lParam f.E. .&H00050005 or a POINTAPI structure
Spy++ tells in lParam stand 007FF29C
This is an undifined moeseposition at X:-3428 and Y:127
The API call fails with return 0
Who has an advise ?

Thanks Tom

Alexander Kienzle

unread,
Oct 26, 2001, 9:59:46 AM10/26/01
to
For standard buttons, you could send BM_CLICK instead
WM_LBUTTONDOWN, but that might not work if the button
is not a normal windows command button.
Simulating the mouse click only with WM_xxx messages is
a bit more tricky (I had some problem), I think it also requires
WM_MOUSEACTIVATE, hit-testing,... (see Spy++)

Hope this helps

Alex

Thomas Kluge <t...@TomsIT.de> wrote in message
news:#wxNpahXBHA.432@tkmsftngp07...

db

unread,
Oct 26, 2001, 10:42:53 AM10/26/01
to
You should be able to use 0 as the lParam. A click involves two messages
though, a WM_LBUTTONDOWN and a WM_LBUTTONUP, and it looks like you aren't
sending the buttonup message. In many cases (not all) you could also send a
WM_KEYDOWN and WM_KEYUP message, using VK_RETURN as the Virtual Key.

'Constants
Const MK_LBUTTON = &H1
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_RETURN = &HD

'Code
'Sends a click to Command1
Call SendMessage(Command1.hwnd, WM_LBUTTONDOWN, ByVal MK_LBUTTON, 0&)
Call SendMessage(Command1.hwnd, WM_LBUTTONUP, ByVal MK_LBUTTON, 0&)

or

'Sends the Enter Key to Command1
Call SendMessage(Command1.hwnd, WM_KEYDOWN, ByVal VK_RETURN, 0&)
Call SendMessage(Command1.hwnd, WM_KEYUP, ByVal VK_RETURN, 0&)

"Thomas Kluge" <t...@TomsIT.de> wrote in message
news:#wxNpahXBHA.432@tkmsftngp07...

Thomas Kluge

unread,
Oct 26, 2001, 11:54:28 AM10/26/01
to
Sorry,

WM_KEYDOWN and WM_KEYUP message, using VK_RETURN as the Virtual Key.
does't work. the button is also not reachable with keyboard-ENTER. If it, i
can use sendkeys.
He Onlys reacts on mouse-click. the Type of Button is Tbutton not VB
ThunderCommandButton.

Spy shows the following messages (if iclick the mouse left)
no messages to ParentWindow

messages to ChildWindow:
Send: WM_MOUSEACTIVATE hwndToplevelWindow, nHittest HTCLIENT uMouseMsg:
WM_LBUTTONDOWN, hwndTopWindow,02010001
Return:MA_ACTIVATE
Send:WM_SETCURSOR hwndButton, nHittest HTCLIENT wMouseMsg:
WM_LBUTTONDOWN,hwndButton,02010001
Return:false

messages to Button:
Send: WM_MOUSEACTIVATE hwndToplevelWindow, nHittest HTCLIENT uMouseMsg:
WM_LBUTTONDOWN, hwndTopWindow,02010001
Send:WM_SETCURSOR hwndButton, nHittest HTCLIENT wMouseMsg:
WM_LBUTTONDOWN,hwndButton,02010001
Return:false
Processed: WM_LBUTTONDOWN,fwKesys:MK_LBUTTON,wParam=1, lParam=MousePos
Processed: WM_LBUTTONUP,fwKesys:0000,wParam=0, lParam=MousePos

What had i to do in VB6, to get the same result ?

with regards Tom

db <d...@b.com> schrieb in im Newsbeitrag:
NDeC7.3201$8P4.4...@news1.rdc1.mb.home.com...

db

unread,
Oct 26, 2001, 12:46:56 PM10/26/01
to
As I said, the keydown won't always work, but the KEYDOWN/KEYUP should. It
doesn't matter whether it's a VB button or not, just substitute the button's
hwnd for the Command1.hwnd that I used in the example.:

> > Call SendMessage(theHWND, WM_LBUTTONDOWN, ByVal MK_LBUTTON, 0&)
> > Call SendMessage(theHWND, WM_LBUTTONUP, ByVal MK_LBUTTON, 0&)

If it really requires coordinates, then do this to send the message at
coordinates 30, 10 for example.

Dim xcoord as long
Dim ycoord as long
Dim packed as long

xcoord = 30
ycoord = 10
packed = (ycoord * &H10000) + xcoord

Call SendMessage(theHWND, WM_LBUTTONDOWN, ByVal MK_LBUTTON, packed)
Call SendMessage(theHWND, WM_LBUTTONUP, ByVal MK_LBUTTON, packed)


David


db

unread,
Oct 26, 2001, 12:50:23 PM10/26/01
to
As I said, the keydown won't always work, but the LBUTTONDOWN / LBUTTONUP


David


"Thomas Kluge" <t...@TomsIT.de> wrote in message

news:e8377WjXBHA.1428@tkmsftngp03...

db

unread,
Oct 26, 2001, 1:12:02 PM10/26/01
to
If it still doesn't work using my above example, then there is something
pretty funky going on with that program and you're maybe going to have to
try activating the MDI child first...the program may be ignoring the
button's messages when it's parent isn't the active window.

David


Thomas Kluge

unread,
Oct 26, 2001, 3:40:19 PM10/26/01
to
Not the solving,
in a VB test programm (the window to close with the button is here opened)
it runs through the events mousedown and mouseup but not through click !
And with the parameter 0& spy tells the undefined mouseposition i described
above.
with the copy of your code (packed) spy return mouse pos of xPos-3228 yPos
99.

This is the same if i run it from the vb-development or the compiled
version.
The window I have to close is an exteernal program, so i have to simulate
the click event.

Arrrhg, I try it now a have year. It seems tricky

Tom


Thomas Kluge <t...@TomsIT.de> schrieb in im Newsbeitrag:
e8377WjXBHA.1428@tkmsftngp03...

Thomas Kluge

unread,
Oct 26, 2001, 3:55:58 PM10/26/01
to
Not the solving,
in a VB test programm (the window to close with the button is here opened)
it runs through the events mousedown and mouseup but not through click !
And with the parameter 0& spy tells the undefined mouseposition i described
above.
with the copy of your code (packed) spy return mouse pos of xPos-3228 yPos
99.

This is the same if i run it from the vb-development or the compiled
version.
The window I have to close is an exteernal program, so i have to simulate
the click event.

Arrrhg, I try it now a have year. It seems tricky

Tom

db <d...@b.com> schrieb in im Newsbeitrag:

CPgC7.3811$8P4.4...@news1.rdc1.mb.home.com...

Samuel B. Quiring

unread,
Oct 26, 2001, 6:31:37 PM10/26/01
to
::SendMessage(hWnd, BM_CLICK, 0, 0);

(Where hWnd is the button's window)

Works great for me on both VB buttons as well
as Windows buttons.


"Thomas Kluge" <t...@TomsIT.de> wrote in message
news:#wxNpahXBHA.432@tkmsftngp07...

Thomas Kluge

unread,
Oct 27, 2001, 9:01:42 AM10/27/01
to
Sorry, No

that runs through MouseDown and MouseUp too.
But not activating the Event MouseClick. The Window will not be closed.

Any other idea ?

Tom
Samuel B. Quiring <sbq_n...@SpeechStudio.com> schrieb in im Newsbeitrag:
eDyZ2zmXBHA.1428@tkmsftngp03...

db

unread,
Oct 27, 2001, 10:38:24 AM10/27/01
to
I looked back through the previous posts in this thread and it looks like
your goal here is simply to close a window...is that correct? If so, maybe
it would be a lot easier just to send a WM_CLOSE message to the window
itself, rather than trying to click its close button. Have you tried that?
Would that accomplish the task?


David


Thomas Kluge

unread,
Oct 27, 2001, 11:46:40 AM10/27/01
to
No sorry.
This I tried first , WM_CLOSE sendkeys, ProcID (Window has no titel)
The code in the Click event must run.
It asks for new components (autoupdate)
If I close the window directly, the app closes.

Tom

db <d...@b.com> schrieb in im Newsbeitrag:

AFzC7.5125$8P4.8...@news1.rdc1.mb.home.com...

db

unread,
Oct 27, 2001, 2:19:58 PM10/27/01
to
I just realized something very important...I've always used PostMessage when
sending mouse messages, not SendMessage. I just tried using SendMessage and
it doesn't work for me either, but PostMessage does.

Try using PostMessage:

Call PostMessage(Command2.hwnd, WM_LBUTTONDOWN, ByVal MK_LBUTTON, 0&)
Call PostMessage(Command2.hwnd, WM_LBUTTONUP, ByVal MK_LBUTTON, 0&)


Thomas Kluge

unread,
Oct 27, 2001, 4:42:35 PM10/27/01
to
Sorry no,
the same effect.

My information is that PostMessage works asyncron and SendMessage syncron.
I sent you the test vb

Tom

db <d...@b.com> schrieb in im Newsbeitrag:

iVCC7.5310$8P4.8...@news1.rdc1.mb.home.com...

Thomas Kluge

unread,
Oct 28, 2001, 4:23:57 AM10/28/01
to
Your E-Mail is not valid,
so I can't sent you the vb app

db <d...@b.com> schrieb in im Newsbeitrag:

iVCC7.5310$8P4.8...@news1.rdc1.mb.home.com...

db

unread,
Oct 28, 2001, 1:07:52 PM10/28/01
to
Sorry, I do that to prevent spam. You can send it to: davb...@home.com

David

"Thomas Kluge" <t...@TomsIT.de> wrote in message

news:u4#FqX5XBHA.1644@tkmsftngp03...

db

unread,
Oct 28, 2001, 4:05:22 PM10/28/01
to
OK,

I got your test. I see what you mean...the target window is getting the
messages but not running it's button_click event. I'm not sure why it's
like that because wrote and app that does exactly the same thing a year ago,
and it works perfectly. The only thing different is that the app that I'm
sending the messages to was written in PowerBuilder, not VB. So, I guess
the results you get depend to some degree on the app that you are trying to
control.

Anyway, I did find a solution that works for closing the VB app. I found
that sending the button down/up message twice will do it. Just verify after
the first down/up message that the window is still there, and if it is, send
the button down/up messages again.

I don't know for sure if this will work in the app you are trying to
control, but if it doesn't, then I'd really need to see the other app to be
able to figure it out.

David


Rene Whitworth

unread,
Oct 29, 2001, 6:10:57 AM10/29/01
to
It might be just a stupid idea, but what if the app checks the mouse
position when receiving the click ?
Try to SetCursorPos() the mouse to the button (the position you use in your
messages) first.

--
Hope this helps ...

Rene Whitworth
R.Whi...@w-s-s.de
Whitworth Software Solutions - Germany
http://www.w-s-s.de

Please reply to the newsgroups ...

"Thomas Kluge" <t...@TomsIT.de> schrieb im Newsbeitrag
news:uj2rEduXBHA.1976@tkmsftngp07...

Thomas Kluge

unread,
Oct 30, 2001, 7:50:39 AM10/30/01
to
Yes, i think too.
But with sendmessage i cant pass through the mouse pos. (see above)
with postmeage it pass through, but the app arrives only the ButtonDown
message, the ButtonUp went to the nirvana
Tom


Rene Whitworth <R.Whi...@w-s-s.de> schrieb in im Newsbeitrag:
OxZ0rrGYBHA.2416@tkmsftngp05...

Thomas Kluge

unread,
Oct 30, 2001, 7:57:32 AM10/30/01
to
Sorry no,

first thank you for your vb app.
with vb it works fine. Also from 1 compiled app to another.
But if I try to use it to close the foreign window, it does'nt.
spy shows only the WM_LBUTTONDOWN message (twice).
the mous up message does not appear.

The OK -Button shows then an hourglass mousepointer (till waitung the
up-message)
I tried also to set first the WM_MOUSEACTIVATE and SETCURSOR first.

Its a little step foreward (i can now pass through the correct mousepos in
lParam)

Tom

db <d...@b.com> schrieb in im Newsbeitrag:

mq_C7.7798$8P4.1...@news1.rdc1.mb.home.com...

0 new messages