views:

154

answers:

1

I've made a wxPerl application which presents just a simple frame which only contains a wxMenuBar, wxPanel, wxTextCtrl and a wxStaticBitmap. The development and deployment platform is Windows XP and beyond.

The image is added to the form like this:

my $logoData = Wx::Bitmap->new(App::Resource::Images::getLogoPath(), wxBITMAP_TYPE_BMP);
my $logo = Wx::StaticBitmap->new($self, -1, $logoData);

I've had no problems displaying the image. I've made an installer with Inno Setup that adds a icon to the users' desktop. If the application gets started using that shortcut the window doesn't draw my wxStaticBitmap. Only when the application loses focus and some other window is being moved over it, only then will my wxStaticBitmap be drawn.

When starting the application from the start menu, quick start, or directly after compiling it with wxpar, or just with the perl interperter displays my wxStaticBitmap fine.

The only thing I've found is calling Refresh() and Update() on my wxFrame. After creating this wxFrame I call Show(1) and right after that Refresh() and Update(). But so far have had no luck with it.

+1  A: 

wxStaticBitmap is derived from wxWindow, so it has both Update and UpdateWindowUI methods. What happens when you call one of those on $logo immediately after creating it?

Edit: I just tried it, and the Update* methods don't help. However, what does force it to repaint is to call SetBitmap after creating the object. Here's what I did:

my $bmp = Wx::Bitmap->new("./testcard.bmp", wxBITMAP_TYPE_BMP);
my $logo = Wx::StaticBitmap->new($frame, wxID_ANY, $bmp);
$logo->SetBitmap($bmp);

$frame is a Wx::Frame, and I just put a button in a sizer and the above code in its event handler callback.

Anonymous
When I put this in a event this does seem to help. However, right after creating the object it doesn't seem to make a difference. It seems like when the application gets started focus is lost and then returned.Is it possible to automatically emit a event which calls this method. Maybe once or twice a second?
Htbaa
I don't know, I'm pretty new at wxWidgets. I've been trying to figure out if you can generate your own events, myself. But as for drawing, you might want to look at wxDC (and ::DrawBitmap), which may handle drawing the bitmap differently.
Anonymous
FWIW, a timer could work like this: `my $timer = Wx::Timer->new($logo); EVT_TIMER($logo, $timer, sub { $logo->SetBitmap($bmp); });`, but it's possible that bad form in a number of ways.
Anonymous
Will try that Monday at work. I'll keep you updated.
Htbaa
Makes no difference for me. But I'll try to see if I can get this problem fixed with updating and refreshing the gui with the use of a timer.
Htbaa
Had to call `$timer->Start(500, wxTIMER_ONE_SHOT)` to actually start the timer. I could've used wxTIMER_CONTINUOUS but that would introduce a flicker in the image. For now this is the best solution.
Htbaa