[perl-win32-gui-users] Like to get started

2002-07-14 Thread Arvind L
Hi All,

i have installed Win32 GUI 0.0.558 on Win Nt through
ppm. Perl version is 5.6.1 (MSWin32-x86-multi-thread).

I tried this simple program to start with.

#!E:/Dev/Perl/bin/perl
use Win32::GUI;

$main = Win32::GUI::Window->new(
-name   => 'Main',
-width  => 100,
-height => 100,
);
$main->AddLabel(-text => "Hello, world");
$main->Show();
Win32::GUI::Dialog();

sub Main_Terminate {
-1;
}

This program generates an Windows application error.

"The instruction at "0x.." referenced memory at
"0x". The memory could not be read.

Could you wise folks out there please point out where
the problem could be.

Thanx in advance
Regards
Arvind

__
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com



RE: [perl-win32-gui-users] Like to get started

2002-07-14 Thread Piske, Harald
This is a common newbie error (xqsme), I think there are even some of the
samples where this happened:
ALL Win32-GUI objects (window, widgets, timers, everything) need a -name
option and usually this must be a unique name.
 
Change
$main->AddLabel(-text => "Hello, world");

to
$main->AddLabel(-name => "label01", -text => "Hello, world");

Here's a FAQ that we had to offer a year ago for beginners support.
Guys, anybody has something newer?? C'mon, this was outdated last year!!

 
Title: Win32::GUI FAQ



The Win32::GUI FAQ
Aldo Calpini, [EMAIL PROTECTED]
Erick Bourgeois, [EMAIL PROTECTED] 
Felix Gaehler, [EMAIL PROTECTED]
 
v0.3, August 20, 2001

This is the "Frequently Asked Questions" for Perl Win32::GUI module. The 
questions and answers have been collected from the Win32::GUI-Users mailing 
list. 


General Questions
What is Win32::GUI?
"Win32::GUI is a Win32-platform native graphical user interface toolkit for 
Perl. Basically, it's an XS implementation of most of the functions found in 
user32.dll and gdi32.dll, with an object oriented Perl interface and an 
event-based dialog model that mimic the functionality of visual basic. It was a 
big fun for me to put it up, hope it will be a fun for you too :-)"
Where can I get Win32::GUI?
The creator and chief maintainer of the Win32::GUI module is Aldo Calpini. 
The module and pertinent information can be found at http://dada.perl.it/. "The module is 
actually in beta testing so be warned that syntax and behavior can change with 
future builds; and of course, that there are many incomplete parts, sparse 
documentation (you can browse here the work in progress), and generally a lot of 
things to do." 
Win32::GUI for ActiveState Perl 5.6 can be downloaded from the ActiveState 
Archive using PPM: 
  ppm install Win32::GUI

Documentation is available at 
  http://dada.perl.it/gui_docs/gui.html

  http://www.jeb.ca/howto/The_Win32-GUI_HOWTO.html

What about licensing?
If I develop a product in Perl with usage of the Win32::GUI module, and I spread 
  (well lets assume for FREE) to the public.. Is it still under GNU license or 
  do we have to pay the Win32::GUI team something ? 
"No, you don't have to pay anything. I'm not a lawyer and I don't want to pay 
a lawyer :-) Win32::GUI is released under the Artistic License, e.g. you can 
redistribute it under the same terms of Perl itself." 


Frequent Problems
Why does my window seem to freeze when my program is in a loop?
I can help here. Put a call to DoEvents() inside the loop. This will ensure 
that all queued messages are processed before going on with the loop:

use strict;
use Win32::GUI;

my $main = Win32::GUI::Window->new(
  -name=> "Main",
  -title   => "Win32-GUI: Doevents-Demo",
  -left=> 100,
  -top => 100,
  -width   => 600,
  -height  => 400,
);

sub Main_Terminate() {
  print "Main window terminated\n";
  return -1;
}

my $textfield = $main->AddTextfield(
  -name   => "Textfield",
  -text   => "have fun and more",
  -left   => 75,
  -top=> 150,
  -width  => 200,
  -height => 40,
  -readonly => 1,
);

$main->Show();

$textfield->Text("Processing infile...");
open INFILE, ") {
  $linenr++;
  $textfield->Text("Processing line $linenr");
  Win32::GUI::DoEvents() >= 0 or die "Window was closed during processing";
  sleep 1; #body of the loop...
}

$textfield->Text("completed");
Win32::GUI::DoEvents();
sleep 1; #program continues...


This will, of course, make your loop run slightly slower (almost irrelevant 
if there is no activity on the window). But there is the advantage (other than 
having the Textfield saying "Processing...") of being able to stop the loop in 
the middle by killing the window, or with a 'dedicated' stopbutton, for example. 

Can I use a window handle in more than one process?
If you run some lengthy processing like web page retrieval with LWP, database 
search, file processing etc., and you cannot call $Window->DoEvents() within 
that processing, your window will seem to freeze during your processing. The 
solution to that is, to do the processing in a separate Windows thread or 
process. ActivePerl 5.6 simulates the "fork" command using Windows threads. 
"Well, from Windows point of view, it is a thread. From Perl's point of view, 
it is a process. The Perl interpreter is busily keeping the data separate 
between the two threads (I'm not sure I understand the complete technique of the 
magic that does that, but I'm sure it can be made to work because the Perl 
language doesn't expose "real" addresses (much))." 
"On the other hand, the (UNIX) model for "fork" is that the multiple 
processes (threads on Perl for Windows) start off with identical 
data/variables/file handles. And the Windows model for "windows" is that the 
windows are owned by a process (not a thread), and can be accessed by any thread 
that has the window handle. (And in fact, because Windows was developed on DOS, 
the windows are even a bit visible to other processes, but that doesn't concern 
us h