From: Felix G. <fe...@fr...> - 2001-04-14 21:03:26
|
<HTML> <BODY> <h1>The Win32::GUI FAQ</h1> <pre> Aldo Calpini, da...@pe... Erick Bourgeois, er...@je...=20 Felix Gaehler, fe...@fr... v0.1, April 14, 2001 </pre> <p><em>This is the "Frequently Asked Questions" for Perl = Win32::GUI=20 module. The questions and answers have been collected from the = Win32::GUI-Users=20 mailing list. </em>=20 <hr> <p><b>Important Notice: This is a first draft version of the FAQ. The = document=20 is not yet complete and the answers have not yet been = verified.</b></p> <hr> <H1>General Questions</H1> <H2>What is Win32::GUI?</H2> <p>"Win32::GUI is a Win32-platform native graphical user interface = toolkit for=20 Perl. Basically, it's an XS implementation of most of the functions = found in=20 user32.dll and gdi32.dll, with an object oriented Perl interface and = an event-based=20 dialog model that mimic the functionality of visual basic. It was a = big fun=20 for me to put it up, hope it will be a fun for you too :-)"</p> <H2>Where can I get Win32::GUI?</H2> <p>The creator and chief maintainer of the Win32::GUI module is Aldo = Calpini.=20 The module and pertinent information can be found at <a = href=3D"http://dada.perl.it/">http://dada.perl.it/</a>. <br> "The module is actually in beta testing so be warned that syntax and = behavior=20 can change with future builds; and of course, that there are many = incomplete=20 parts, sparse documentation (you can browse here the work in = progress), and=20 generally a lot of things to do." <p>Win32::GUI for ActiveState Perl 5.6 can be downloaded from the = ActiveState=20 Archive using ppm:=20 <pre> ppm install Win32::GUI </pre> <p>Documentation is available at <pre> <a = href=3D"http://dada.perl.it/gui_docs/gui.html">http://dada.perl.it/gui_do= cs/gui.html</a> <a = href=3D"http://www.jeb.ca/howto/The_Win32-GUI_HOWTO.html">http://www.jeb.= ca/howto/The_Win32-GUI_HOWTO.html</a> </pre> <H2>What about licensing?</H2> <p>If I develop a product in Perl with usage of the Win32::GUI module, = and I spread=20 (well lets asume for FREE) to the public.. is it still under GNU = license or=20 do we have to pay the win32::gui team something ?=20 <p> "No, you don't have to pay anything. I'm not a lawyer and I = don't want=20 to pay a lawyer :-) Win32::GUI is released under the Artistic License, = eg. you=20 can redistribute it under the same terms of Perl itself." <hr> <H1>Frequent Problems</H1> <H2>Why does my window seem to freeze when my program is in a loop?</H2> <p>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: <pre> Textfield->change(-text "Processing..."); = $$$verify foreach $line (<INFILE>) { $Window->DoEvents(); # body of the loop... } Textfield->change(-text "completed"); </pre> <p>This will, of course, make your loop run slightly slower (almost = irrelevant=20 if there is no activity on the window). But there is the advantage = (other than=20 having the Textfield saying "Processing...") of being able to stop the = loop=20 in the middle by killing the window, or with a 'dedicated' stopbutton, = for example.=20 <H2>Can I use a window handle in more than one process?</H2> <p>If you run some lengthy processing like web page retrieval with LWP, = database=20 search, file processing etc, and you cannot call = $Window->DoEvents() within=20 that processing, your window will seem to freeze during your = processing. The=20 solution to that is, to do the processing in a separate Windows thread = or process.=20 ActivePerl 5.6 simulates the "fork" command using Windows = threads. <p>"Well, from Windows point of view, it is a thread. From Perl's = point of=20 view, it is a process. The Perl interpreter is busily keeping the data = separate=20 between the two threads (I'm not sure I understand the complete = technique of=20 the magic that does that, but I'm sure it can be made to work because = the Perl=20 language doesn't expose "real" addresses (much))."=20 <p> "On the other hand, the (Unix) model for "fork" is that the = multiple=20 processes (threads on Perl for Windows) start off with identical = data/variables/file=20 handles. And the Windows model for "windows" is that the windows are = owned by=20 a process (not a thread), and can be accessed by any thread that has = the window=20 handle. (And in fact, because Windows was developed on DOS, the = windows are=20 even a bit visible to other processes, but that doesn't concern us = here.)" <p>"By creating the Win32::GUI objects before forking, both the = parent and=20 child threads get copies (?) of the object variables. Because of the = nature=20 of Windows, the embedded Window handles inside both copies of the = object variables=20 are equally usable. Because of the (present) nature of Win32::GUI, = whereby most=20 of the parameter data is pumped into Win32 API parameters, and most of = the return=20 values are obtained by calling Win32 APIs to obtain it, I have shown = experimentally=20 that it is possible to use the Win32::GUI object references from both = a parent=20 and a child thread. Now it is important to remember that Windows only = delivers=20 window messages to the first thread of a program, so in the Perl = "fork" environment,=20 this gets translated to <b>only the parent process of a group of = Perl-forked=20 processes can successfully run Win32::GUI::Dialog</b> (Yep, I tried it = the other=20 way first, figuring that the parent could more easily monitor the = child process=20 for death, since fork returns the child pid, and waitpid works that = way--but=20 it just hung, and the windows never appeared). However, <b>the child = can use=20 the object references created by Win32::GUI</b> [before the fork] to = access=20 the "IsEnabled", "IsVisible" attributes of the window widgets, and = they are=20 dynamically updated (not cached in the object). The child can access = the current=20 selection from combo boxes. The child can enable and disable widgets, = and the=20 display gets updated appropriately. This is quite adequate for my = application,=20 which now can do its "long" operations in the child "process", and = keep the=20 GUI window "active" (except that certain parts get disabled during = "long" operations)." <H2>How can I use Win32::GUI functions in EVAL?</H2> <p>Yes, Win32::GUI supports things like these (it's really Perl that = supports=20 it :-), but you need to escape your window-handler variable $W:=20 <pre> eval qq ( sub main::$subtxt { print "button clicked\n"; <b>\$W</b>->SimpleLabel->Text("Got a click"); } ); $@ or die "Error in eval: $@"; $$$verify </pre> ...and always check for $@ after an eval! <hr> <H1>Text Fields</H1> <H2>How can I change the background color of a text field?</H2> <p>To change the background color of a Richedit field, use</p> <pre> Richedit->SendMessage(EM_SETBKGNDCOLOR, 0, hex('00FF00')); </pre> <p>This sets the background color to green. Note that the hex() format = for the=20 color is expressed as BBGGRR (BB=3Dblue, GG=3Dgreen, RR=3Dred). </p> <p>Textfield does not support EM_SETBKGNDCOLOR. have you tried this: = </p> <pre> # change to red Textfield->Change( -background =3D> [ 255, 0, 0 ] );=20 # repaint the control Textfield->InvalidateRect(1); =20 </pre> <p>Note: Colors can now be given in the HTML notation too (eg. = "#E3E2CC"). <H2>How can I get a vertical scrollbar in a textfield?</H2> Add this option when you create the Textfield: <pre> -autovscroll =3D> 1 </pre> This should do the trick. <H2>How can I get the selected portion of a textfield?</H2> <p>There is a Selection method that returns the start and end of the = selection.=20 then you just make a substr on the Textfield content:=20 <pre> ($from, $to) =3D $Textfield->Selection(); $var =3D substr($Textfield->Text, $from, $to-$from); </pre> <H2>How can I get the _Change event from a RichEdit control?</H2> <p>"I'd like to share a solution to a problem that has been driving = me nuts=20 for a while. I changed a Textfield control to a RichEdit and it would = not give=20 me the _Change event. I dug in the GUI.xs and could find nothing = wrong. I finally=20 tracked it down to the eventmask being zero, which means that the = notification=20 messages don't come to the GUI message loop in the first place. The = workaround=20 is to do=20 <pre> $MainWindow->myRichEditField->SendMessage (0x445, 0, 1); </pre> <p>That sends EM_SETEVENTMASK (0x445) to the control with the ENM_CHANGE = bit set.=20 Hope that spares somebody else a headache." <hr> <H1>ListView</H1> <H2> How can I prevent the user from choosing more than one item in a = Listview?</H2> You can use the -singlesel option on the ListView to achieve what you = want. <H2>How can I display a popup menu within a ListView?</H2> <p>Here is an example how it can be done: <pre> # define popup menu for listview my $PopupMenu =3D new Win32::GUI::Menu( "Item Properties" =3D> "ItemProp", ">&Properties" =3D> "ItemProperties", ); =20 # get right-click in listview sub DataView_RightClick { my($X, $Y) =3D Win32::GUI::GetCursorPos(); =20 $MainWindow->TrackPopupMenu($PopupMenu->{ItemProp},$X, $Y); } =20 # clicked on particular menu item in popup menu sub ItemProperties_Click { ## code you want to process; } </pre> <hr> <H1>MessageBox</H1> <H2>What are the icon, button and modality values for MessageBox?</H2> <p>"I think these will work, I haven't tried them all.=20 <pre> Settings =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D 0 - display only the OK button 1 - display OK and Cancel buttons 2 - display Abort, Retry, and Ignore buttons 3 - display Yes, No, and Cancel buttons 4 - display Yes and No buttons 5 - display Retry and Cancel buttons 16 - display Critical Message icon 32 - display Warning Query icon 48 - display Warning Message icon 64 - display Information Message icon 0 - set first button as default 256 - set second button as default 512 - set third button as default 768 - set fourth button as default =20 Return Values =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 - OK 2 - Cancel 3 - Abort 4 - Retry 5 - Ignore 6 - Yes 7 - No" </pre> <H1>Cursors</H1> <H2>How can I change the cursor to hourglass and back?</H2> <p>$$$tbd (find out first...) <hr> <H1>Extensions to Win32::GUI</H1> <H2>Is there a spreadsheet (grid) look-a-like solution or = component?</H2> <p>"No, but I'm thinking about implementing one (just thinking for = now :-).=20 " <H2>Is there a inline webbrowser somewhere ? or a HTML or XML = parser?</H2> "No, and I don't think I will try to implement one :-) You should = instead=20 look at Win32::OLE, to see if you can embed an InternetExplorer instance = in a=20 window. That said, it seems that RichEdit 3.0 (available in Windows = 2000) has=20 a lot of nice features, that I'll try to implement if time = permits."=20 <H2>Is there support for JPG or common image formats like .PNG or = .GIF?</H2> <p>"Support is for .BMP files only. There is something in the Win32 = API about=20 JPGs, but I have not yet investigated it thoroughly."=20 <p>$$$How to convert JPG and GIF to BMP in Perl (tbd) <H2>Is there a Win32-GUI-Builder available (i.e. a visual aid in = designing the GUI)?</H2> <p>yes, well.. at least a basic one. Download <pre> <a = href=3D"ftp://ftp.wh.whoi.edu/pub/gb109.zip">ftp://ftp.wh.whoi.edu/pub/gb= 109.zip</a> </pre> For more information, see in the Win32::GUI mailing-list, the mails from = David Hiltz. <H2>How can I deal with moving and resizing stuff when a window is = resized?</H2> <p>"Dealing with moving and resizing stuff when a window is resized = is really=20 annoying, not to mention boring. So I created a class to make that = easier. That=20 was a lot more fun for some reason :) Anyway, the result is = Win32::GUI::Resizer.=20 <pre> <a = href=3D"http://www.bahnhof.se/~johanl/perl/Win32GUI/">http://www.bahnhof.= se/~johanl/perl/Win32GUI/</a> </pre> Please try it out if you like and let me know what you think. "=20 <p>$$$Source: mail from Johan Lindstr=F6m, Sourcerer, Boss Casinos Ltd, = Antigua,=20 jp...@bo...=20 <hr> </BODY></HTML> |