日期:2013-03-31  浏览次数:20460 次

在windows下要实现不同用户拥有不同分辨率其实可以自己动手来实现,看看如下实例吧:

首先制作一个能改变屏幕分辨率的C#程序,源代码如下,使用了VS.NET 2005 BETA 1:
1、新建Windows Application工程,取名为ScreenResolution
2、粘贴各文件的代码:
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 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)
// {