Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:

It's well-documented that creating custom cursors in Tk under Windows using the -cursor option doesn't work. However, Tk comes with 77 or so (mostly hideous) X-windows cursors as standard. These cursors aren't part of Windows, so they must be in the Perl distribution somewhere. But where? I'm thinking a quick way to get the cursors I want would be to modify the standard ones. Any ideas where I could find them in my system and what their file format is?

Or is there better way?

Replies are listed 'Best First'.
Re: Modifying Standard Tk Cursors?
by Dr. Mu (Hermit) on Oct 07, 2004 at 15:59 UTC
    Yes, and in that same Chapter 23 of Mastering Perl/Tk, they offer the following code snippet,

    my $cursor = $^0 eq 'MSWin32' ? 'mouse' : [qw/@mouse.xbm mouse.mask brown white/];

    along with the comment, "What it's telling us is that, unfortunately, home-brewed cursors are not supported on Win32 machines [emphasis mine]; we use a built-in cursor named mouse instead."

    Hence, the point of my question. If I can't create my own cursor under Windows, how can I modify one of the built-in ones? (The file "cursorfont.h", BTW, is just a header file, associating cursor names with numbers.)

      If you really want to, you might be able to get a Windows resource editor to hack at the cursors themselves, stored in tk.dll (here it is in c:\perl\site\lib\auto\tk\tk.dll). Another option would be to recompile Tk yourself, but that is too much work for me. Of course neither of these options is very portable, but I too did a bit of looking (because it doesn't seem like it should be this hard) and there doesn't appear to be a way to do what you want on the fly under Windows.

      One other possibility would be to see how Win32::API or perhaps one of the Win32 GUI toolkits might let you do this. Please do let us know if you get a decent solution!

      --
      I'd like to be able to assign to an luser

Re: Modifying Standard Tk Cursors?
by zentara (Cardinal) on Oct 07, 2004 at 11:24 UTC
    In Master PerlTk Chapeter23, pTk Potpourri, it discusses how to make custom cursors:

    Besides a built-in cursor name, the -cursor option also accepts a cursor specification, which is an array reference of four elements: an X11 bitmap (XBM) filename, a mask filename, and foreground and background colors.

    on unix/linux it would look like

    my $cursor = [qw/@mouse.xbm mouse.mask brown white/];
    The X11/cursorfont.h file contains the names, tracking it down from there is left to you.

    Here is code from the MPTk's sample code:

    #!/usr/bin/perl -w use Tk; use strict; my $mw = MainWindow->new; my $c = $mw->Canvas->grid; $c->configure(-cursor => ['@images/trans_cur.xbm', 'images/trans_cur.msk', 'black', 'white']); $c->CanvasBind('<Motion>' => sub { my($c) = @_; my($x, $y) = ($Tk::event->x, $Tk::event->y); print "cursor at canvas coordinate ($x,$y)\n"; }); MainLoop;
    It is supposed to give you a transparent cursor, but it shows the idea. If you want the images, track them down on the Mptk website, under Chapter code samples.

    I'm not really a human, but I play one on earth. flash japh