views:

57

answers:

1

In my Delphi 6 Pro program I'm able to change the cursor on a TWebBrowser component successfully using the code below, but only when it does not contain a valid web document:

const
    theCursorID: integer = 1;

Screen.Cursors[theCursorID] := LoadCursorFromFile(PChar(theAniCursorFilename));
theWebBrowser.Cursor := theCursorID;

As soon as a web document loads, the cursor reverts to the standard mouse pointer. I'm guessing it's because the underlying window (handle/canvas/etc.) changes when a web document is loaded. How can I successfully change the mouse cursor when a web document is loaded?

+1  A: 

Remember TWebBrowser is a wraper for IE, which in turns shows a consistent user interface, including cursors used to "navigate" in the browser. For example, wherever the loaded web page contains hyperlinks, it will change the cursor to a hand to let the user know s/he can click on that hyperlink.

I know no way to change this behavior from Delphi, maybe it is possible. But, if you're in control of the loaded web-page (it seems the case to me), you can code in that page the cursor change, because it is supported (only) in IE.

If you cannot or do not want to modify your .css file, put the following code to the header of your page:

<style type="text/css">
<!--
BODY { cursor:url("<url of your cursor>"); }
-->

Alternatively, you can directly modify the style of an element on your page like this:

...<body style="cursor:url(<url of your cursor>)" >... 
jachguate
Thanks jachguate. I thought since I was able to control the cursor position from code (SetCursorPos) that I'd be able to take over the cursor icon itself, but I guess not. I'll give your idea a try, but seeing as the web page is dominated by a Flash object, I'm not sure if I'll be able to override it's cursor choice. I have control over the web page, but not the SWF contained in the Flash object.
Robert Oschler
@Robert: I made a test, and the cursor change has no effect on a simple flash animation.
jachguate