Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I currently have a program that will get each connected monitor location, once i get the location I atach a windows media player object to the desktop handle for each monitor, the problem is the locations are wrong.

1 Monitor returns X:0 Y: 0
2nd Monitor returns X:-1080 Y:0
3rd Monitor returns X: 1080, -130

When I run the program they are all bunched up on one monitor

One monitor is rotated and 768x1366
The other two are 1080x1920

DPI is 100% on all three.

What I have tried:

I have tried
Screen.allScreens[¡].bounds
and
Screen.allScreens[¡].workingArea


And this is the current code:

using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AnimateMyBackground {
  public class ambScreen {
    public string DeviceName {
      get;
    }
    public int dmPelsHeight {
      get;
    }
    public int dmPelsWidth {
      get;
    }
    public int dmPositionX {
      get;
    }
    public int dmPositionY {
      get;
    }
    public Point Location {
      get;
    }
    public Size Size {
      get;
    }
    public ScreenOrientation dmDisplayOrientation {
      get;
    }
    public ambScreen() {}
    public ambScreen(string DeviceName, Size Size, Point Location, int dmPelsHeight, int dmPelsWidth, int dmPositionX, int dmPositionY, ScreenOrientation dmDisplayOrientation) {
      this.DeviceName = DeviceName;
      this.Size = Size;
      this.Location = Location;
      this.dmPositionX = dmPositionX;
      this.dmPositionY = dmPositionY;
      this.dmPelsHeight = dmPelsHeight;
      this.dmPelsWidth = dmPelsWidth;
      this.dmDisplayOrientation = dmDisplayOrientation;
    }
  }

  public class Display {
    private
    const int ENUM_CURRENT_SETTINGS = -1; 
//private int height = 0; 
//private int width = 0;
 //public Screen Screen { get; }
 public ambScreen ambScreen { get; } public WindowsMediaPlayer wmp { get; } 
public bool enable { get; set; } 
public bool autpPlay { get; set; }
 public onStatusUpdate OnStatusUpdate { get; set; } = null; 
public ToolStripMenuItem playNext { get; set; } 
public ToolStripMenuItem playPrevious { get; set; } 
public ToolStripMenuItem playerEnable { get; set; } 
public ToolStripMenuItem playerRandom { get; set; } 
public ToolStripMenuItem playerMute { get; set; }
 public ToolStripMenuItem loopCurrent { get; set; } 
private void doOnStatusUpdate(PlayEvent playEvent) { OnStatusUpdate?.Invoke(playEvent); } 
public Display(Screen Screen, Control.ControlCollection Controls, int index) { //this.Screen = Screen; DEVMODE dm = new DEVMODE(); dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE)); 
EnumDisplaySettings(Screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm); 
ambScreen = new ambScreen(Screen.DeviceName, new Size(dm.dmPelsWidth, dm.dmPelsHeight), new Point(dm.dmPositionX, dm.dmPositionY), dm.dmPelsHeight, dm.dmPelsWidth, dm.dmPositionX, dm.dmPositionY, dm.dmDisplayOrientation); wmp = new WindowsMediaPlayer(Controls, index); 
wmp.OnStatusUpdate += new onStatusUpdate(doOnStatusUpdate); //wmp.AxWindowsMediaPlayer.Dock = DockStyle.Fill; wmp.AxWindowsMediaPlayer.Location = ambScreen.Location; wmp.AxWindowsMediaPlayer.Size = ambScreen.Size; //wmp.PlayListName = "DISPLAY" + (c + 1).ToString(); //Controls.Add(wmp.AxWindowsMediaPlayer); //wmp.AxWindowsMediaPlayer.playlistCollection.newPlaylist("AnimateMyBackGround"); 
wmp.AxWindowsMediaPlayer.Hide(); } [DllImport("user32.dll")] 
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode); [StructLayout(LayoutKind.Sequential)] public struct DEVMODE { 
private const int CCHDEVICENAME = 0x20; 
private const int CCHFORMNAME = 0x20; [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 ScreenOrientation 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; } } }
Posted
Updated 5-Feb-21 13:40pm

1 solution

That could be a problem with EnumDisplaySettings() and lpszDeviceName.
Maybe this will help:
windows - C# EnumDisplaySettings not working for lpszDeviceName - Stack Overflow[^]

Otherwise try this: c# - Keep track of screen change and screen resolution change in Windows Form Application to change form size - Stack Overflow[^]
But I think you can only use this if you drag form(s) to the monitors.
 
Share this answer
 
v2
Comments
Member 1329249 13-Feb-21 18:45pm    
Hi I have messed with the code but it still return the same results not sure if I am doing this right thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900