10

I'm trying to figure out a way to know if the user is using multiple monitors.

I would like to know how to do this in native C++ (using the Win32 API) and with managed code (using the .NET Framework).

Thanks in advance

1
  • some very elegant Linq code in C# here by Rob Fonseca-Ensor which will calculate the bounds of all current screens in use : stackoverflow.com/questions/2176648/… Commented Feb 8, 2010 at 7:56

4 Answers 4

12

I can give you C# .NET:

if (Screen.AllScreens.Length > 1)
{
    // Multiple monitors
}

Edit: A search on Google turned up the following. It mentions 98/ME so it might no be relevant but may point you in the right direction:

There are new APIs for handling multiple monitors in Windows 98. The APIs used in the monitors class sample are GetMonitorInfo, MonitorFromWindow and MonitorFromRect.

The GetSystemMetrics API has some new constants (see below) that can be used to determine the metrics of a multiple monitor system. The GetSystemMetrics API returns information about the Windows environment. This API can be used to determine how many monitors are on the system, whether they are set at the same display format, and the size of the virtual desktop.

http://support.microsoft.com/kb/194578

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Both answers were accurate. I was able to get the number of monitors using the GetSystemMetrics function passing as argument the SM_CMONITORS constant.
6

GetSystemMetrics with SM_CMONITORS and off you go...

2 Comments

Had a feeling it was GetSystemMetrics.
Using three monitors on a daily basis I needed to learn this fast ;>
6

In .NET it's as simple as using the Screen.AllScreens.Length property. Not too sure about C++ though.

Comments

2

Just to document here the C/C++ solution:

int iMonitors = GetSystemMetrics(SM_MONITORS); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.