[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Get screen Size

Posted on 2002-05-04
3
Medium Priority
?
700 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
Six Sigma Control Plans

649 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