Hi All,
I write in Perl6. I wrote a module to give me a pop up
in Windows to send information to the user. It uses
a native call and I do believe it is a C++ call, but I
really don't know what I am doing when it comes to
anything C.
Do any of you guys know how to add a time out to the
pop up? I do believe it would be in the choice of the
constants.
Many thanks,
-T
<WinMsg.pm6>
# unit module WinMsg;
# WinMsg.pm6
#`{
Reference:
https://stackoverflow.com/questions/59105696/how-can-i-create-pop-up-windows-for-perl6-in-windows
}
use NativeCall;
sub WinMsg( Str $TitleStr, Str $MessageStr ) is export( :WinMsg ) {
#`{
Pop up a message box to the user. Windows only.
Test one liner:
perl6 -e "use lib '.'; use WinMsg :WinMsg; WinMsg( 'Super Duper
Title', 'What? You were expecting something witty?' );"
}
my $SubName = &?ROUTINE.name;
my $OS = $*KERNEL.name;
if not $OS eq "win32" { say "Sorry, $SubName only work in Windows.";
exit; }
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 );
}
</WinSmg/pm6>