in reply to Win32 GUI Window Problem

You're allowing the script to "fall off the end" and terminate, and when it terminates the windows will be closed.

Add Win32::GUI::Dialog(); after the close TXT;.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Win32 GUI Window Problem
by Acid Amygdala (Novice) on Jan 26, 2009 at 00:50 UTC
    This makes sense, however, it doesn't work when I try it. Do you have any idea why?
      It seems that it has to do with the windows automatically terminating at the completion of the foreach loop. Any ideas for fixing this? All comments, advice and ideas are greatly appreciated. And a big thank you to BrowserUk for your advice.
        Here is the revised version of the code, which now keeps the windows up:
        $filename="log3.txt"; open(TXT, $filename)||die("Could not open file!"); @filedata = <TXT>; close TXT; close TXT; open (TXT, ">$filename"); @alert = ['a'..'z']; $i=0, $p=1; while(@filedata || !@filedata) { if($filedata[0] =~ /(\s+)(\d{1,4})(\.\d{1,4}){3}(\s+)/) { &Build_Window; } shift(@filedata); ++$i; ++$p; if(!@filedata) { open(TXT, $filename)||die("Could not open file!"); @filedata = <TXT>; close TXT; open (TXT, ">$filename"); close TXT; &Loop; } } Win32::GUI::Dialog(); sub Loop { if($filedata[0] =~ /(\s+)(\d{1,4})(\.\d{1,4}){3}(\s+)/) { &Build_Window; Win32::GUI::Dialog(); } shift(@filedata); ++$i; ++$p; if(!@filedata) { open(TXT, $filename)||die("Could not open file!"); @filedata = <TXT>; close TXT; open (TXT, ">$filename"); close TXT; &Loop; } } sub Build_Window { $datetime = localtime(); $alert[$i] = new Win32::GUI::Window(-name => "Alert", -width = +> 500, -height => 150, -pos => [$p*2, $p*2]); $font = Win32::GUI::Font -> new(-name => "Arial", size => 46, +-bold => 1); $alert[$i] -> AddLabel(-text => $datetime, -font => $font); $alert[$i] -> AddLabel(-text => "SNORT ALERT: MALICIOUS BEHAVI +OR DETECTED!", -font => $font, -top => 50); $alert[$i] -> AddLabel(-text => $filedata[0], -font => $font, +-top => 75); my $t1 = $alert[$i] -> AddTimer('T1', 1000); Win32::Sound::Play("SystemExclamation"); $alert[$i] -> Show(); Win32::GUI::Dialog(); sub T1_Timer { return -1; } sub Alert_Terminate { return 1; } }
        The problem I have now is that only the first set of windows (the data that was first wrote to the log file) appears. Does anyone have any thoughts on this?
      Your first version of code with the excellent suggestion from BrowserUK looks like it should work. What may be happening here is that the windows you put up are just info info windows and re-display of these windows happens so fast that you don't notice it before program ends.

      Try putting a sleep(10) after BrowserUK's suggestion to see if windows really do come back. If that works, then you need to put a Window up that asks a question and waits for a user response. I'm not familiar with the particular module that you are using, but for example with Win32::MsgBox (I didn't worry about import of specific constants, etc).. just the basics .....

      use Win32; my $ERROR_OK_BOX=16; # Red Error X box with an ok button Win32::MsgBox("Some errors deteted, click Ok to end program", $ERROR_OK_BOX,"some_title" ); print "program now exiting\n";
      This segment of code will cause a "block" until user hits the OK button, ie program hangs until user does something. So presumably whatever you've already got up there will stay up there.