primus has asked for the wisdom of the Perl Monks concerning the following question:


hail monks,

i seem to have an interesting problem that i wish i could fix, but i am not sure why it is still causing me trouble.

i load up a bitmap and whenever i minimize the window the bitmap disappears, also if i move a window on top of the one with the bitmap, the bitmap disappears. it's weird, i dont quite know what could be wrong.

here's the code i use to load it...
$bitmap = new Win32::GUI::Bitmap("temp.bmp"); $mypic = $main->AddLabel( -text => "nothing", -name => 'label_bitmap', -top => '25', -left => '10', -font => $t_font, -style => '14', -visible => '1', -background => [255,255,255], -foreground => [0,0,0],)); $mypic->SetImage($bitmap);
thanks for the help monks

Replies are listed 'Best First'.
Re: Win32::GUI bitmap
by primus (Scribe) on Jan 28, 2003 at 03:14 UTC
    to add to this... the following code works fine
    use Win32::GUI; $main = new Win32::GUI::Window( -name => 'Main', -title => 'temp', -width => '325', -height => '310', -minsize => ['300', '310'], -style => WS_OVERLAPPEDWINDOW, ); $main->Show(); $ok = "42"; $bitmap = new Win32::GUI::Bitmap("images/$ok.bmp"); push (@{$tmp},$main->AddLabel( -text => 'pic', -name => 'label_bitmap', -top => '25', -left => '10', -style => '14', -visible => '1', -background => [255,255,255], -foreground => [0,0,0], )); $tmp->[0]->SetImage($bitmap); Win32::GUI::Dialog(); sub Main_Terminate { -1; }
    and this is very close to what happens in my program... the only difference is that i use subroutines...
      An important side note (thanks to Johan Lindstrom) is that the "$bitmap" is only valid in its current scope, ie, if you make this a function and return, then the $bitmap is no longer valid (bug in GUI), so you'll need to make it global. I tried this numerous ways an got a lot of headaches until this was "uncovered".
Re: Win32::GUI bitmap
by Flame (Deacon) on Jan 28, 2003 at 04:43 UTC
    This is a problem you often run into using visual basic, at least while first getting started. The problem is, your window isn't getting completely redrawn. I don't quite remember the command to force a redraw, but you might find it if you contacted the Win32-GUI mailing list. http://sourceforge.net/projects/perl-win32-gui/



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      you monks wont believe this, but it is because the variable i was using to hold the instance of the bitmap went out of scope.... GAH! thanks all for the help
        Lol, well it wasn't what I thought it was, at least I don't think it was anymore, but it was still a valid possibility :) Glad to hear you solved your problem.



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Re: Win32::GUI bitmap
by pg (Canon) on Jan 28, 2003 at 06:06 UTC
    The moment I were reading your second post (your reply to yourself), I had the feeling that it might be a scope thing, as you said the only difference was that you used a sub.

    The lesson here is again, that good old advice:

    Use "use strict" and "use warnings" all the time.

    There is a good editing software, called EditPlus. It supports template, every time you new a perl file, this template will pop up, and then you can add your code on top of the template. You can set different template for each language. My template for perl is:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    So there is no chance for me to forget or to be lazy.

    EditPlus is a freeware, you can download it. Just go google.com, and search for editplus.

    It can also highlight syntax, match brace, implicitly ftp (so you can edit files on remote host, as if they are local)...Give a try, see whether you like it.
      Maybe your brain subconciously slurped up the whole post as it was presented on screen then pushed the correct answer to the top of your stack? Kind of follows basic neural-network strongest path relationship logic as well.

      Happens to me sometimes, and this is the best answer I can come up with. Maybe I shouldn't post after bedtime :-)

      Oh, and to make it on topic, I like "use warnings;" so much more than perl -w, not sure why on this one, it just makes more sense.

      heh, well i was talking with a computer science amigo of mine and then suddenly it hit me... 'SCOPE'!

      btw: EditPlus is just the best edditing software ever... i have been using it for about 3 years. it's great!

      thanks alot monks!!