Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Win32::GUI MessageBox

by coldmiser (Hermit)
on Oct 17, 2006 at 19:11 UTC ( #578879=perlquestion: print w/replies, xml ) Need Help??

coldmiser has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to put together a message window on my PC that will display a message on top of everything else. I also want to display the message window even if no one is logged into the system. I am able to get this far with it
use Win32::GUI; $main = Win32::GUI::Window->new(); $main->MessageBox($ARGV[0], "",0x001000|0x000030);
The problem I am having is where I want this message box to be displayed even when no one is logged into the system. I am trying to add the MB_SERVICE_NOTIFICATION type to this message box like so:
use Win32::GUI; $main = Win32::GUI::Window->new(); $main->MessageBox($ARGV[0], "",0x200000|0x001000|0x000030);
But when I do that, the message box stops showing up completely. Has anyone experienced problems like this? Is the 0x200000 number I'm using the wrong one?

Replies are listed 'Best First'.
Re: Win32::GUI MessageBox
by BrowserUk (Pope) on Oct 17, 2006 at 21:08 UTC

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://578879]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2021-06-24 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (130 votes). Check out past polls.

    Notices?