Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

popup with timeout question

47 views
Skip to first unread message

T

unread,
Dec 3, 2019, 12:02:46 AM12/3/19
to
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>


Paavo Helde

unread,
Dec 3, 2019, 3:13:26 AM12/3/19
to
On 3.12.2019 7:02, T wrote:
> 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.

C and C++ are two different languages. Windows SDK interface is defined
in C, not 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.
> MessageBoxW( my $handle, to-c-str( $MessageStr ), to-c-str(
> $TitleStr ), MB_ICONEXCLAMATION );

MessageBoxW is documented at
"https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox"
- it does not mention any timeout.

I have written some code for a "Windows popup with timeout" in C++, but
I doubt it will help you. It displays the message box in a separate
thread, while the main thread waits for it on a condition variable with
a timeout.

I guess you would get better responses in forums where Perl or Windows
are on topic.


T

unread,
Dec 3, 2019, 4:17:53 AM12/3/19
to
Hi Paavo,

Now I know were and what is going on with my MessageBoxW call.

On your reference, I also found MessageBoxIndirectA and
MessageBoxIndirectW. Maybe they will work. It is worth
experimenting!

Thank you!

-T

Alf P. Steinbach

unread,
Dec 3, 2019, 5:08:31 AM12/3/19
to
On 03.12.2019 06:02, T wrote:
> 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.

Perl code that calls a C function in the Windows API.

Naturally that's best asked about in a C++ language group.


> 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.

No, `MessageBox` and immediate closest family does not support any timeouts.

It may be that this JScript snippet, using the some of the COM-based
scripting support in the Windows API, can help you:

var WshShell = WScript.CreateObject("WScript.Shell");
var BtnCode = WshShell.Popup("Do you feel alright?", 7, "Answer
This Question:", 4 + 32);
switch(BtnCode) {
case 6:
WScript.Echo("Glad to hear you feel alright.");
break;
case 7:
WScript.Echo("Hope you're feeling better soon.");
break;
case -1:
WScript.Echo("Is there anybody out there?");
break;
}

Here "7" is the number of seconds before the message box closes
automatically, and "WScript.Shell" is a COM programmatic ID, which you
maybe can use with the relevant COM object creation functionality in
Perl, if there is.


> Many thanks,

Oh, don't mention it.

- Alf

T

unread,
Dec 3, 2019, 6:06:59 AM12/3/19
to
Thank you!

Geoff

unread,
Dec 3, 2019, 3:28:38 PM12/3/19
to
On Mon, 2 Dec 2019 21:02:35 -0800, T <T...@invalid.invalid> wrote:

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

There is no provision for a timeout in any message box in Windows.
However, you can probably use SetTimer in the initialization of the
message box with a pointer to a TimerProc and when the timer expires
the TimerProc function can send a WM_COMMAND message to the message
box.

T

unread,
Dec 3, 2019, 5:14:42 PM12/3/19
to
That explains it. Thank you!

I am spoiled by Linux's send-notify.


Geoff

unread,
Dec 4, 2019, 4:19:36 AM12/4/19
to
Keeping in mind that this is off topic for this group. Here's a simple
About box in C that might help. This will work if your timed box has
only one button and closes on receipt of a WM_COMMAND and doesn't have
to handle any other buttons.

BOOL CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM
lParam)
{

switch (message)
{
case WM_INITDIALOG:
SetTimer(hDlg, 1, 5000, NULL);
return (TRUE);
break;

case WM_TIMER:
SendMessage(hDlg, WM_COMMAND, NULL, NULL);
return(TRUE);
break;

case WM_COMMAND:
KillTimer(hDlg, 1);
EndDialog(hDlg, TRUE);
return (TRUE);
break;
}
return (FALSE);
}

T

unread,
Dec 10, 2019, 7:08:10 AM12/10/19
to
Thank you!
0 new messages