如何在 Windows 中为 Perl6 创建弹出窗口 windows?

How can I create pop-up windows for Perl6 in Windows?

我正在使用 Windows 7 和 10 rakudo-star-2019.03-x86_64 (JIT)。我想知道如何在 Perl6 中创建一个弹出窗口 window 来向用户提供信息?类似于 Linux 的发送通知或 Windows Pro 消息(没有网络)

非常感谢, -T

一个简单的消息框就够了吗?然后

use NativeCall;

constant WCHAR              = uint16;
constant INT                = int32;
constant UINT               = uint32;
constant HANDLE             = Pointer[void];
constant LPWCTSTR           = CArray[WCHAR];
constant MB_ICONEXCLAMATION = 0x00000030;

sub MessageBoxW( HANDLE, LPWCTSTR, LPWCTSTR, UINT ) is native('user32') returns INT { * };

MessageBoxW( my $handle, to-c-str("๘❤ Raku is awesome ❤๖"), to-c-str("Hellö Wαrld"), MB_ICONEXCLAMATION );

sub to-c-str( Str $str ) returns CArray[WCHAR]
{
    my @str := CArray[WCHAR].new;
    for ( $str.comb ).kv -> $i, $char { @str[$i] = $char.ord; }
    @str[ $str.chars ] = 0;
    @str;
}

对于任何更复杂的事情,我认为目前唯一可用的 GUI 选项是 bindings for Tk

我把你的例子变成了一个模块。谢谢!

# unit module WinMsg;
# WinMsg.pm6

#`{
Reference: 
}

use NativeCall;

sub WinMsg( Str $TitleStr, Str $MessageStr ) is export( :WinMsg ) {

   constant WCHAR              = uint16;
   constant INT                = int32;
   constant UINT               = uint32;
   constant HANDLE             = Pointer[void];
   constant LPWCTSTR           = CArray[WCHAR];
   constant MB_ICONEXCLAMATION = 0x00000030;

   # Note: the following two subs have to be embedded

   sub MessageBoxW( HANDLE, LPWCTSTR, LPWCTSTR, UINT ) is native('user32') returns INT { * };

   sub to-c-str( Str $str ) returns CArray[WCHAR]  {
      my @str := CArray[WCHAR].new;
      for ( $str.comb ).kv -> $i, $char { @str[$i] = $char.ord; }
      @str[ $str.chars ] = 0;
      @str;
   }


    # MessageBoxW( my $handle, to-c-str("๘❤ Raku is awesome ❤๖"), to-c-str("Hellö Wαrld"), MB_ICONEXCLAMATION );

    MessageBoxW( my $handle, to-c-str( $MessageStr ), to-c-str( $TitleStr ), MB_ICONEXCLAMATION );
}

测试运行行:

>perl6 -e "use lib '.'; use WinMsg :WinMsg; WinMsg( 'Super Duper Title', 'What? You were expecting something witty?' );"