# --------------------------------------------------------------------------- # xrselw32.pl - Use a resizable window to define a desktop monitoring area # jjg, 5-Aug-2016 # # Description: # A quick'n'dirty tool to allow me to use a standard # Windows resizable 'Window' to block-out a region # of the desktop and return the location in an X11 # 'WxH+X+Y' format. # # Notes: # 1. I can't work-out how to place buttons and other # objects within the window (there doesn't seem to be # any Tk-like concept of 'pack' or similar in Win32::GUI), # so I took the KISS approach and have left the system # menu(s) on the main window; this allows me to use a # single button to accept the window and use the # "system menu" and '[X]' window button to act as a # 'Cancel' button. # # 2. I also can't work-out how to properly communicate # 'outside' of the Dialog 'monitoring' thing other than # through the use of global variables = kludge. Hence, # I'll make this whole silly thing an external tool, much # the same as I do with the linux version. Inefficient # but Pffft. # # 3. This is something that works Ok, so I'm not # particularly worried that it's not as pretty as # it might be... # # References: # http://www.perlmonks.com/?node_id=1169110 (my question) # http://search.cpan.org/~kmx/Win32-GUI-1.13/GENERATED/Win32/GUI/Tutorial/Part1.pod # # --------------------------------------------------------------------------- use Win32::GUI(); Get_Script_Name(\$my_proc, \$my_path); # Determine the name of this script $W_INIT = 440; # Initial window size $H_INIT = 330; $main_window; # Global declaritive ('Wot!?') $W, $H, $X, $Y; # GLobals that define the capture area: WxH+X+Y $position_status = 0; # ...and their validity Place_Window(); # Get the window position if ($position_status) { printf("%dx%d+%d+%d", $W, $H, $X, $Y); } else { printf(""); } # ==================== end mainline ==================== #### # ------------------------------------------------------------------------ # Place_Window - Use Win32::GUI to position a window as required # Uses Globals: $my_proc (others implicit) # Calls (Implicit): Main_Resize, Main_Terminate, # OK_BUTTON_Click, CANCEL_BUTTON_Click # ------------------------------------------------------------------------ sub Place_Window { my ($prompt, $w, $h, $desk, $dw, $dh, $x, $y); $prompt = "$my_proc - Define capture size & location"; $main_window = Win32::GUI::Window->new( -name => 'Main', -sysmenu => 1, # I'd like to remove this but I need to use # the '[X]' as a CANCEL button...Duhhh.. -width => $W_INIT, -height => $H_INIT, -text => $prompt, ); my $font = Win32::GUI::Font->new( -name => "Tahoma", -size => 12, ); my $OK_Button = $main_window->AddButton( -name => "OK_BUTTON", -text => " Ok ", -font => $font, -height => 38, -width => 68, ); # my $cncl = $main_window->AddButton( # -name => "CANCEL_BUTTON", # -text => "Cancel", # ); # ---- $w = $main_window->Width(); # Initial 'overlap window' geometry $h = $main_window->Height(); $desk = Win32::GUI::GetDesktopWindow(); $dw = Win32::GUI::Width($desk); $dh = Win32::GUI::Height($desk); $x = ($dw - $w) / 2; $y = ($dh - $h) / 2; # $main_window->Change(-minsize => [$W_INIT, $H_INIT]); $main_window->Resize($w, $h); $main_window->Move($x, $y); $main_window->Show(); Win32::GUI::Dialog(); # Monitor for events $W = $X2 - $X1; # Define the position/size in globals $H = $Y2 - $Y1; # NOTE: '$position_status' contains a truth value $X = $X1; # which says the position is valid or not $Y = $Y1; return; } # end Place_Window # ---------------------------------------------- # Main_Terminate - Event: Exit the main window # ...Win32::GUI updates # ---------------------------------------------- sub Main_Terminate { ($X1, $Y1, $X2, $Y2) = # Update globals Win32::GUI::GetWindowRect($main_window); -1; } # end Main_Terminate # -------------------------------------------- # OK_BUTTON_Click - Event: 'Ok' Button Click # ...Win32::GUI updates # -------------------------------------------- sub OK_BUTTON_Click { $position_status = 1; Main_Terminate(); } # end OK_BUTTON_Click # ------------------------------------------------------ # CANCEL_BUTTON_Click - Event: 'Cancel' Button Click # ...Win32::GUI updates # ------------------------------------------------------ sub CANCEL_BUTTON_Click { $position_status = 0; Main_Terminate(); } # end BTN_Click # ---------------------------------------------------- # Get_Script_Name - Return the basename of this file # Returns: script name (no ext.), path to script # ---------------------------------------------------- sub Get_Script_Name { my ($my_proc_ref, $my_path_ref) = @_; my ($buf); if (defined $PerlApp::VERSION) { $$my_proc_ref = PerlApp::exe(); $buf = PerlApp::exe(); } else { $$my_proc_ref = $0; $buf = $0; } $$my_proc_ref =~ s#\\#\/#g # DOS path to linux path if ($$my_proc_ref =~ m/\\/); $$my_proc_ref =~ s{.*/}{}; # removes "/"-delimited path $$my_proc_ref =~ s{\.[^.]+$}{}; # removes extension $buf =~ s#\\#\/#g if ($buf =~ m/\\/); # DOS path to linux path $buf =~ m#(.*)/#; $$my_path_ref = $1; return; } # end Get_Script_Name # [EOF]