Solved

Multiple display

Posted on 1998-09-05
7
473 Views
Last Modified: 2010-04-06
How can I detect if windows is using multiple display's and
get the information (resolution pixel depth etc).
0
Comment
Question by:rnieuwl
  • 6
7 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1338695
See TScreen type. At run time use Screen variable to retreive screen parameters.
I think it's a new feature for Win98 to work with several screens. Documentation should be available in the MSDN or some new versoin of WIN32S.HLP.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1338696
The EnumDisplayMonitors function enumerates the display monitors that intersect a region formed by the intersection of a specified clipping rectangle
and the visible region of a device context. EnumDisplayMonitors calls an application-defined MonitorEnumProc callback function once for each display
monitor that intersects the region.

BOOL EnumDisplayMonitors (
  HDC hdc,                   // handle to a display device context
  LPCRECT lprcClip,          // specifies a clipping rectangle
  MONITORENUMPROC lpfnEnum,  // pointer to a callback function
  LPARAM dwData              // data passed to the callback function
);
 

Parameters

hdc
     Handle to a display device context that defines the visible region of interest.

     If this parameter is NULL, the hdcMonitor parameter passed to the MonitorEnumProc calls will be NULL, and the visible region of interest is the
     virtual screen that encompasses all the displays on the desktop.
lprcClip
     Pointer to a RECT structure that specifies a clipping rectangle. The region of interest is the intersection of the clipping rectangle with the visible
     region specified by hdc.

     If hdc is non-NULL, the coordinates of the clipping rectangle are relative to the origin of the hdc. If hdc is NULL, the coordinates are virtual screen
     coordinates.

     This parameter can be NULL if you don't want to clip the region specified by hdc.
lpfnEnum
     Pointer to a MonitorEnumProc application-defined callback function.
dwData
     Application-defined data that EnumDisplayMonitors passes directly to the MonitorEnumProc function.

Return Values

If the function succeeds, the return value is nonzero

If the function fails, the return value is zero.

Windows NT: To get extended error information, call GetLastError. .

Remarks

There are two key reasons to call the EnumDisplayMonitors function:

     You want to draw optimally into a device context that spans several display monitors, and the monitors have different color formats.
     You want to obtain a handle and position rectangle for one or more display monitors.

To determine whether all the display monitors in a system share the same color format, call GetSystemMetrics(SM_SAMEDISPLAYFORMAT).

You do not need to use the EnumDisplayMonitors function when a window spans display monitors that have different color formats. You can continue to
paint under the assumption that the entire screen has the color properties of the primary monitor. Your windows will look fine. EnumDisplayMonitors just
lets you make them look better.

Setting the hdc parameter to NULL lets you use the EnumDisplayMonitors function to obtain a handle and position rectangle for one or more display
monitors. The following table shows how the four combinations of NULL and non-NULL hdc and lprcClip values affect the behavior of the
EnumDisplayMonitors function:

 hdc
                                 lprcRect
                                                                 EnumDisplayMonitors Behavior
 NULL
                                 NULL
                                                                 Enumerates all display monitors.

                                                                 The callback function receives a NULL
                                                                 HDC.
 NULL
                                 non-NULL
                                                                 Enumerates all display monitors that
                                                                 intersect the clipping rectangle. Use
                                                                 virtual screen coordinates for the
                                                                 clipping rectangle.

                                                                 The callback function receives a NULL
                                                                 HDC.
 non-NULL
                                 NULL
                                                                 Enumerates all display monitors that
                                                                 intersect the visible region of the device
                                                                 context.

                                                                 The callback function receives a handle
                                                                 to a DC for the specific display monitor.
 non-NULL
                                 non-NULL
                                                                 Enumerates all display monitors that
                                                                 intersect the visible region of the device
                                                                 context and the clipping rectangle. Use
                                                                 device context coordinates for the
                                                                 clipping rectangle.

                                                                 The callback function receives a handle
                                                                 to a DC for the specific display monitor.


Examples

To paint in response to a WM_PAINT message, using the capabilities of each monitor, you can use code like this in a window procedure:

case WM_PAINT:
  hdc = BeginPaint(hwnd, &ps);
  EnumDisplayMonitors(hdc, NULL, MyPaintEnumProc, 0);
  EndPaint(hwnd, &ps);

To paint the top half of a window using the capabilities of each monitor, you can use code like this:

GetClientRect(hwnd, &rc);
rc.bottom = (rc.bottom - rc.top) / 2;
hdc = GetDC(hwnd);
EnumDisplayMonitors(hdc, &rc, MyPaintEnumProc, 0);
ReleaseDC(hwnd, hdc);

To paint the entire virtual screen optimally for each display monitor, you can use code like this:

hdc = GetDC(NULL);
EnumDisplayMonitors(hdc, NULL, MyPaintScreenEnumProc, 0);
ReleaseDC(NULL, hdc);

