Link to home
Start Free TrialLog in
Avatar of Sergy Stouk
Sergy StoukFlag for Canada

asked on

Get screen Size

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.
Avatar of baltman
baltman

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
ASKER CERTIFIED SOLUTION
Avatar of rj2
rj2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sergy Stouk

ASKER

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.