MouseClick to Web Browser via messages
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: MouseClick to Web Browser via messages

  1. #1
    Join Date
    Oct 2012
    Posts
    1

    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!

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,877

    Re: MouseClick to Web Browser via messages

    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.
    Best regards,
    Igor

  3. #3
    Join Date
    Oct 2012
    Posts
    8

    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);

  4. #4
    Join Date
    Oct 2012
    Posts
    8

    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);

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,009

    Re: MouseClick to Web Browser via messages

    Quote Originally Posted by David101 View Post
    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?
    Last edited by VictorN; October 3rd, 2012 at 07:24 AM. Reason: Link was added
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center