MouseClick to Web Browser via messages
Thanks in advance,
I'm having trouble sending a mouseclick to a web browser with the WM_LMOUSEDOWN and WM_LMOUSEUP messages. Below are the html and javascript pages. Save them in the same folder then open the html file in internet explorer. All it does is put a paragraph that says "You just clicked!" whenever you click anywhere in the browser. It works just fine with the real mouse but not with my code.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
react.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>react</title>
<script src="./react.js"></script>
</head>
<body style="margin:0px;" onload="init()">
<div id="body" style="background-color:white; height:100%; width:100%; position:absolute;"></div>
</body>
</html>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
react.js
var numclicks = 0;
function init(){
var b = document.getElementById('body');
b.addEventListener("click",addP,false);
}
function addP(){
var t = document.createElement("p");
t.innerHTML = "You Just Clicked!";
t.id = "p" + numclicks;
var b = document.getElementById('body');
b.appendChild(t);
numclicks++;
}
////////////////////////////////////////////////////////////////////////////////////////////////
Anyway, I've seen things like mouse_event but I'm really wanting to capture messages and send them over a network. I can do this just fine but it didn't work when using PostMessage to the window. So I bypassed the network and tried to send it directly to the window and it still didn't work.
POINT p;
p.x = 500;
p.y = 500;
LPARAM lp = MAKELPARAM(p.x,p.y);
WPARAM wp;
chrome=FindWindow(NULL,TEXT("react - Windows Internet Explorer"));
SetForegroundWindow(chrome);
ShowWindow(chrome,3);
//SetActiveWindow(chrome);
//SetCapture(chrome);
//lr = DefWindowProc(chrome,WM_NCHITTEST,NULL,lp);
//lp = MAKELPARAM(lr,NULL);
//wp = MAKEWPARAM(chrome,NULL);
//lr = DefWindowProc(chrome,WM_MOUSEACTIVATE,wp,lp);
//PostMessage(chrome,WM_LBUTTONDOWN,MK_LBUTTON,lp);
//PostMessage(chrome,WM_LBUTTONUP,MK_LBUTTON,lp);
PostMessage(chrome,WM_LBUTTONDOWN,0,lp);
PostMessage(chrome,WM_LBUTTONUP,0,lp);
So in short sending the down and up messages with PostMessage to the handle found with FindWindow did not invoke the "click" eventlistener in the javascript file and I've not been able to figure out why. I was wondering if it was because the window wasn't activated but I tried sending WM_MOUSEACTIVATE, WM_NCHITTEST, calling SetActiveWindow, SetFocus, etc but none of that seems to work. I really hope we can get this working so I can move on to the fun stuff. I'm assuming it's something ridiculous like - Oh you weren't jumping up and down on one foot while holding your nose while posting the messages?:)
But I thought windows messages and the message queue are essentially the bottom line for windows. Any code in any other language for mouseclicks like OnClick etc compiles into a window procedure that responds to the mouse messages. Is this correct?
Thanks again!
Re: MouseClick to Web Browser via messages
Quote:
Anyway, I've seen things like mouse_event but I'm really wanting to capture messages and send them over a network. I can do this just fine but it didn't work when using PostMessage to the window. So I bypassed the network and tried to send it directly to the window and it still didn't work.
. . .
But I thought windows messages and the message queue are essentially the bottom line for windows.
This means you thought wrong. Seems browser is not that simple in processing user input.
Re: MouseClick to Web Browser via messages
It maybe that using the functions below to identify your "chrome" variable will bring better luck.
BOOL WINAPI GetGUIThreadInfo( _In_ DWORD idThread, _Inout_ LPGUITHREADINFO lpgui);
HWND WINAPI GetCapture(void);
Re: MouseClick to Web Browser via messages
It maybe that using the functions below to identify your "chrome" variable will bring better luck.
BOOL WINAPI GetGUIThreadInfo( _In_ DWORD idThread, _Inout_ LPGUITHREADINFO lpgui);
HWND WINAPI GetCapture(void);
Re: MouseClick to Web Browser via messages
Quote:
Originally Posted by
David101
Thanks in advance,
I'm having trouble sending a mouseclick to a web browser with the WM_LMOUSEDOWN and WM_LMOUSEUP messages.
Did you consider using SendInput instead?