- Joined
- May 25, 2009
- Messages
- 100
[FIXED] C# - EnumDisplaySettings() returns a wrong dmPelsWidth
Hi,
I tried making my own plugin for Sharpcraft but it's not working the way i want to.
The Plugin is meant to get the screen resolution and sets the mousecursor in the middle of the screen and it's working in general...the only thing is, that dmPelsWidth is set to '32' and not '1050' as it should be...dmPelsHeight is set to '1680'.
Does somebody has an idea, what could be wrong?
Hi,
I tried making my own plugin for Sharpcraft but it's not working the way i want to.
The Plugin is meant to get the screen resolution and sets the mousecursor in the middle of the screen and it's working in general...the only thing is, that dmPelsWidth is set to '32' and not '1050' as it should be...dmPelsHeight is set to '1680'.
Does somebody has an idea, what could be wrong?
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using TinkerWorX.SharpCraft.Game;
using TinkerWorX.SharpCraft.Game.Jass;
[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 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;
}
namespace Cataract92.KtKPlugin
{
public class KtKPlugin : GamePluginBase
{
public override String Name { get { return "KtK Plugin"; } }
public override Version Version { get { return new Version(0, 2); } }
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
private delegate void CenterMousePrototype();
private void CenterMouse() {
DEVMODE vDevMode = new DEVMODE();
EnumDisplaySettings(null, -1, ref vDevMode);
Console.WriteLine("Width:{0} Height:{1} Color:{2} Frequency:{3}", vDevMode.dmPelsWidth, vDevMode.dmPelsHeight, 1 << vDevMode.dmBitsPerPel, vDevMode.dmDisplayFrequency);
SetCursorPos(vDevMode.dmPelsWidth / 2, vDevMode.dmPelsHeight / 2);
}
public override void Initialize() {
WarcraftIII.AddNative(new CenterMousePrototype(this.CenterMouse));
}
}
}
Last edited: