Allow different users to use different resolutions under Windows (C # 2005)

Source: Internet
Author: User
Tags log static class
window| resolution in Windows to achieve different users have different resolution can actually do-it-yourself to achieve, look at the following examples:

First, make a C # program that can change the screen resolution, the source code is as follows, using the Vs.net 1:
1, new Windows Application project, named Screenresolution
2, paste the files of the code:
Program.cs



--------------------------------------------------------------------------------
#region Using directives

Using System;
Using System.Collections.Generic;
Using System.Windows.Forms;

#endregion

Namespace Screenresolution
{
Static Class Program
{
<summary>
The main entry point is for the application.
</summary>
[STAThread]
static void Main ()
{
Application.enablevisualstyles ();
Application.enablertlmirroring ();
Application.Run (New Form1 ());
}
}
}



--------------------------------------------------------------------------------

Form1.cs

--------------------------------------------------------------------------------


Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using System.Runtime.InteropServices;

Namespace Screenresolution
{

Partial class Form1:System.Windows.Forms.Form
{
public enum DMDO
{
DEFAULT = 0,
D90 = 1,
D180 = 2,
D270 = 3
}

[StructLayout (layoutkind.sequential, CharSet = CharSet.Auto)]
struct DEVMODE
{
public const int dm_displayfrequency = 0x400000;
public const int dm_pelswidth = 0x80000;
public const int dm_pelsheight = 0x100000;
Private Const int cchdevicename = 32;
Private Const int cchformname = 32;

[MarshalAs (UnmanagedType.ByValTStr, SizeConst = cchdevicename)]
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 Dmdo dmdisplayorientation;
public int dmdisplayfixedoutput;

public short Dmcolor;
public short Dmduplex;
public short dmyresolution;
public short dmttoption;
public short dmcollate;
[MarshalAs (UnmanagedType.ByValTStr, SizeConst = cchformname)]
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;
}

[DllImport ("user32.dll", CharSet = CharSet.Auto)]
static extern int changedisplaysettings (DEVMODE lpdevmode, int dwflags);

static extern int ChangeDisplaySettings ([in] ref DEVMODE lpdevmode, int dwflags);
Private System.ComponentModel.Container components = null;
Public Form1 ()
{
InitializeComponent ();
}
protected override void Dispose (bool disposing)
// {
if (disposing)
// {
if (Components!= null)
// {
Components. Dispose ();
// }
// }
Base. Dispose (disposing);
// }

#region Windows Form Designer generated code
private void InitializeComponent ()
// {
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (292, 273);
This. Text = "Example of changing screen resolution";
//
// }
#endregion

static void Main ()
// {
Form1 r = new Form1 ();
R.changeres ();
Application.Run (New Form1 ());
// }

void changeres (int chmode)
{
Form1 t = new Form1 ();
Long RetVal = 0;
DEVMODE dm = new DEVMODE ();
Dm.dmsize = (short) marshal.sizeof (typeof (DEVMODE));
if (Chmode = 1)
{
dm.dmpelswidth = 1600;
Dm.dmpelsheight = 1024;
Dm.dmdisplayfrequency = 85;
}
else if (Chmode = 2)
{
Dm.dmpelswidth = 1024;
Dm.dmpelsheight = 768;
Dm.dmdisplayfrequency = 85;
}
Dm.dmfields = DEVMODE. Dm_pelswidth | DEVMODE. Dm_pelsheight | DEVMODE. dm_displayfrequency;
RetVal = changedisplaysettings (ref DM, 0);
}

private void Form1_Load (object sender, EventArgs e)
{
Changeres (1);
}

private void Form1_formclosing (object sender, FormClosingEventArgs e)
{
Changeres (2);
}
}
}

3, in the Design view of the Windowsstate set to Minimized,showintaskbar set to False

Second, according to the needs of each user to modify the Changeres method in the resolution settings, build the project to put the executable file in this user's Startup folder

Summarize:
The principle of the program is very simple, when the user log in to set the resolution to the user's expectations, the program is always running before the user log out, but users will not be aware, in the user login, the program is terminated, the resolution is set back to a specific value, so as to achieve a unified logon resolution and each user has its own resolution.

Improved:
If you have more users, you can change the screen resolution by program parameters, avoid multiple generation of projects and generate confusion of several versions.

Test Platform:
Windows Server 2003,visual C # 1



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.