To get information about all of the display monitors, you can use code like this:

EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, 0);
 

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Requires Windows 98.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1338697
The GetMonitorInfo function lets you obtain information about a display monitor.

BOOL GetMonitorInfo(
  HMONITOR hMonitor,  // handle to display monitor
  LPMONITORINFO lpmi  // pointer to display monitor information
);
 

Parameters

hmonitor
     Handle to the display monitor of interest.
lpmi
     Pointer to a MONITORINFO structure or a MONITORINFOEX structure. The function stores information about the specified display monitor
     in this structure.

     You must set the cbSize member of the structure to sizeof(MONITORINFO) or sizeof(MONITORINFOEX) before calling the GetMonitorInfo
     function. Doing so lets the function determine the type of structure you are passing to it.

     The MONITORINFOEX structure is a superset of the MONITORINFO structure. It has one additional member: a string member, to contain a
     name for the display monitor. Most applications have no use for a display monitor name, and so can save some bytes by using a MONITORINFO
     structure.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Windows NT: To get extended error information, call GetLastError. .

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Requires Windows 98.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 3

Expert Comment

by:Matvey
ID: 1338698
-MSDN.

Delphi 3 doesn't implements this - hope D4 does.

Good luck, Matvey
0
 

Author Comment

by:rnieuwl
ID: 1338699
This helps a lot. But I am still stuck. How do I know on which
display my active form is. I need to change the size according to this.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1338700
Hi, these will help I guess:

The MonitorFromWindow function obtains a handle to the display monitor that has the largest area of intersection with the bounding rectangle of a specified window.

HMONITOR MonitorFromWindow(
  HWND hwnd,       // handle to a window
  DWORD dwFlags    // flags if no monitor intersects the window
);
 

Parameters

hwnd
     Handle to the window of interest.
dwFlags
     A set of flags that determine the function's return value if the window does not intersect any display monitor.

     This parameter can be one of the following values.
     Value
                                                            Meaning
     MONITOR_DEFAULTTONEAREST
                                                            Return a handle to the display monitor that is nearest to the window.
     MONITOR_DEFAULTTONULL
                                                            Return NULL.
     MONITOR_DEFAULTTOPRIMARY
                                                            Return a handle to the primary display monitor.


Return Values

If the window intersects one or more display monitor rectangles, the return value is an HMONITOR handle to the display monitor that has the largest area of intersection with
the window.

If the window does not intersect a display monitor, the return value depends on the value of dwFlags.

Remarks

If the window is currently minimized, MonitorFromWindow uses the rectangle of the window before it was minimized.
0
 
LVL 3

Accepted Solution

by:
Matvey earned 100 total points
ID: 1338701
The MonitorFromPoint function obtains a handle to the display monitor that contains a specified point.

HMONITOR MonitorFromPoint(
  POINT pt,      // a specified point
  DWORD dwFlags  // flags if no monitor contains specified point
);
 

Parameters

pt
     A POINT structure that specifies the point of interest.
dwFlags
     A set of flags that determine the function's return value if the point is not contained within any display monitor.

     This parameter can be one of the following values.
     Value
                                                            Meaning
     MONITOR_DEFAULTTONEAREST
                                                            Return a handle to the display monitor that is nearest to the point.
     MONITOR_DEFAULTTONULL
                                                            Return NULL.
     MONITOR_DEFAULTTOPRIMARY
                                                            Return a handle to the primary display monitor.


Return Values

If the point is contained by a display monitor, the return value is an HMONITOR handle to that display monitor.

If the point is not contained by a display monitor, the return value depends on the value of dwFlags.
________________________________________________________________

The MonitorFromRect function obtains a handle to the display monitor that has the largest area of intersection with a specified rectangle.

HMONITOR MonitorFromRect(
  LPCRECT lprc,    // pointer to a RECT structure
  DWORD dwFlags    // flags if no monitor intersects the rectangle
);
 

Parameters

lprc
     Pointer to a RECT structure that specifies the rectangle of interest.
dwFlags
     A set of flags that determine the function's return value if the rectangle does not intersect any display monitor.

     This parameter can be one of the following values.
     Value
                                                            Meaning
     MONITOR_DEFAULTTONEAREST
                                                            Return a handle to the display monitor that is nearest to the rectangle.
     MONITOR_DEFAULTTONULL
                                                            Return NULL.
     MONITOR_DEFAULTTOPRIMARY
                                                            Return a handle to the primary display monitor.


Return Values

If the rectangle intersects one or more display monitor rectangles, the return value is an HMONITOR handle to the display monitor that has the largest area of intersection with
the rectangle.

If the rectangle does not intersect a display monitor, the return value depends on the value of dwFlags.
________________________________________________________________

Good luck!
--Matvey
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question