Jez,
Very nice. Here's a modification to your gui.pl that
(1) fixes needing to run the the script with the current working
directory the same as the location of the chm file - in this example the
perl script needs to be in the same directory as the chm file.
(2) Adds context help: click the '?' icon in the title bar, then one of
the buttons, or tab to one of the buttons (to give it focus) and hit 'F1'
[crashes on exit with Win32::GUI v1.03, but that is fixed in CVS.]
Regards,
Rob.
#!perl -w
use strict;
use warnings;
#use lib qw( C:/Development/Work/Win32-GUI/blib/arch
# C:/Development/Work/Win32-GUI/blib/lib );
use Win32::GUI;
use Win32::OLE ();
use Win32::OLE::Const ();
use File::Basename;
#Get the current working dir
my $helpfile = dirname($0) . "/Help.chm";
#Define the same contants that are used in the help system
sub IDH_Page1() {1003};
sub IDH_Page2() {1004};
sub IDH_Page3() {1005};
sub IDH_Page4() {1006};
sub WM_HELP() {83}
# Create the main window
my $mainwindow = Win32::GUI::DialogBox->new(
-name => "Window",
-title => "HTML help example",
-pos => [100,100],
-size => [400,400],
);
$mainwindow->UserData(IDH_Page1);
$mainwindow->AddButton (
-name => 'Help',
-text => 'Help',
-height => 20,
-width => 60,
-top => 2,
-left => 60,
-tip => 'Help page 1',
-tabstop => 1,
-onClick => sub {ShowHelp(IDH_Page1)},
)->UserData(IDH_Page3);
$mainwindow->AddButton (
-name => 'Help2',
-text => 'Help 2',
-height => 20,
-width => 60,
-top => 24,
-left => 60,
-tip => 'Help page 2',
-tabstop => 1,
-onClick => sub {ShowHelp(IDH_Page2)},
)->UserData(IDH_Page4);
$mainwindow->Hook(WM_HELP, \&contextHelp);
$mainwindow->Show();
#Enter the message processing loop
Win32::GUI::Dialog();
exit(0);
sub ShowHelp {
#show the help for this ID
my $id=shift;
Win32::OLE::Const::_ShowHelpContext($helpfile,$id);
return 1;
}
sub contextHelp
{
my ( $obj, $wparam, $lparam, $type, $msgcode ) = @_;
return unless $type == 0;
return unless $msgcode == WM_HELP;
# See MSDN HELPINFO structure
my ($cbSize, $iContextType, $ctrlId, $handle, $dwContextId, $x, $y)=
unpack("IiiLLll", unpack("P28", pack("L",$lparam)));
return unless $cbSize == 28;
return unless $iContextType == 1;
my $win = Win32::GUI::GetWindowObject($handle);
return unless $win;
ShowHelp($win->UserData());
return 0;
}
__END__
Jeremy White wrote:
All,
The below is a "rough and ready" guide to building a MS HTML help system
for your application. It will show you how to generate the .chm file,
and how to link to it from your GUI application. I've included a zip
folder containing all the example files you'll need.
The MS HTML system is based on a single .chm file, it's kind of like a
zip folder with all the HTML contained within it. To create the .chm
file you have to download free tools from Microsoft:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp
You need HtmlHelp.exe, download and install. The key file is hhc.exe
which 'compiles' your html files into a .chm file. Copy hhc.exe and
place it in the same folder as the files in the attached zip. There is
plenty of documentation on the MS site to explain the actual details, but:
To build the .chm, hhc.exe needs to have 4 files as well as your HTML
documentation:
.hhp file which contains the options and all the HTML files to be
included in your help file (any images will be included automatically)
.hhc file which contains the table of contents for your help system (the
tree on the left of the help system) the TOC is itself HTML.
.h file which contains numeric constants to identify topics (these
constants are used within your GUI)
.ali file which maps the numeric constants to actual HTML pages.
Typically you'll generate these files automatically from your
documentation. Once you've got these files, you now build your .chm file:
cd to the dir with the example zipped files then:
hhc.exe help.hhp
Now run gui.pl in the same folder, it'll bring up a window with a few
buttons. When you click on the button, the html help system
automatically opens and goes to the correct topic. You can create as
many topics as you like - it's quite flexible. When you distribute your
app, you just need the .chm file.
Cheers,
jez.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/