Solved

Get screen Size

Posted on 2002-05-04
3
672 Views
Last Modified: 2008-02-01
I am evaluating the use Win32::GUI module.
Does anyone know how can I get the size of the Screen (the resolution) in order to position my new window in the center of the screen?

Some example would be appriciated.

thanks.
0
Comment
Question by:sstouk
3 Comments
 
LVL 1

Expert Comment

by:baltman
ID: 6989911
I think you could best do so in JavaScript...
With JavaScript you can get the screensize and there are also scripts available that will center the new window, regardless of the screen size. JavaScript can also very easily be programmed in your Perl script.

Use the following JavaScript code to open a new window centered on the screen, regardless of the screensize:

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos)
     {
     if(pos=="random")
          {
          LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
          }
     if(pos=="center")
          {
          LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
          }
     else if((pos!="center" && pos!="random") || pos==null)
          {
          LeftPosition=0;TopPosition=20
          }

     settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
     win=window.open(mypage,myname,settings);
     }

// -->
</SCRIPT>

If you want more scripts for popup windows, have a look at http://www.dynamicdrive.com/dynamicindex8/popwin.htm

Hope this helps...

BA
0
 
LVL 10

Accepted Solution

by:
rj2 earned 50 total points
ID: 6990268
The tutorial on Win::GUI has an example demonstrating this.

http://search.cpan.org/doc/ACALPINI/Win32-GUI-0.0.558/docs/tut/guitut1.html#Centring_the_window_and_the_text

However, when I try this on my computer (Win2K, ActiveState Perl 5.6.1 build 631) the examples provided there crashes. This suggests that the module Win32::GUI is not yet ready for primetime.

I suggest you check out Tk instead. It has been around for a while, and is probably more stable than Win32::GUI. It also has the advantage of being platform independent.
Here is a link to the Perl/Tk FAQ, this might help you getting started with Perl/Tk.
http://w4.lns.cornell.edu/~pvhp/ptk/ptkTOC.html
Below is an example of centering a window with Perl/Tk.


#!/usr/bin/perl
use Tk;
my $m = new MainWindow;
CenterWindow($m,200,200);
MainLoop;


####################################################
sub CenterWindow {
####################################################
# Args: (0) window to center
#       (1) [optional] desired width
#       (2) [optional] desired height
#
# Returns: *nothing*
####################################################
    my($window, $width, $height) = @_;

    $window->idletasks;
    $width  = $window->reqwidth  unless $width;
    $height = $window->reqheight unless $height;
    my $x = int(($window->screenwidth  / 2) - ($width  / 2));
    my $y = int(($window->screenheight / 2) - ($height / 2));
    $window->geometry($width . "x" . $height . "+" . $x . "+" . $y);
}

0
 
LVL 6

Author Comment

by:sstouk
ID: 6991662
You gave me a link to the page, which had the answer I need.

I tested TK and found out that you can create nice Windows with it, but they will look like an emulation of Unix Desktop on Windows platform.
I want a professionally looking Windows GUI Application, which Win32::Gui perfectly provides with, because it accesses the native Windows dlls for doing it.
That's why I stick with Win32-Gui and am happy with.
All the basic controls are there, enough for working with.

I am thankful you pointed out the link where I got the answer and since I am using version 0.665 of Win32::GUI this function might had been fixed and worked perfectly for me. I simply did not know it.

Thanks again.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hard perl script 16 158
Perl Script - Remove row of data based on column value 3 75
Edit Odbc.ini using perl module 2 90
Call Shell Script from Perl Script 6 134
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question