Selva,

I have managed to throw together a quick script that can be used to find info on a toolbar of another application. To use it, run the script and click and hold the left mouse button on the 'Find Window' button. This will hide the window, then while still holding the mouse button down, move the mouse over the toolbar of the other application and release the mouse. The window of the script should reappear, and display the number of buttons in the toolbar in the text box. Unfortunately, if you try to get the text of the toolbar buttons, the script crashes. At least, that is what happens for me when I try it on an instance of Notepad2 <http://www.flos-freeware.ch/notepad2.html>. Not sure exactly what causes this. It may work for you. Try un-commenting the block of code in the onMouseMove event to see what happens. Anyway, here is my script:

#!perl
use strict;
use warnings;

use Data::Dump qw(dump);
#use Win32::API;
use Win32::GUI qw();
use Win32::GUI::Constants qw(CW_USEDEFAULT HOLLOW_BRUSH WM_USER);
#use constant {TB_GETBUTTON => WM_USER+23};

my $MouseDown = 0;
my $FoundHandle;
my $penHilight = Win32::GUI::Pen->new(-width => 5, -color => 0x000000, -style => 0);
my $winMain = Win32::GUI::Window->new(
    -name => 'winMain',
    -text => 'Window Finder',
    -size => [320,240],
    -left => CW_USEDEFAULT,
    -maximizebox => 0,
    -resizable => 0,
);

$winMain->AddButton(
    -name => 'btnWinFind',
    -text => 'Find Window',
    -pos => [$winMain->ScaleWidth()/2-40,5],
    -size => [80,25],
    -onMouseDown => sub {
        my($self,$x,$y,$flags) = @_;
        $MouseDown = 1;
        $winMain->Hide();
        $self->SetCapture();
        return 1;
    },
    -onMouseUp => sub {
        my($self,$x,$y,$flags) = @_;
        $MouseDown = 0;
        if($FoundHandle){
            Win32::GUI::InvalidateRect($FoundHandle, 1);
            Win32::GUI::Update($FoundHandle);
            Win32::GUI::Redraw($FoundHandle, 1);
            $winMain->Show();
            $self->ReleaseCapture();
if(Win32::GUI::GetClassName($FoundHandle) eq 'ToolbarWindow32'){
                my $count = Win32::GUI::Toolbar::ButtonCount($FoundHandle);
                $winMain->txtInfo->Text("$count\r\n");
#                foreach(0..$count-1){
#                    my $tbbutton = "\0" x 20;
# Win32::GUI::SendMessage($FoundHandle, TB_GETBUTTON, $_, $tbbutton);
#                    dump $tbbutton;
# my @button = Win32::GUI::Toolbar::GetButton($FoundHandle, $_); # my @size = Win32::GUI::Toolbar::GetButtonSize($FoundHandle); # my $text = Win32::GUI::Toolbar::GetButtonText($FoundHandle, $_);
#                    $winMain->txtInfo->Append(join "\r\n", @size);
#                }
            }
        }
        return 1;
    },
    -onMouseMove => sub {
        my($self,$x,$y,$flags) = @_;
        if($MouseDown){
my $found = Win32::GUI::WindowFromPoint($self->ClientToScreen($x,$y));
            if($found){
                $FoundHandle = $found;
                Win32::GUI::InvalidateRect($found, 1);
                Win32::GUI::Update($found);
                Win32::GUI::Redraw($found, 1);
                my $dc = Win32::GUI::DC::GetDC($found);
                my %rect;
@rect{qw(left top right bottom)} = Win32::GUI::GetWindowRect($found);
                if($dc){
my $oldpen = Win32::GUI::DC::SelectObject($dc, $penHilight); my $oldbrush = Win32::GUI::DC::SelectObject($dc, Win32::GUI::DC::GetStockObject(HOLLOW_BRUSH)); Win32::GUI::DC::Rectangle($dc,0,0,$rect{right}-$rect{left},$rect{bottom}-$rect{top});
                    Win32::GUI::DC::SelectObject($dc, $oldpen) if $oldpen;
Win32::GUI::DC::SelectObject($dc, $oldbrush) if $oldbrush;
                    Win32::GUI::DC::ReleaseDC($found, $dc);
                }
                else {
                    warn "Can't get DC: $^E";
                }
            }
        }
        return 1;
    },
);

$winMain->AddTextfield(
    -name => 'txtInfo',
    -size => [$winMain->ScaleWidth()-10,$winMain->ScaleHeight()-40],
    -pos => [5,35],
    -multiline => 1,
);

$winMain->Show();

Win32::GUI::Dialog();

__END__

I based this code off of some C/C++ code that was posted here <http://www.codeproject.com/kb/dialog/windowfinder.aspx>.

Hope this helps,

