Extend Laptop Screen to Two Monitors: HDMI & USB Ports
In today's digital world, having multiple monitors connected to a laptop can significantly boost productivity and enhance the user experience. With advancements in technology, extending a laptop screen to two monitors has become a common practice. In this article, we will discuss how to achieve this using HDMI and USB ports.
Requirements
To extend your laptop screen to two monitors, you will need the following:
- A laptop with HDMI and/or USB ports
- Two external monitors with HDMI or VGA inputs (for USB connections, you may need an adapter)
- HDMI or USB cables (for HDMI connections)
Using HDMI Ports
HDMI (High Definition Multimedia Interface) is a digital interface that supports both audio and video transmission. To extend your laptop screen to two monitors using HDMI ports:
- Connect one monitor to your laptop using an HDMI cable.
- Connect the second monitor to your laptop using an HDMI cable.
- Press the Windows key + P on your keyboard. A pop-up window will appear, displaying the Display settings.
- Select "Extend" from the options to extend your desktop across both monitors.
HDMI Multi-Monitor Setup (Windows 10)
// Code block for Windows 10 settings
const int DISPLAY_CONNECTION_CHANGED_EVENT_SOURCE_ID = 10;
const int WM_DEVICECHANGE = 0x0219;
LPMDS_EXTENDED_MODE_INFO pEDID = null;
MDS_EXTENDED_MODE_INFO_V2 pEDIDv2 = null;
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern IntPtr RegisterDeviceNotification(IntPtr hWnd, DeviceNotification lpfn, int idEventSource);
[DllImport("user32.dll")]
static extern void UnregisterDeviceNotification(IntPtr hDevNot);
[DllImport("setupapi.dll")]
static extern IntPtr SetupDiCallClassInstaller(IntPtr hDevInfo, IntPtr classInstaller, IntPtr hwndParent, int Flags);
[DllImport("setupapi.dll")]
static extern IntPtr SetupDiEnumDeviceInfo(IntPtr hDevInfo, int i, out SP_DEVINFO_DATA pdid);
[DllImport("setupapi.dll")]
static extern IntPtr SetupDiGetClassInstallParams(IntPtr hDevInfo, IntPtr classInstallParams, out SP_CLASSINSTALL_HEADER pClassInstallHeader, int Size);
[DllImport("setupapi.dll")]
static extern IntPtr SetupDiGetDeviceRegistryProperty(IntPtr hDevInfo, IntPtr hDeviceInfo, int PropertyID, IntPtr PropertyType, out IntPtr PropertyData, int Size, IntPtr Reserved);
[DllImport("setupapi.dll")]
static extern IntPtr SetupDiSetClassInstallParams(IntPtr hDevInfo, IntPtr classInstallParams, ref SP_CLASSINSTALL_HEADER pClassInstallHeader);
[DllImport("setupapi.dll")]
static extern IntPtr SetupDiSetClassInstallParams(IntPtr hDevInfo, IntPtr classInstallParams, ref SP_CLASSINSTALL_HEADER pClassInstallHeader);
[StructLayout(LayoutKind.Sequential)]
struct SP_CLASSINSTALL_HEADER
{
SP_CLASSINSTALL_HEADER(int dwSize, int dwFlags, IntPtr hInstaller)
{
this.dwSize = dwSize;
this.dwFlags = dwFlags;
this.hInstaller = hInstaller;
}
int dwSize;
int dwFlags;
IntPtr hInstaller;
}
[StructLayout(LayoutKind.Sequential)]
struct SP_DEVINFO_DATA
{
SP_DEVINFO_DATA(IntPtr hwDevice, int cbSize)
{
this.hwDevice = hwDevice;
this.cbSize = cbSize;
}
IntPtr hwDevice;
int cbSize;
}
[StructLayout(LayoutKind.Sequential)]
struct MDS_EXTENDED_MODE_INFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
string szEDID;
int dwSize;
int dwFlags;
int iEDIDLength;
IntPtr pEDID;
}
[StructLayout(LayoutKind.Sequential)]
struct MDS_EXTENDED_MODE_INFO_V2
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
string szEDID;
int dwSize;
int dwFlags;
int iEDIDLength;
IntPtr pEDID;
IntPtr pEDIDv2;
}
public static void Main()
{
IntPtr hDevInfo = SetupDiGetClassDevs(IntPtr.Zero, "VID_1B14&PID_1024", IntPtr.Zero, 0);
if (hDevInfo == IntPtr.Zero)
{
MessageBox.Show("Error getting device info set.");
return;
}
IntPtr classInstallParams = IntPtr.Zero;
SP_CLASSINSTALL_HEADER classInstallHeader = new SP_CLASSINSTALL_HEADER(Marshal.SizeOf(typeof(SP_CLASSINSTALL_HEADER)), 0, IntPtr.Zero);
SetupDiSetClassInstallParams(hDevInfo, classInstallParams, ref classInstallHeader);
IntPtr hDeviceInfo = IntPtr.Zero;
if (!SetupDiEnumDeviceInfo(hDevInfo, 0, out hDeviceInfo))
{
MessageBox.Show("Error enumerating devices.");
return;
}
IntPtr pClassInstallHeader = IntPtr.Zero;
if (!SetupDiGetClassInstallParams(hDevInfo, hDeviceInfo, out pClassInstallHeader, Marshal.SizeOf(typeof(SP_CLASSINSTALL_HEADER))))
{
MessageBox.Show("Error getting class install params.");
return;
}
IntPtr hInstaller = IntPtr.Zero;
if (!SetupDiCallClassInstaller(hDevInfo, classInstallParams, IntPtr.Zero, DIF_PROPERTYCHANGE))
{
MessageBox.Show("Error installing class.");
return;
}
IntPtr hDevNot = RegisterDeviceNotification(hWnd, DeviceNotificationCallback, DISPLAY_CONNECTION_CHANGED_EVENT_SOURCE_ID);
if (hDevNot == IntPtr.Zero)
{
MessageBox.Show("Error registering device notification.");
return;
}
SetupDiCallClassInstaller(hDevInfo, classInstallParams, IntPtr.Zero, DIF_PROPERTYCHANGE);
UnregisterDeviceNotification(hDevNot);
SetupDiDestroyDeviceInfoList(hDevInfo);
}
Using USB Ports
USB (Universal Serial Bus) is a popular interface for connecting peripherals, including external monitors. To extend your laptop screen to two monitors using USB ports:
- Connect one monitor to your laptop using a USB-to-VGA or USB-to-HDMI adapter.
- Connect the second monitor to your laptop using another USB-to-VGA or USB-to-HDMI adapter.
- Press the Windows key + P on your keyboard. A pop-up window will appear, displaying the Display settings.
- Select "Extend" from the options to extend your desktop across both monitors.
USB Multi-Monitor Setup (Windows 10)
// Code block for USB multi-monitor setup in Windows 10
// (Not provided as the setup process may vary depending on the specific USB-to-DVI/HDMI adapter)
Summary
In conclusion, extending your laptop screen to two monitors using HDMI or USB ports is a straightforward process. By following the steps outlined above, you can enhance your productivity and improve your overall computing experience.