Simulating mouse events on a TWebBrowser

Posted on 2005-04-29
Last Modified: 2010-04-05
Hi, I'm writing an application that has some similarities with the RemoteDesktop function in windows.

In application A, we have a TWebBrowser control that I want to be able to control from application B, (which should be runing on a different computer)  

A and B communicates via TCP network... (Indy10)
My plan was to make an imagecapture from the TWebBrowser component in A, and send that Image to B. The Image is then painted to a TCustomControl descendant in B, from which I also record all the WM_Mouse messages.

All WM_Mouse messages are sent over from B to A, and upon reception, they are posted to the TWebBrowser control.

I thought this would make it possible for me to control the TWebBrowser in A from B... but the WebBrowser control doesn't seem to react at all when I post the messages.

Any ideas why this doesn't work? or How this could be acheived in a better way?
Question by:Hypo
    LVL 11

    Assisted Solution

    Check out the thread

    it may provide some answers

    LVL 26

    Expert Comment

    The technique in that thread won't work because WebBrowser doesn't handle clicks in the same manner as regular windows.
    LVL 26

    Accepted Solution

    It WILL respond to the mouse_event api though. You will just need to calculate the position (in screen coords) to issue the mouse event.



      SetForegroundWindow(FindWindow('IEFrame', nil));

      mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, 100, 100, 0, 0);
      mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 100, 100, 0, 0);

    LVL 12

    Author Comment

    I didn't intend to use the mouse_event functions since I wanted to simulate the mouse events on a minimized window... But after giving it some thought I realized that I can't have a minimized window, mostly because of popupwindows and question/notification dialogs.

    The mouse_event functions works fine, but the SetForegroundWindow makes it impossible to click any buttons in the window, I think that's because SetForegroundWindow changes focus from the button, link or whatever; between the LEFTDOWN and LEFTUP calls.

    Removing the SetForegroundWindow makes it work fine.

    (A notification to all you others who reads this question: The coordinates that's passed in the mouse_event function IS NOT pixels. the range of the coordinates are from 0..65535, where 0,0 is top-left corner, and 65535,65535 is bottom right corner of the screen or desktop)

    I still dont understand why PostMessage doesn't work tho... :-/
    LVL 26

    Expert Comment

    by:Russell Libby
    One thing you should understand is that the controls in the IE window (buttons, links, edit fields, etc) are not true windowed controls (those with a handle). They are owner drawn / handled controls, and as such do not handle messages in the same way as a windowed control would.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now