RE: How to passing a hex number in Win32::API call

2009-10-26 Thread Su, Yu (Eugene)
Hi,

I have a DLL from FTDI (ftd2xx.dll www.ftdichip.com) for a USB device. I
try to write a simple perl script to list a number of (FTD) USB devices
connected to a PC. My code below got an error on invalid parameter;

Argument "M-\0\0\0\0\" isn't numeric in subroutine entry at demo.pl line
# 

I guess I did not pass a hex data in the function call properly. Can
someone help me?

Thanks.

Eugene
 
 code snippet ###

use strict;
use Win32::API;
use Carp;
use warnings;

# from FTD2xx programmer guide: 
# FT_ListDevices(PVOID numDevs,PVOID NULL,DWORD FT_LIST_NUMBER_ONLY)
# FT_LIST_NUMBER_ONLY is defined in FTD2xx.h as 
#define FT_LIST_NUMBER_ONLY = 0x8000
#
my $function = new Win32::API("ftd2xx", "FT_ListDevices", "PPN", "N");
if (not defined $function) {
   die "Can't import API FT_ListDevices: $!\n";
}
my $DevBuffer = " " x 80;
my $FT_LIST_NUMBER_ONLY=pack('N', 0x8000);
my $status=$function->Call($DevBuffer,0,$FT_LIST_NUMBER_ONLY);
print "status: $status\n";
print "DeviceNumber: $DevBuffer";
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Strange Perl/Tk action

2009-10-26 Thread Geoff Horsnell
Many thanks. I have tried your suggestion and it seems to do the trick! And,
as you say, it also loses the "flicker".

Once again, many thanks

Geoff

-Original Message-
From: Jack [mailto:goodca...@hotmail.com] 
Sent: Monday, October 26, 2009 3:44 AM
To: 'Geoff Horsnell'; perl-win32-users@listserv.activestate.com
Subject: RE: Strange Perl/Tk action


Ok. I get it now. First off - sorry for the top post. It's just the way my
mail works.

I don't see the canvas resize on Vista, however I do see it flicker. I don't
doubt that it resizes though, I just cannot reproduce it. I guess the main
question I have is "why are you rebuilding the entire menu just to disable
an entry?". Instead you should just use the entryconfigure method and target
the entry you wish to disable.

Here is one way of doing that (fully working code - just cut, paste and
run):

###
use Tk;
use strict;

my $mw=tkinit;
$mw->Canvas->pack;
create_all_menus_only_once();
MainLoop;

sub create_all_menus_only_once {
  my $menub = $mw->Menu(-type => "menubar");
  $mw->configure (-menu => $menub);
  my $submenu = create_menu1($menub);
  $menub->cascade(
   -label => "Edit",
   -underline => 0,
   -tearoff =>0,
   -menu=>$submenu);
}

sub create_menu1 {
  my $mainmenu = shift;
  my $menu1 = $mainmenu->Menu(-tearoff=>0);
  #First entry
  $menu1->command(-label => 'A Switch to B',
-command=>[\&switch,$menu1,'A']);
  #Second entry
  $menu1->command(-label => 'B Switch to A',
-command=>[\&switch,$menu1,'B'], -state=>'disabled');
  return ($menu1);
}

sub switch {
  my ($m,$val) = @_;

  if ($val eq 'A') {
$m->entryconfigure(0,-state=>'disabled');
$m->entryconfigure(1,-state=>'normal');
  }
  elsif ($val eq 'B') {
$m->entryconfigure(0,-state=>'normal');
$m->entryconfigure(1,-state=>'disabled');
  }
}
__END__
###

There are "so" many ways to create and manipulate menus - that I could not
cover all the scenarios. In this method, I created the submenu before
creating the "Edit" cascade. This will allow you to use the menu reference
to adjust the entries as you see fit.

There is "no flicker" with this code - so I will guess that it will solve
your resizing issue.

HTH

Jack





___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Strange Perl/Tk action

2009-10-26 Thread Brian Raven
Geoff Horsnell <> wrote:
> Unfortunately, it would be rather a lot of code. I will try to
> describe the action with example segments. 

Which is why it is generally advisable to try to create a small example
script that illustrates the problem.

> 
> ...
> 
> sub create_all_menus {
>   $mode = "A";
>   $menub = $tl->Menu(-type => "menubar");
>   $tl->configure (-menu => $menub);
>   $widget1 = menub->cascade(-label => "Edit, -underline => 0,
>   -tearoff => 0); $widget->pack(-side => "top", -anchor => "nw");
>   &create_menu1 ($widget1);
> ...
> }
> 
> sub create_menu1 {
>   my $widget = shift;
> 
>   $state = "disabled";
>   if ($mode eq "A") {
> $widget->command(-label => "B", -underline => 0, -command =>
> \&switchToB); $widget->command(-label => "A", -underline => 0,
>   -command => \&switchToA, -state => $state); } else {
> $widget->command(-label => "B", -underline => 0, -command =>
> \&switchToB, -state => $state); $widget->command(-label => "A",
>   -underline => 0, -command => \&switchToA); }
> }
> ...
> sub switchToA {
>   $mode = "A";
>   &create_all_menus (...);  # repaint all menu buttons } Sub
>   switchToB { $mode = "B";
>   &create_all_menus (...);  # repaint all menu buttons }
> 
> After calling the "create_all_menus" from the main program, option
> "A" is greyed out and option "B" is active. When "B" is selected for
> the first time, option "B" is then greyed out and option "A" is
> active. At the same time, the height of the "canvas" window
> containing these menu buttons is reduced by about 0.2 cm. Subsequent
> selection of the "A" or "B" menu option (whichever is currently
> active) has no further effect on the size of the window.  
> 
> I hope this makes better sense.
> 
> TIA
> 
> Geoff
> 
> -Original Message-
> From: Jack [mailto:goodca...@hotmail.com]
> Sent: Saturday, October 24, 2009 10:51 PM
> To: 'Geoff Horsnell'; perl-win32-users@listserv.activestate.com
> Subject: RE: Strange Perl/Tk action
> 
> 
> It's hard to follow your description. Can you upload some sample code
> that 
> shows the problem?
> 
> "Shrinkage is always bad" ;)
> 
> Jack
> 
> 
> From: perl-win32-users-boun...@listserv.activestate.com
> [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf
> Of 
> Geoff Horsnell
> Sent: October-24-09 10:05 AM
> To: perl-win32-users@listserv.activestate.com
> Subject: Strange Perl/Tk action
> 
> 
> 
> I have created a GUI using the Tk "canvas" widget that contains a
> menu list 
> with two mutually exclusive menu items - say "A" and "B". When "A" is
> selected, "B" should be disabled (greyed out) and vice versa.
> Therefore, 
> when the currently active option is selected, the menu list needs to
> be 
> repainted switching the active and disabled items. However, the first
> time 
> that this happens, the height of the canvas window shrinks - by about
> the 
> height of the menu tab. The height of the window remains unchanged
> for all 
> subsequent menu actions. I have printed out the variable containing
> the 
> nominated height of the window before and after making the selection
> and it 
> does not change. I can compensate for this action by making the
> original 
> window height slightly larger in the first place. However, I would
> rather 
> that the shrinkage did not happen at all. Has anyone seen this happen
> for 
> themselves and does anyone know how to prevent the window from
> shrinking in 
> the first place?
> 
> Any suggestions would be most welcome.

I may have missed something from your description and code, but it seems
to me that using radio buttons in your menu would be preferable, not to
mention simpler, than recreating it. The widget demo has examples if you
need them.

HTH

-- 
Brian Raven 
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs