MultiMonitor


Quick Data

Header file:multi_monitor.h
Object name:fMULTIMONITOR
Object index:1 of 1 Objects

General Description

The MultiMonitor class is used to determine what physical monitors are attached to the system. Naturally, though, this only works on Windows 98 or better, or Windows 2000 and better. The reason for this restriction is that Windows 95 and Windows NT did not have support for multiple monitors.

You need not worry about including this in a program that is to be run on a Win95/NT system. This class dynamically loads the required functions, and if they are not found, then you will get a FALSE from the Initialise() function. If you do get a FALSE from this, please, please, don't use any of the other functions!

A global object with the name MultiMonitors is always created when this file is included. Thanks to Microsofts nice way of including support for multiple monitors, it is impossible to have this any other way, without a lot more coding.


Methods


Prototype Description

bool Initialise(void); This function loads the appropriate DLL and obtains the dynamic function pointers. Call this before you call any other functions. If your operating system supports these functions, the function will return TRUE. Otherwise, it will return FALSE. Please do not use any other function if this one returns FALSE.
bool UnInitialise(void); This function unloads the DLL and cleans up any extra memory. You should call this when you are finished.
void EnumerateMonitors(int MaxNumMonitors); This function allows the class to collect information on all the monitors attached to the system. MaxNumMonitors is the maximum number of monitors to enumerate. Once this function returns, you can use the following functions to obtain information about the monitors attached to the system.
int GetNumberMonitors(void); This function returns the number of monitors that were enumerated with the above function.
RECT GetMonitorRect(int NumMonitor); This function returns a RECT structure of the specified monitor. NumMonitor starts at Zero. The rectangle coordinates are the "virtual screen" co-ordinates of the monitor. For example, if you have a secondary monitor to the right of your primary monitor, Left might be 1280, top might be 0, bottom might be 768, and right might be 2304. This means that the second monitor starts at (1280,0) and is 1024x768. Likewise, if left is a negative value, then the second monitor is to the left of the primary monitor.
HMONITOR GetMonitorHandle(int NumMonitor); This function returns the handle to the specified monitor. NumMonitor starts at Zero.

Sample Code

The following snippet gives a basic idea of how to use this component.


if (MultiMonitors.Initialise())
   {
   //Go - enumerate!
   MultiMonitors.EnumerateMonitors(20);
   //Spout the details...
   RECT R;
   for (int TempX = 0; TempX < MultiMonitors.GetNumberMonitors(); TempX++)
       {
       R = MultiMonitors.GetMonitorRect(TempX);
       // R.left and R.top indicate the start location, eg. (1280,0)
       // R.right-R.left and R.bottom-R.top indicate width and height.
       }
   MultiMonitors.UnInitialise(); //This also frees the DLL - so don't call any more functions!
   } else {
   MessageBox(NULL, "MultiMonitor Init failed. You probably don't have the OS support required.", "MMSupport", 0);
   }

Back to indexThe FreeFoote Foundation Classes Documentation