Extended my windows desktop onto this monitor

Source: Internet
Author: User

Let's talk about the idea. Here is what we found online.
Use the enumdisplaydevices () API call to enumerate the display devices on the system and look for those that don't have the display_device_attached_to_desktop Flag Set (this will include any devices so not all will be physical displays .) once you 've found the display device you'll need to get a valid display mode to change it to, you can find this by calling the enumdisplaysettingsex () API call-generally you 'd display all the available modes and allow the user to choose however in your case it sounds like this may be possible to hard-code and save you an additional step. for the sake of future-proofing your application though I 'd suggest having this easily changeable without having to dig through the source every time, a registry key wocould be the obvious choice. once you 've got that sorted out populate a devmode display structure with the information about the display positioning (set the pelswidth/height, position, displayfrequency and bitsperpel properties) then set these flags in the fields member. finally call changedisplaysettingsex () with this settings structure and be sure to send the reset and update registry flags. that shoshould be all you need, hope this helps,

The above meaning is not explained.

Solution

Display_device structure import using pinvoke. This is some information about the monitor.

Enumdisplaydevices Function Import can obtain display_device through the display index.

Enumdisplaysettingsex Function Import sets display information

Changedisplaysettingsex extends the desktop to the configured display.

 

# Region code

 

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. diagnostics;
Using system. runtime. interopservices;
Using system. Windows. forms;

Namespace windowssreen
{
Class mulscreen
{
Public const int dm_orientation = 0x00000001;

Public constint dm_papersize = 0x00000002;

Public const int dm_paperlength = 0x00000004;

Public const int dm_paperwidth = 0x00000008;

Public const int dm_scale = 0x00000010;

Public const int dm_position = 0x00000020;

Public const int dm_nup = 0x00000040;

Public constint dm_displayorientation = 0x00000080;

Public const int dm_copies = 0x00000100;

Public const int dm_defaultsource = 0x00000200;

Public const int dm_printquality = 0x00000400;

Public const int dm_color = 0x00000800;

Public const int dm_duplex = 0x00001000;

Public const int dm_yresolution = 0x00002000;

Public const int dm_ttoption = 0x00004000;

Public const int dm_collate = 0x00008000;

Public const int dm_formname = 0x00010000;

Public const int dm_logpixels = 0x00020000;

Public const int dm_bitsperpel = 0x00040000;

Public const int dm_pelswidth = 0x00080000;

Public const int dm_pelsheight = 0x00100000;

Public const int dm_displayflags = 0x00200000;

Public const int dm_displayfrequency = 0x00400000;

Public const int dm_icmmethod = 0x00800000;

Public const int dm_icmintent = 0x01000000;

Public const int dm_mediatype = 0x02000000;

Public const int dm_dithertype = 0x04000000;

Public const int dm_panningwidth = 0x08000000;

Public const int dm_panningheight = 0x10000000;

Public const int dm_displayfixedoutput = 0x20000000;

Const uint ewx_force = 4;
Const uint display_device_attached_to_desktop = 1;
[Dllimport ("user32.dll")]
Static extern bool enumdisplaydevices (string lpdevice, uint idevnum,
Ref display_device lpdisplaydevice, uint dwflags );

[Dllimport ("user32.dll")]
Static extern int changedisplaysettingsex (string lpszdevicename,
Ref devmode lpdevmode, intptr hwnd, uint dwflags, intptr lparam );
[Dllimport ("user32.dll")]
Public static extern int enumdisplaysettings (
String devicename, int modenum, ref devmode );
Public struct display_device
{
[Financialas (unmanagedtype. U4)]
Public int CB;

[Financialas (unmanagedtype. byvaltstr, sizeconst = 32)]
Public String devicename;

[Financialas (unmanagedtype. byvaltstr, sizeconst = 128)]
Public String devicestring;

[Financialas (unmanagedtype. U4)]
Public uint stateflags;

[Financialas (unmanagedtype. byvaltstr, sizeconst = 128)]
Public String DeviceID;

[managed Alas (unmanagedtype. byvaltstr, sizeconst = 128)]
Public String devicekey;
}< br> [structlayout (layoutkind. sequential)]
public struct devmode
{< br> Public const int cchdevicename = 32;
Public const int cchformname = 32;

[managed Alas (unmanagedtype. byvaltstr, sizeconst = cchdevicename)]
Public String dmdevicename;
Public short dmspecversion;
Public short dmdriverversion;
Public short dmsize;
Public short dmdriverextra;
Public int dmfields;

Public short dmorientation;
Public short dmpapersize;
Public short dmpaperlength;
Public short dmpaperwidth;

Public short dmscale;
Public short dmcopies;
Public short dmdefaultsource;
Public short dmprintquality;
Public short dmcolor;
Public short dmduplex;
Public short dmyresolution;
Public short dmttoption;
Public short dmcollate;
[Financialas (unmanagedtype. byvaltstr, sizeconst = cchformname)]
Public String dmformname;
Public short dmlogpixels;
Public int dmbitsperpel; // declared wrong in the full Framework
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;

Public int dmpositionx; // using a pointl struct does not work
Public int dmpositiony;

}

Public void MUL ()
{
Display_device d = new display_device ();
Devmode dm = new devmode ();
D. cb = marshal. sizeof (d );
Int DeviceID = 1; // This is only for my device setting. Go through the whole enumdisplaydevices to find your device
Enumdisplaydevices (null, (uint) DeviceID, ref D, 0 );//
Enumdisplaysettings (D. devicename, 0, ref DM );
DM. dmpelswidth = 1024;
DM. dmpelsheight = 768;
DM. dmpositionx = screen. primaryscreen. bounds. Right;
DM. dmfields = dm_position | dm_pelswidth | dm_pelsheight;
Changedisplaysettingsex (D. devicename, ref DM, intptr. Zero, display_device_attached_to_desktop, intptr. Zero );


}

}
}

 

# Endregon

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.