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

I am building a Perl-based application under Win32 (say, Windows 7/8/10) where I need to monitor what's going on in a particular region of the desktop display.

However, the region to be monitored is generated by another application and its output can be of a variable size and a variable location on the display, although it will always be a rectangular region within a standard window (but that Window can be of variable size).

So, I'm intending to have some mechanism where I can use a rectangular selection area/fence (much how the Windows 'Snipping Tool' works) to define an area of interest on the desktop. However, what I want returned from the selected area is not the content (as the Snipping Tool provides) but more the rectangular region's position/dimension information; I envisage this information to be presented like it is often specified in X11-parlance, as a "WxH+x+Y" string.

There is a tool I use under Windows called Meazure (see https://www.cthing.com/Meazure.asp) which captures the information I want but I can't retrieve the info very easily from that tool.

Hence, I'm looking to see if there's a Perl-ish way I can do what I need... If I'm lucky, there might be a CLI tool to do what I'm describing (I found one of those for Linux/X11/C (see https://bbs.archlinux.org/viewtopic.php?id=85378) but couldn't find anything similar for Windows... so far(!)).

Maybe something can be done with a Perl/Tk canvas that has a transparent background (is that even possible?) or something? Hmm... much work in that approach, I fear...

Anyway, I'd appreciate any thoughts.

Using Windows7-32bit/SP1 and Windows8-32bit, ActiveState Perl v5.16.3 and v5.20.2.


John

Edit: Updated with the version of Perl I use at home (v5.20.2)
  • Comment on How Do I Select An Area of the Win32 Desktop and Return Its Size and Location?

Replies are listed 'Best First'.
Re: How Do I Select An Area of the Win32 Desktop and Return Its Size and Location?
by Anonymous Monk on Aug 04, 2016 at 04:01 UTC
Re: How Do I Select An Area of the Win32 Desktop and Return Its Size and Location?
by ozboomer (Friar) on Aug 05, 2016 at 13:41 UTC

    Many thanks for the useful pointers.

    For now, I've opted for the simplest way out and have built something that lets me manipulate a standard window; I can use it to 'block out' the area of interest on the desktop and it returns the X11-style attributes of the window. Code follows:-

    # -------------------------------------------------------------------- +------- # 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/Tu +torial/Part1.pod # # -------------------------------------------------------------------- +------- use Win32::GUI(); Get_Script_Name(\$my_proc, \$my_path); # Determine the name of this s +cript $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 ====================
    Read more code in this 'spoiler', if you want...

    Ultimately, I still hope to work out how to draw a simple outlined rectangle... but this script works Ok.

    Again, many thanks for the assistance.


    John