srtindall
asked on
c# code to change mouse cursor from pointer to "hand" shape on Safari
does anyone have the
c# code to change mouse cursor from pointer to "hand" shape on Safari
c# code to change mouse cursor from pointer to "hand" shape on Safari
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My guess is this is an ASP.Net app. And if tht is the case I
Don't think these soln work. Is this a asp.net app?
Don't think these soln work. Is this a asp.net app?
I think u have 2 use css
.mousecursor{
Cursor:hand;
}
.mousecursor{
Cursor:hand;
}
Well I went under the notion that it was a Windows application. However if this is asp.net, then this is not the answer.
Monitor cursor movement and flag when it goes over Safari:
Then to start the monitor:
Then to catch the event:
If this is the path you were going and need help finishing the change cursor, let me know. The information on changing the cursor is at: http://msdn.microsoft.com/en-us/library/ms648393%28VS.85%29.aspx
Monitor cursor movement and flag when it goes over Safari:
//Requires reference to System.Drawing
public class MouseMonitor
{
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(POINT Point);
[DllImport("user32.dll")]
static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowThreadProcessId(IntPtr handle, out uint processId);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
public static implicit operator Point(POINT p)
{
return new Point(p.X, p.Y);
}
public static implicit operator POINT(Point p)
{
return new POINT(p.X, p.Y);
}
}
public class MouseFoundOverApplicationEventArgs : EventArgs
{
IntPtr windowHandle;
public MouseFoundOverApplicationEventArgs(IntPtr windowHandle)
{
this.windowHandle = windowHandle;
}
public IntPtr WindowHandle
{
get { return this.windowHandle; }
}
}
public delegate void MouseFoundOverApplicationEventHandler(object sender, MouseFoundOverApplicationEventArgs e);
public event MouseFoundOverApplicationEventHandler MouseFoundOverApplication;
Timer timer = new Timer();
string applicationName;
public MouseMonitor(string applicationName)
{
this.timer = new Timer();
this.timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
this.applicationName = applicationName;
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
IntPtr windowHandle = MouseMonitor.GetHandleOfWindow();
if (MouseMonitor.WindowMatchesApplication(windowHandle, applicationName))
this.OnMouseFoundOverApplication(new MouseFoundOverApplicationEventArgs(windowHandle));
this.timer.Start();
}
public void Start(double interval = 500)
{
this.timer.AutoReset = false;
this.timer.Interval = interval;
this.timer.Start();
}
public void Stop()
{
if (this.timer.Enabled)
this.timer.Stop();
}
protected void OnMouseFoundOverApplication(MouseFoundOverApplicationEventArgs e)
{
if (this.MouseFoundOverApplication != null)
this.MouseFoundOverApplication(this, e);
}
private static IntPtr GetHandleOfWindow()
{
POINT location;
MouseMonitor.GetCursorPos(out location);
IntPtr window = MouseMonitor.WindowFromPoint(location);
IntPtr windowParent = IntPtr.Zero;
while (window != IntPtr.Zero)
{
windowParent = window;
window = MouseMonitor.GetParent(window);
}
return windowParent;
}
private static bool WindowMatchesApplication(IntPtr windowHandle, string applicationName)
{
uint processID = 0;
MouseMonitor.GetWindowThreadProcessId(windowHandle, out processID);
Process process = Process.GetProcessById((int)processID);
string executableName = Path.GetFileName(process.MainModule.FileName);
return (applicationName.ToLower() == executableName.ToLower());
}
}
Then to start the monitor:
this.monitor = new MouseMonitor("safari.exe");
this.monitor.MouseFoundOverApplication += new MouseMonitor.MouseFoundOverApplicationEventHandler(monitor_MouseFoundOverApplication);
this.monitor.Start();
Then to catch the event:
void monitor_MouseFoundOverApplication(object sender, MouseMonitor.MouseFoundOverApplicationEventArgs e)
{
//TODO Add code to change cursor
}
If this is the path you were going and need help finishing the change cursor, let me know. The information on changing the cursor is at: http://msdn.microsoft.com/en-us/library/ms648393%28VS.85%29.aspx
Hello Bro,
Also look into this
Regards,
Asif Ahmed Khan
Also look into this
HCURSOR WINAPI SetCursor(
__in_opt HCURSOR hCursor
);
Regards,
Asif Ahmed Khan
Open in new window
To change it back to normal after the application has stopped loading:
Open in new window
Hope this will help you
Regards,
Asif Ahmed Khan