如何使用perl win32 :: GUI创建一个在树结构中拖动节点的函数?

时间:2011-12-15 07:17:41

标签: perl

如何使用perl win32 :: gui将节点拖放到另一个位置? 可能吗?我正在创建树视图并动态添加节点。完成树结构后,我需要通过拖动将一个节点位置移动到另一个节点位置。我已经提到了下面的代码。

use strict;
use Win32::GUI;

my $main_window=Win32::GUI::Window->new(
        -name => 'Main',
        -text => 'Main Window',
        -left => 375,
        -top  => 200,
        -width =>510,#370,
        -height =>480,
        -background => [177,175,175],
        -dialogui   => 1,
        -maximizebox => 0,
  );

 $C = new Win32::GUI::Cursor("harrow.cur");

  Win32::GUI::SetCursor($C);

  $B1 = new Win32::GUI::Bitmap("node.bmp");
  $B2 = new Win32::GUI::Bitmap("node_sel.bmp");

    $IL = new Win32::GUI::ImageList(26, 26, 0, 2, 30);
    $IL->Add($B1, 0);
    $IL->Add($B2, 0);

   my $TV=$main_window->AddTreeView(
        -name      => "myTree",
        -text      => "",
        -width     => 220,
        -height    => 238,
        -left      => 260,
        -top       => 198,
        -lines     => 1,
        -rootlines => 1,
        -buttons   => 1,
        -visible   => 1,
        -imagelist => $IL,
        -editlabels =>1,
        -singleexpand => 1,
        -disabledragdrop =>0,

    );
   my $IndentWin = new GUI::Window(
        -text   => "Treeview Indent",
        -name   => "IndentWin",
        -width  => 200,
        -height => 100,
        -left   => 10,
        -top    => 10,
        -background=>[190,190,190],
    );

    my $IndentVal = $IndentWin->AddLabel(
        -text => "Indent value = ".$TV->Indent(),

        -name => "IndentVal",
        -left => 10,
        -top  => 10,
    );

   my $IndentNew = $IndentWin->AddTextfield(
        -text   =>  $TV->Indent(),
        -name   =>  "IndentNew",
        -left   =>  10,
        -top    => 40,
        -width  => 100,
        -height => 25,
    );

   my $IndentSet = $IndentWin->AddButton(
        -text => "Set",
        -name => "IndentSet",
        -left => 130,
        -top  => 10,
    );

  my $Button=$main_window->AddButton(                     
        -text => 'Create tree',
        -name =>  'treecreate',
        -size => [110,20],
        -align=>center,
        -pos  =>  [135,150],
        -font =>  $font1,
        -background =>  [177,175,175],
        -foreground => [],
        -tabstop => 1,
  );

$main_window->Show();

my $DOS = Win32::GUI::GetPerlWindow();
Win32::GUI::Hide($DOS);
Win32::GUI::Dialog();

sub treecreate_Click{
 for(my $inc=0;$inc>=10;$inc++){
  $TV->InsertItem(
              -text          => 'Root'.$inc,
              -image         => 0,
              -selectedimage => 1,
             );
 }
}

创建树状菜单后,如何将一个节点位置拖放到另一个位置。

1 个答案:

答案 0 :(得分:0)

注册处理程序以响应树上的onmousedown onmouseup

当onmousedown,检测选择了哪个项目,然后注册响应onmousemove的处理程序(闭​​包)

当onmouseup时,取消注册响应onmousemove的处理程序,检测鼠标位置,如果它仍在树窗口小部件上方,则使用api调用将先前检测到的项目移动到新位置

您还想在拖动时更改游标

http://cpansearch.perl.org/src/ROBERTMAY/Win32-GUI-1.06/samples/listview_drag_drop.pl

http://search.cpan.org/src/ROBERTMAY/Win32-GUI-1.06/Win32-GUI-DropFiles/t/08_DragQueryPoint.t