[perl-win32-gui-users] Help with Win32::Gui::Graphic, WM_Paint and InvalidateRect

2003-11-23 Thread rkoch
Hi,
I am trying to draw an interactive graph in a window, and I don't want to use
GD, ImageMagick, Freeimage or any other libraries because of portability
issues.
However, I can't figure out how to correctly use Win32::GUI::Graphic,
Win32::GUI::DC, WM_Paint and InvalidateRect. I've tried reading through some of
my MSDN docs that came with my copy of VC++ 6.0, but I couldn't figure this
out.
I also looked through the samples directory in the Win32::GUI distribution, but
none of them use the Graphic object or _Paint handlers.

Can _Paint messages be generated only for Win32::GUI::Graphic objects?
How do I tell my program to redraw a window object?
What will cause a window object to be redrawn?
Does the entire window object have to be redrawn or can an area of 
specified coordinates within the window object be redrawn?
What are the options that can be set in a "new Win32::GUI::Graphic"? I 
cannot find them in GUI.xs.
Can someone share a simple, working example of the usage of 
Win32::GUI::Graphic, WM_Paint, and InvalidateRect so that I can get 
started on experimentation?

Thanks in advance,
Rod

Here is my code so far:

#!c:/Perl/bin/wperl.exe -w
use strict;
use Win32::GUI;

my $topwin = new Win32::GUI::Window(
  -name   => 'topwin',
  -title => 'window',
  -width  => 800,
  -height => 600,
  -pos => [125,75],
  -maximizebox => "0",
  -minimizebox => "0",
  -resizable => "0"
);
my $graph = new Win32::GUI::Graphic(
$topwin,
   -name => "graph"
);

$topwin->Show();
$topwin->graph->InvalidateRect(1);
Win32::GUI::Dialog();

sub topwin_Terminate {
return -1;
}
sub graph_Paint {
my $W = $topwin->ScaleWidth;
my $H = $topwin->ScaleHeight;
my $DC = $topwin->graph->GetDC;
my $P = new Win32::GUI::Pen(
-color => 'BLACK', 
-width => 1,
);
$DC->SelectObject($P);
$DC->BeginPath();
$DC->MoveTo(50,50);
$DC->LineTo(45,75);
$DC->EndPath();
$DC->StrokePath();
$DC->Validate;
}
exit;


This message was sent using IMP, the Internet Messaging Program.




[perl-win32-gui-users] Solved Re: Help with Win32::Gui::Graphic, WM_Paint and InvalidateRect

2003-11-23 Thread rkoch
Hello,
I managed to solve my own problem with about 3 hours of tinkering and reading
MSDN. Although I still haven't figured out how exactly WM_Paint messages are
being generated. If I comment out the Update and the InvalidateRect method
calls, the graph line still gets drawn; which means calling Show on a window
fires a WM_Paint message. Additionally, the BeginPaint and EndPaint functions,
which I couldn't find in the documentation but did find in GUI.xs, don't seem
to do anything. They are required in Win32 C programming, so I (incorrectly?)
assumed they would be needed here as well. Finally, the Validate function has
no effect, which seems to indicate the Update function does not invalidate any
windows. So the WM_Paint message is being generated for a reason other than a
window being declared invalidated. Could someone clarify any of this? I'm
finding Win32 to be very complicated! 

Anyways, since there is not alot of documentation nor example code for
Win32::GUI, I'll show my simple code just in case someone else ever
needs to learn how to do this.

Best Regards,
Rod

#!c:/Perl/bin/wperl.exe -w
use strict;
use Win32::GUI;

my $topwin = new Win32::GUI::Window(
  -name   => 'topwin',
  -title => 'window',
  -width  => 800,
  -height => 600,
  -pos => [125,75],
  -maximizebox => "0",
  -minimizebox => "0",
  -resizable => "0"
);

my $graph = new Win32::GUI::Graphic(
$topwin,
-left => 0,
-top => 0,
-width => $topwin->ScaleWidth,#same width as parent window
-height => $topwin->ScaleHeight,#same height as parent window
-name => "graph",
);
$topwin->Show();
$graph->Show();
#$graph->Update(); Send WM_Paint message for the graphic control window?
#GUI::InvalidateRect($topwin,1);

Win32::GUI::Dialog();

sub graph_Paint {
my $W = $graph->ScaleWidth;
my $H = $graph->ScaleHeight;
my $DC = $graph->GetDC;
#$graph->BeginPaint(); useless?
$DC->MoveTo(0,$H);
$DC->LineTo($W,0);
#$DC->Validate; useless?
#$graph->EndPaint(); useless?
return 1;
}
sub topwin_Terminate {
return -1;
}
sub ExitButton_Click {
return -1;
}
exit;


This message was sent using IMP, the Internet Messaging Program.