Kevin.
Kevin,
Thanks for your response.This is not created with Win32::GUI
This is VC++ application and in that application, in the toolbar (you could see save image etc - attachment- red colored is the toolbar INeed to work), I have to get/do the
Toolbar count ,
Button click based on indiex or test
Click on IMage
Size of Each Button
Individual Button State.
My perl script will not create these window application, I have to to some activity on these tollbar icons such as click and for this I need use of this module.
 Thx
Selva D

--- On *Wed, 19/5/10, Kevin Marshall /<kejoh...@hotmail.com>/* wrote:


    From: Kevin Marshall <kejoh...@hotmail.com>
    Subject: Re: [perl-win32-gui-users] Is it possible to work on
    toolbar controls with win32::GUI
    To: "selva ganapathy" <ganapathy_se...@yahoo.com>
    Cc: perl-win32-gui-users@lists.sourceforge.net
    Date: Wednesday, 19 May, 2010, 5:07 AM

    Selva,

    How exactly is this other window with toolbar created? Is it from
    a completely separate script or from a module that your script
    loads? Is it created using Win32::GUI in Perl? Could you provide a
    small example of your problem?

    Sorry for the confusion.

    Kevin.
    Kevin.
    Thanks for the update. The one you have referred will get the
    tool bar button count for which you create the window and add
    content to that window and you are getting the same.
    But I look for the  situation, where I have to get the Toolbar
    button count on existing window which I will not create on run time.
    I am looking some solution on the same . Any further thoughts
    from you is very much helpful.
    Thx in advance and I  hope that I have clarified my requirement.
    Selva D

    --- On *Mon, 10/5/10, Kevin Marshall /<kejoh...@hotmail.com>/* wrote:


        From: Kevin Marshall <kejoh...@hotmail.com>
        Subject: RE: [perl-win32-gui-users] Is it possible to work on
        toolbar controls with win32::GUI
        To: ganapathy_se...@yahoo.com
        Cc: "Perl-Win32-GUI-Users List"
        <perl-win32-gui-users@lists.sourceforge.net>
        Date: Monday, 10 May, 2010, 7:44 AM

        Selva,

        You can use the ButtonCount() method to retrieve the number
        of buttons in the toolbar and the GetButtonText() method to
        retrieve the text of the specified button. Here is some
        sample code:

        #!perl
        use strict;
        use warnings;

        use Data::Dump qw(dump);
        use Win32::GUI qw();
        use Win32::GUI::Constants qw(TBSTATE_ENABLED BTNS_SHOWTEXT
        IDB_STD_SMALL_COLOR CW_USEDEFAULT);

        my $win = Win32::GUI::Window->new(
            -name => 'win',
            -text => 'Toolbar Sample',
            -size => [320,240],
            -left => CW_USEDEFAULT,
        );

        $win->AddToolbar(
            -name => 'toolbar',
            -adjustable => 1,
            -flat => 1,
            -multiline => 1,
            -nodivider => 1,
        );
        my @buttons = (qw(Cut Copy Paste Undo Redo Delete New Open
        Save Preview
            Properties Help Find Replace Print));
        $win->toolbar->LoadImages(IDB_STD_SMALL_COLOR);
        $win->toolbar->AddString($_) foreach @buttons;
        $win->toolbar->AddButtons(
            scalar @buttons,
            map {($_,$_+1,TBSTATE_ENABLED,BTNS_SHOWTEXT,$_)} 0..$#buttons
        );

        $win->Show();

        Win32::GUI::Dialog();

        sub win_Resize {
            $win->toolbar->Width($win->Width());
            return 1;
        }

        sub toolbar_ButtonClick {
            my($index,$dropdown) = @_;
            printf "Button %02d of %02d text => %s\n", $index,
                $win->toolbar->ButtonCount(),
        $win->toolbar->GetButtonText($index);
            return 1;
        }
        __END__

        Hope this helps,

        Kevin.

        > Date: Tue, 4 May 2010 05:38:04 -0700
        > From: ganapathy_se...@yahoo.com
        > To: perl-win32-gui-users@lists.sourceforge.net
        > Subject: [perl-win32-gui-users] Is it possible to work on
        toolbar controls with win32::GUI
        >
        > Hi,
        > I exhaustively looked at win32::GUI and please clarify on
        the same.
        > I just want to get the toolbar item- count and also the
        text of the items in toolbar. I saw win32::GUI was creating
        an window and doing adding some control for the same.
        > Is there any way to test the toolbar controls for the
        existing toolbar by passing the window handler.
        >
        > I also tried with win32::GUItest..but not succeeded.(by
        using sendmessage ) Please any clue on this?
        >
        > Thanks
        > Selva D
        >
        >
        >
        >
        >
        >
        
------------------------------------------------------------------------------
        > _______________________________________________
        > 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/

        ------------------------------------------------------------------------
        Looking for a hot date? View photos of singles in your area!
        <http://clk.atdmt.com/NMN/go/150855801/direct/01/>






------------------------------------------------------------------------------

_______________________________________________
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/

Reply via email to