From: Glenn L. <pe...@ne...> - 2004-06-02 06:46:11
|
So, when I add "use warnings;" to the BitmapScroll.pl sample code, I get 40 "Use of uninitialized value in subroutine entry..." warnings. The line number information lines up with the call to EndPaint. EndPaint contains 40 attempts to obtain "-ps.*" values. There seems to be a correlation. BUT: The EndPaint code _seems_ to carefully check for NULL and exit. But I guess checking for NULL isn't the same as "Use of uninitialized value..." So I added a call to DataDumper between the BeginPaint and EndPaint calls, to dump the window object. No "-ps.*" entries are found. Are there two bugs? One/40 in BeginPaint to not really put the "-ps.*" entries in the window object? And one/40 in EndPaint to access uninitialized values when attempting to retrieve the "-ps.*" objects that aren't there? I'd really like to "cure" this problem, rather than leave warnings turned off. On approximately 6/1/2004 12:18 PM, came the following characters from the keyboard of Glenn Linderman: > Of course not. It kept getting later, and I kept getting tireder. When > I sent that message, I forgot that I renamed my file, so I could see the > one in CVS again. > > Oops. > > This morning when I woke up, I realized I should add a couple more > comments, also. > > Thanks for noticing. And sorry for the confusion. I kept learning > more, but I kept making silly mistakes too. > > > On approximately 6/1/2004 1:57 AM, came the following characters from > the keyboard of Jez White: > >> Hi, >> >> Is this the correct version? The resize event is the same as the >> original? >> >> Cheers, >> >> jez. >> ----- Original Message ----- From: "Glenn Linderman" <pe...@ne...> >> To: "Jez White" <je...@je...> >> Sent: Tuesday, June 01, 2004 9:38 AM >> Subject: another code revision >> >> >> >>> Hi Jez, >>> >>> I left some debug and try this sort of code in my last email. Here >>> is the code without such. Sorry for 3 versions before I got the >>> whole message across. I think the text is reasonable, although I >>> learned more as I wrote each message. >>> >>> -- >>> Glenn -- http://nevcal.com/ >>> =========================== >>> The best part about procrastination is that you are never bored, >>> because you have all kinds of things that you should be doing. >>> >>> >> >> >> >> > > > ------------------------------------------------------------------------ > > #This example creates a scrolling bitmap within another window. This example > #uses a hooked event to paint to the window directly, rather than using a > #Graphic Control. > > use Win32::GUI; > use strict; > > sub Paint { > #Paint event handler, called when ever the window needs to be redrawn/painted > #get the window that needs to be repainted, in this case it is the child window > my $mdc=shift; > my $win=shift; > #tell windows that we are starting to paint > $win->BeginPaint; > #get the DC of this window > my $dc=$win->GetDC; > #Perform a bit block transfer of the memory DC into the window DC > #The cordinates are based upon the position of the scroll bars > $dc->BitBlt(0, 0, $win->Width,$win->Height,$mdc,$win->ScrollPos(0),$win->ScrollPos(1)); > #tell windows that we have finished painting. > $win->EndPaint; > return 1; > } > > sub AdjScroll { > my $bmap=shift; > my $cwin=shift; > my ($cwid, $chei) = ($cwin->GetClientRect)[2..3]; > #Set the scroll bar page of each scroll bar. > #This has the effect of increasing/decreasing the size of the bar within the > #scroll bar as the window is resized. > if ($bmap) { > my ($width,$height)=$bmap->Info(); > while (1) { > #the ScrollPage calls might trigger a Resize event, so this code might > #run reentrantly. To be sure we don't use old data later and overwrite > #newer data, we reobtain the ClientRect after each operation that might > #change it. > $cwin->ScrollPage(0,$cwid); > my ($cwidA, $cheiA) = ($cwin->GetClientRect)[2..3]; > $cwin->ScrollPage(1,$cheiA); > my ($cwid2,$chei2) = ($cwin->GetClientRect)[2..3]; > my ($cwid3,$chei3) = ($cwin->Width,$cwin->Height); > last if $cwid == $cwid2 && $chei == $chei2; > ($cwid,$chei) = ($cwid2,$chei2); > } > } > } > > sub Resize { > #Resize handler, get the window > my $bmap=shift; > my $cwin=shift; > & AdjScroll($bmap,$cwin); > return 1; > } > > sub OpenBitmap { > my ($bmap,$mdc,$cwin) = @_; > #Function to load in the bitmap > my $file = Win32::GUI::GetOpenFileName( > -owner => $cwin, > -hidereadonly => 0, > -title => "Open an bitmap file", > -filter => ['Bitmaps' => '*.bmp', > 'All files' => '*.*', > ], > ); > $bmap=new Win32::GUI::Bitmap($file); > $_[0]=$bmap; # set original parameter > if ($bmap) { > #if we have a valid bitmap, get the dimensions > my ($width,$height)=$bmap->Info(); > #select the bitmap into the memory DC so it can be manipulated later. > $mdc->SelectObject($bmap); > #set the scroll bars to 0. > $cwin->ScrollRange(0,0,$width); > $cwin->ScrollRange(1,0,$height); > $cwin->ScrollPos(0,0); > $cwin->ScrollPos(1,0); > & AdjScroll($bmap,$cwin); > $cwin->InvalidateRect(1); #invalidate the child window so windows triggers the paint event > } > return 1; > } > > sub Scroll { > #Scroll event handler. We have to explicitly "move" the scroll bars. > #Once they have been moved, we repaint the window. > my($win,$scrollbar, $operation, $position) = @_; > if($operation == SB_THUMBTRACK) { > $win->ScrollPos($scrollbar,$position); > } > elsif($operation == SB_LINEDOWN) { > $win->ScrollPos($scrollbar,$win->ScrollPos($scrollbar)+1); > } > elsif($operation == SB_LINEUP) { > $win->ScrollPos($scrollbar,$win->ScrollPos($scrollbar)-1); > } > elsif($operation == SB_PAGEDOWN) { > $win->ScrollPos($scrollbar,$win->ScrollPos($scrollbar) + $win->ScrollPage($scrollbar)); > } > elsif($operation == SB_PAGEUP) { > $win->ScrollPos($scrollbar,$win->ScrollPos($scrollbar) - $win->ScrollPage($scrollbar)); > } > #invalidate the child window so windows triggers the paint event > $win->InvalidateRect(0); > return 1; > } > > #create a new class which stops the WM_ERASEBKGND message from erasing the > #background this stops the flicker of the window on resize. > my $WC = new Win32::GUI::Class( > -name => "NoFlicker", > -style => 0, > ); > > #Define global variable > my $bitmap; #will hold the bitmap > > sub MainResize { > my $win=shift; > my ($width, $height) = ($win->GetClientRect)[2..3]; > $win->Open->Left($width-120); > $win->ChildWin->Resize($width-150,$height); > return 1; > } > > #Create the window and child controls. > my $mainwin = new Win32::GUI::Window ( > -pos => [100, 100], > -size => [330, 235], > -name => "Window", > -text => "Bitmap Scroll demo", > -pushstyle => WS_CLIPCHILDREN, > -class => $WC, > #NEM Events for this window > -onResize => \&MainResize, > -onTerminate => sub {return -1;} > ); > > #Create a child window with a scroll bars. > my $ChildWin = new Win32::GUI::Window ( > -parent => $mainwin, > -name => "ChildWin", > -pos => [0, 0], > -size => [180, 235], > -popstyle => WS_CAPTION | WS_SIZEBOX, > -pushstyle => WS_CHILD | WS_CLIPCHILDREN, > -pushexstyle => WS_EX_CLIENTEDGE, > -class => $WC, > -hscroll => 1, > -vscroll => 1, > -onScroll => \&Scroll, > -onResize => sub {&Resize($bitmap,@_)}, > ); > > #Create a memory DC compatible with the child window DC > my $memdc=$ChildWin->GetDC->CreateCompatibleDC(); > > $mainwin->AddButton ( > -name => 'Open', > -pos => [205, 20], > -size => [110, 20], > -text => 'Open Bitmap', > -onClick => sub{ &OpenBitmap( $bitmap, $memdc, $ChildWin, @_ ) }, > ); > > #hook into the paint event of the child window > $ChildWin->Hook(15, sub { &Paint( $memdc, @_ )}); > > #show both windows and enter the Dialog phase. > $mainwin->Show(); > $ChildWin->Show(); > > Win32::GUI::Dialog(); -- Glenn -- http://nevcal.com/ =========================== The best part about procrastination is that you are never bored, because you have all kinds of things that you should be doing. |