Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Tk and native controls do not play along on Windows

by nikosv (Hermit)
on Jan 18, 2011 at 09:39 UTC ( #882834=perlquestion: print w/ replies, xml ) Need Help??
nikosv has asked for the wisdom of the Perl Monks concerning the following question:

Tk and native/MFC controls do not exchange WM_ windows messages correctly which results to this effect

pic

a button is clicked on the Tk mainwindow which fires a Windows control (ShBrowseForFolder).Everything seems fine until you drag the control around which does not refresh the background.

Is there a way to hook into the Tk Windows procedure so I can capture the messages (especially WM_PAINT, WM_ERASEBKGND) and handle them myself? (essentially establishing something like a C++ message map )

or tweaking and recompiling the Tk source? thanks

Comment on Tk and native controls do not play along on Windows
Re: Tk and native controls do not play along on Windows
by BrowserUk (Pope) on Jan 18, 2011 at 10:30 UTC

    Essentially, you'd need to service both message queues concurrently. Tk has calls that allow you to service it's queue without entering MainLoop, but there probably isn't any effective way to call them once you've entered the native control's dispatch loop.

    It would be worth trying invoking the ShBrowseForFolder() api from within a thread:

    use threads; asynch { ShBrowseForFolder( ... ); }->detach;

    That should allow the main thread to run the Tk MainLoop concurrently with the Native controls dispatch loop.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      It would be worth trying invoking the ShBrowseForFolder() api from within a thread

      that was one of my intial approaches,which works perfectly painting wise,but the app breaks shortly after since Tk is not thread safe

        but the app breaks shortly after since Tk is not thread safe

        Then only use Tk from one thread. Really, it works just fine.

        If you'd care to post your working but crashing code, I'll show you how to stop it from crashing.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        since Tk is not thread safe

        It doesn't matter if you only load Tk in one thread, see BrowserUks replies to Tk + threads and Tk and Threads

Re: Tk and native controls do not play along on Windows
by lamprecht (Friar) on Jan 18, 2011 at 10:34 UTC

    What keeps you from using Tks Dir chooser?

    perl -MTk -e"tkinit->chooseDirectory"

    Cheers, Chris
      because I would loose functionality such as the ability to 'make a new folder' available from within the MFC control,shown here pic2

      Besides the specific control,I would like to leverage possible alternate or more rich functionality from other native controls

        Have you considered using Wx?

        Wx::DirDialog will give you the native style directory chooser, with the new folder option.
Re: Tk and native controls do not play along on Windows
by zentara (Archbishop) on Jan 20, 2011 at 13:42 UTC
    Gtk2 has a nice file browser too, it's the same one you get with any Gtk2 app, like firefox, gimp, etc. It has an "Add" Button which allows you to make new directories, as per your pic above.
    #!/usr/bin/perl use strict; use warnings; use Gtk2 '-init'; my $window = Gtk2::Window->new; $window->set_title("File Selector"); $window->signal_connect( destroy => sub { Gtk2->main_quit; } ); my $button = Gtk2::Button->new("Select"); $button->signal_connect( clicked => \&dir_selector ); $window->add($button); $window->show_all(); Gtk2->main; sub dir_selector { my $d = Gtk2::FileChooserDialog->new( 'Choose a Directory', $window, 'select-folder', "Cancel" => "cancel", "OK" => "accept", ); my $response = $d->run(); if ( "accept" eq $response ) { print $d->get_filename(), "\n"; } $d->destroy; }

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://882834]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-08-30 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls