Asked  7 Months ago    Answers:  5   Viewed   38 times

Possible Duplicate:
Getting the screen resolution using PHP

well the question is self explanatory

where i want to reach is

$width = ; //user screen width in here

F1! F1!



You need JavaScript, not PHP.

var screenWidth = window.screen.width,
    screenHeight = window.screen.height;

You can then send it to the server via Ajax (with an XmlHttpRequest).

See also the MDC window.screen docs.

Wednesday, March 31, 2021
answered 7 Months ago

You can convert it to an array with json_decode like this:

$json = json_decode('{
   "destination_addresses" : [ "Milano, Italia" ],
   "origin_addresses" : [ "Padova PD, Italia" ],
   "rows" : [
         "elements" : [
               "distance" : {
                  "text" : "246 km",
                  "value" : 246492
               "duration" : {
                  "text" : "2 ore 36 min",
                  "value" : 9388
               "status" : "OK"
   "status" : "OK"


The result is:

array(4) {
  array(1) {
    string(14) "Milano, Italia"
  array(1) {
    string(17) "Padova PD, Italia"
  array(1) {
    array(1) {
      array(1) {
        array(3) {
          array(2) {
            string(6) "246 km"
          array(2) {
            string(12) "2 ore 36 min"
          string(2) "OK"
  string(2) "OK"

In order to only get your km, you can do this afterwards:

    echo $json['rows']['0']['elements']['0']['distance']['text'];
Saturday, May 29, 2021
answered 5 Months ago

What you are looking for is Liquid Layout in WPF.

Avoid specifying explicit Width and Height for your elements and it should scale up to whatever screen resolution available.

Of course, MinWidth, MaxWidth and MinHeight, MaxHeight are also useful in restricting the size.


  • Automatic Layout in WPF
  • Discussion on MSDN forums on same topic with lots of pointers
  • Is WPF Really Resolution Independent?
Friday, July 30, 2021
answered 3 Months ago

Some things block some of your viewport, such a history/bookmarks side panel. This includes the taskbar, unless it's on Autohide

Then window.screen.width != window.screen.availWidth. :)

If you are drawing things to the viewport, you ought to use availWidth / availHeight to determine if things are off the viewport etc. Be sure to recalculate on window resize otherwise you won't know when the sidepanel has been closed.

Note that not all of the width given by this property may be available to the window itself. When other widgets occupy space that cannot be used by the window object, there is a difference in window.screen.width and window.screen.availWidth.


Wednesday, August 4, 2021
answered 3 Months ago

If you don't want to use System.Windows.Forms (or cannot), you can get the screen resolution by using a Windows API function EnumDisplaySettings.

To call the WinAPI function, you can use the P/Invoke feature that is also available on .NET Core. Please note that this will only work on a Windows system, because there's no WinAPI on non-Windows targets.

The function declaration looks as follows:

static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);

You also need the WinAPI DEVMODE struct definition:

struct DEVMODE
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
  public string dmDeviceName;
  public short dmSpecVersion;
  public short dmDriverVersion;
  public short dmSize;
  public short dmDriverExtra;
  public int dmFields;
  public int dmPositionX;
  public int dmPositionY;
  public int dmDisplayOrientation;
  public int dmDisplayFixedOutput;
  public short dmColor;
  public short dmDuplex;
  public short dmYResolution;
  public short dmTTOption;
  public short dmCollate;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
  public string dmFormName;
  public short dmLogPixels;
  public int dmBitsPerPel;
  public int dmPelsWidth;
  public int dmPelsHeight;
  public int dmDisplayFlags;
  public int dmDisplayFrequency;
  public int dmICMMethod;
  public int dmICMIntent;
  public int dmMediaType;
  public int dmDitherType;
  public int dmReserved1;
  public int dmReserved2;
  public int dmPanningWidth;
  public int dmPanningHeight;

Actually, you don't need most of this structure's fields. The interesting ones are dmPelsWidth and dmPelsHeight.

Call the function like this:


DEVMODE devMode = default;
devMode.dmSize = (short)Marshal.SizeOf(devMode);
EnumDisplaySettings(null, ENUM_CURRENT_SETTINGS, ref devMode);

Now you can check the screen resolution in the dmPelsWidth and dmPelsHeight fields of the devMode struct.

Since we specify null as first argument, the function describes the current display device on the computer on which the calling thread is running.

Wednesday, September 22, 2021
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :