in reply to Win32::GUI MessageBox

According to MSDN,

MB_SERVICE_NOTIFICATION

Windows NT/2000/XP: The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.

If this flag is set, the hWnd parameter must be NULL. This is so that the message box can appear on a desktop other than the desktop corresponding to the hWnd.

As Win32::GUI doesn't allow the perl programmer access to that parameter, the only way to achieve your aim using it, would be to modify the package. Since there is no mention of "MessageBox" in any of the packages Perl sources, this would have to be a patch to the XS code.

However, you can get at the MessageBox() api through Win32::API(::Prototype), and passing MB_SERVICE_NOTIFICATION to that causes the messagebox to appear when logged (which your example doesn't), provided you pass 0 as the first parameter. The following code has been tested and works when the screensaver is in operation. I haven't tried it when logged out, but see no reason it wouldn't work.

#! perl -slw use strict; use Win32::API::Prototype; ApiLink( 'User32', q[ int MessageBox( HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, U +INT uType ) ] ) or die $^E; MessageBox( 0, 'Some Text', 'A title', 0x200000|0x001000|0x000030 ) or die $^E;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Win32::GUI MessageBox
by coldmiser (Hermit) on Oct 18, 2006 at 13:53 UTC
    OK, thanks for your help, but I'm confused on two things you mentioned.

    First, you say that there is no mention of "MessageBox" in the Win32::GUI documentation. When I installed the Win32::GUI module, It installed a HTML file called Win32::GUI::Reference::Methods - Common Methods This file tells me directly how to use the MessageBox command. It also states, that when using MB_SERVICE_NOTIFICATION I should leave the hWnd (or Handle) off. I didn't have to modify the package (and with my programming skills, I wouldn't want to attempt it).

    Secondly, I installed the Win32::API module to try your sample code and I could not get it to work. I am unable to find the protocol.pm. I have looked in PPM & CPAN but have not found it.

    I do realize that it's probably something simple that I've overlooked, however this too I can learn and one day I may eventually evolve into a good programmer.

    Thanks.

      I actually said:

      Since there is no mention of "MessageBox" in any of the packages Perl sources,

      I grepped the source files (*.pm/*.pl). As the document you mention is .pod, it was not found.

      When I try to use the htmlised docs for Win32::GUI, all the links are dead ends producing:

      You tried to access the address file://localhost/c:/perl/html/TEMP/Win +32-GUI-1-1300-1139047283/blib/html/site/lib/Win32/GUI/Reference/Metho +ds.html, which is currently unavailable.

      which means that I did not see the info you've cited.

      There's probably some magical invokation of some obscure AS module that isn't documented, that would cause those .pod files to be htmlised and linked properly, but I am not aware of it.

      And when I try getting to it from the cpan docs I get

      Not found Whatever it was you were looking for, it's not here. This may be due t +o... You made a typo in the URL What you are looking for no longer exists on CPAN

      If CPAN doesn't know how to treat .pod files, I'm not surprised that I don't.

      Having an optional first parameter on a method seems a little obscure?

      A quick check with PPM finds Win32::API::Prototype:

      ppm> search Win32::API::Prototype Searching in Active Repositories 1. Roth [http://www.roth.net/perl/packages/] Win32-API-Prototype [0. +2002.12.17] Roth Consulting (http://www.roth.net/) ppm>

      Google turns up many similar pointers.

      There is a Win32::API mechanism similar to Win32::API::Protoype::ApiLink(), namely Win32::API->Import(), hence I linked to that module, but I've found the former less buggy.

      Glad you found your solution.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Ahh perfect, I did not have the ROTH repository in my PPM entries. After that addition, I found prototype quite easily.

        Your solution works perfectly now. Thank you

        You are an "Archbishop" among "Archbishops"