VC implements the Windows method of multi monitor programming

  • 2020-05-05 11:41:27
  • OfStack

This article illustrates how VC implements Windows multi-monitor programming. Share with you for your reference. The details are as follows:

I. when multiple displays are connected in Windows, it can be set to copy and expand the screen.

1. When set to copy the screen, the resolution of multiple monitors is the same, and the position is 0~ resolution value

2, when set to expand the screen, the relationship between the display is more complex. First the Windows system recognizes a main display, which can be changed in the screen resolution. The position relationship between multiple monitors can also be changed in the screen resolution. The position of the main display is from (0,0) to (width,height). The other display positions are determined by the position relation with the main display. At the bottom right, the resolution of the main display plus the length and width. Where the driver or with mouse_event processing is the same, the main display is 0~65535, other displays according to the relative position of the main display.

Ii. Relevant procedures and API are as follows:

1. Get the resolution

of the current display

m_iCurScrWidth = ::GetSystemMetrics(SM_CXSCREEN);
m_iCurScrHeight = ::GetSystemMetrics(SM_CYSCREEN);

2. Move the window location


MoveWindow(0, 0, m_iCurScrWidth, m_iCurScrHeight);
// Move the window 
ModifyStyle(WS_CAPTION,0,0);
// Cancel the title bar 

3. Get the number of monitors

GetSystemMetrics(SM_CMONITORS);

4. Obtain the relative position of the display at the resolution


void GetScreenRect(int ScreenNo)
{
BOOL flag;
DISPLAY_DEVICE dd;
 ZeroMemory(&dd, sizeof(dd));
 dd.cb = sizeof(dd);
flag = EnumDisplayDevices(NULL, ScreenNo, &dd, 0);
if (!flag) return;
DEVMODE dm;
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
flag = EnumDisplaySettings(dd.DeviceName,ENUM_CURRENT_SETTINGS, &dm);
m_ScrRect[ScreenNo].left = dm.dmPosition.x;
m_ScrRect[ScreenNo].top = dm.dmPosition.y;
m_ScrRect[ScreenNo].right = dm.dmPelsWidth;
m_ScrRect[ScreenNo].bottom = dm.dmPelsHeight;
}

I hope that this article has been helpful to your VC programming.


Related articles: