1 paragraph C code to translate into Delphi code

I am trying to send virtual mouse clicks to a flash object in Twebbrowser. I couldn't achive it by delphi
on the otherhand it seems they achived it in C or C# can someone help me to convert this code into pascal please?
thank you


http://www.dzone.com/snippets/simulate-mouse-click

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,int nMaxCount);

Open in new window


IntPtr handle = webBrowser1.Handle;
StringBuilder className = new StringBuilder(100);
while (className.ToString() != "Internet Explorer_Server") // your mileage may vary with this classname
{
   handle = GetWindow(handle, 5); // 5 == child
   GetClassName(handle, className, className.Capacity);
}
IntPtr lParam = (IntPtr)((y << 16) | x); // X and Y coordinates of the click
const IntPtr wParam = IntPtr.Zero; // change this if you want to simulate Ctrl-Click and such
const uint downCode = 0x201; // these codes are for single left clicks
const uint upCode   = 0x202;
SendMessage(handle, downCode, wParam, lParam); // mousedown
SendMessage(handle, upCode, wParam, lParam); // mouseup

Open in new window


and also there is another in here but I am not sure which is the best

http://www.geekpedia.com/code139_Simulate-Mouse-Click-On-WebBrowser-Control.html

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
 
namespace BrowserMouseClick
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
 
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://www.devpub.com");
        }
 
        private void btnMouseClick_Click(object sender, EventArgs e)
        {
            int x = 100; // X coordinate of the click
            int y = 80; // Y coordinate of the click
            IntPtr handle = webBrowser1.Handle;
            StringBuilder className = new StringBuilder(100);
            while (className.ToString() != "Internet Explorer_Server") // The class control for the browser
            {
                handle = GetWindow(handle, 5); // Get a handle to the child window
                GetClassName(handle, className, className.Capacity);
            }
 
            IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates
            IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
            const uint downCode = 0x201; // Left click down code
            const uint upCode = 0x202; // Left click up code
            SendMessage(handle, downCode, wParam, lParam); // Mouse button down
            SendMessage(handle, upCode, wParam, lParam); // Mouse button up
        }
    }
}

Open in new window

AffetmeyenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
With part of code from here ...
make this one:
var
  webHwd: HWND;
  lParam: Cardinal;
  x, y: Integer;
begin
  x := 80;
  y := 100;

  webHwd := GetIEHandle(webBrowser1, 'Internet Explorer_Server');
  if webHwd > 0 then
  begin
    lParam := (y shl 16) or x; // X and Y coordinates of the click
    SendMessage(webHwd, WM_LBUTTONDOWN, 0, lParam); // mousedown
    SendMessage(webHwd, WM_LBUTTONUP, 0, lParam); // mouseup
  end;

Open in new window


or

  x := 100;  //calculate web browser position first an add ...
  y := 200;
  //or
  SetCursorPos(x, y);
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
  mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.