private void videoModeCombo_SelectedIndexChanged(object sender, EventArgs e) { int index = videoModeCombo.SelectedIndex; if (index >= 0) { // query our video mode if (User_32.EnumDisplaySettings(null, index, ref dm) != 0) { int flags = 0; if (writeToRegistrycb.Checked) { flags = User_32.CDS_UPDATEREGISTRY; } int err = User_32.ChangeDisplaySettings(ref dm, flags); if (err != User_32.DISP_CHANGE_SUCCESSFUL) { MessageBox.Show("Error on ChangeDisplaySettings " + err); } } else { MessageBox.Show("Error on EnumDisplaySettings, index= " + index); } } }
public CResolution(int a, int b) { Screen screen = Screen.PrimaryScreen; int iWidth = a; int iHeight = b; DEVMODE1 dm = new DEVMODE1(); dm.dmDeviceName = new String(new char[32]); dm.dmFormName = new String(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); getMaximumSupportedResolution(); if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm)) { dm.dmPelsWidth = iWidth; dm.dmPelsHeight = iHeight; int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST); if (iRet == User_32.DISP_CHANGE_FAILED) { Console.WriteLine("Unable to process your request"); Console.WriteLine("Description: Unable To Process Your Request. Sorry For This Inconvenience."); } else { iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY); switch (iRet) { case User_32.DISP_CHANGE_SUCCESSFUL: { break; //successfull change } case User_32.DISP_CHANGE_RESTART: { Console.WriteLine("Description: You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode."); break; //windows 9x series you have to restart } default: { Console.WriteLine("Description: Failed To Change The Resolution."); break; //failed to change } } } } }
public CResolution(int a, int b) { Screen screen = Screen.PrimaryScreen; int iWidth = a; int iHeight = b; DEVMODE1 dm = new DEVMODE1(); dm.dmDeviceName = new String(new char[32]); dm.dmFormName = new String(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm)) { dm.dmPelsWidth = iWidth; dm.dmPelsHeight = iHeight; int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST); if (iRet == User_32.DISP_CHANGE_FAILED) { MessageBox.Show("Unable to process your request"); MessageBox.Show("Description: Unable To Process Your Request. Sorry For This Inconvenience.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY); switch (iRet) { case User_32.DISP_CHANGE_SUCCESSFUL: { break; } case User_32.DISP_CHANGE_RESTART: { MessageBox.Show("Description: You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } default: { MessageBox.Show("Description: Failed To Change The Resolution.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } } } }
public static void Change(int width, int height, int frequency) { int iWidth = width; int iHeight = height; DEVMODE dm = new DEVMODE(); dm.dmDeviceName = new string(new char[32]); dm.dmFormName = new string(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); if (User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm) != 0) { dm.dmPelsWidth = iWidth; dm.dmPelsHeight = iHeight; dm.dmDisplayFrequency = frequency; int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST); if (iRet == User_32.DISP_CHANGE_FAILED) { Debug.Log("Unable to process your request"); Debug.Log("Description: Unable To Process Your Request. Sorry For This Inconvenience."); } else { iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY); switch (iRet) { case User_32.DISP_CHANGE_SUCCESSFUL: { break; } case User_32.DISP_CHANGE_RESTART: { Debug.Log("分辨率修改成功"); break; } default: { Debug.Log("自动分辨率修改失败"); break; } } } } }
public static int ChangeResolution(int width, int height) { DEVMODE dm = GetDevMode1(); if (User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm)) { dm.dmPelsWidth = width; dm.dmPelsHeight = height; int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST); if (iRet == User_32.DISP_CHANGE_FAILED) { return(-1); } else { iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY); switch (iRet) { case User_32.DISP_CHANGE_SUCCESSFUL: { return(0); } case User_32.DISP_CHANGE_RESTART: { return(1); } default: { return(-1); } } } } else { return(-1); } }
public static int ChangeResolution(int Width, int Height) { Screen screen = Screen.PrimaryScreen; DEVMODE1 dm = new DEVMODE1(); dm.dmDeviceName = new String(new char[32]); dm.dmFormName = new String(new char[32]); dm.dmSize = (short)Marshal.SizeOf(dm); if (User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm) == 0) { return(User_32.DISP_CHANGE_FAILED); } dm.dmPelsWidth = Width; dm.dmPelsHeight = Height; int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST); if (iRet == User_32.DISP_CHANGE_FAILED) { return(iRet); } else { /* * Thats good article, it gave me some initial knowledge and the direction of further searching. * There is some useful tip that I have encountered while writing my own application: * You can use another constant CDS_FULLSCREEN = 0x04 instead of CDS_UPDATEREGISTRY = 0x01 when changing resolution: * [code] User_32.ChangeDisplaySettings(ref dm, User_32.CDS_FULLSCREEN); [/code] * This gives you some benefits: resolution is changed temporally, you even do not need to restore previous settings - it is done automatically when the application exits. And, this doesn't disorder the icons - the desktop is not even affected. * I used this in writing a small game that run in full screen - form was covering the whole screen (automatically covering taskbar). * Maybe this information can help someone else too. */ return(User_32.ChangeDisplaySettings(ref dm, User_32.CDS_FULLSCREEN)); //return User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY); } }
public void setSupportedResolution(DEVMODE1 dm) { int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST); if (iRet == User_32.DISP_CHANGE_FAILED) { Console.WriteLine("Unable to process your request"); Console.WriteLine("Description: Unable To Process Your Request. Sorry For This Inconvenience."); } else { iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY); switch (iRet) { case User_32.DISP_CHANGE_SUCCESSFUL: { break; //successfull change } case User_32.DISP_CHANGE_RESTART: { Console.WriteLine("Description: You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode."); break; //windows 9x series you have to restart } default: { Console.WriteLine("Description: Failed To Change The Resolution."); break; //failed to change } } } }