]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/display.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MSW Implementation of wxDisplay class
4 // Author: Royce Mitchell III
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "display.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/dynarray.h"
37 #include "wx/display.h"
39 // the following define is necessary to access the multi-monitor function
40 // declarations in a manner safe to use w/ Windows 95
41 // JACS: not used for now until we're clear about the legality
42 // of distributing multimon.h. Meanwhile you can download the file
44 // http://www.microsoft.com/msj/0697/monitor/monitortextfigs.htm#fig4
47 #define COMPILE_MULTIMON_STUBS
48 #include "wx/msw/multimon.h"
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
57 // ---------------------------------------------------------------------------
59 void wxmswInitDisplayRectArray();
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 class wxmswDisplayInfo
;
67 WX_DECLARE_OBJARRAY(wxmswDisplayInfo
, wxmswDisplayInfoArray
);
69 class wxmswDisplayInfo
78 wxmswDisplayInfoArray
* g_wxmswDisplayInfoArray
= 0;
80 #include <wx/arrimpl.cpp> // this is a magic incantation which must be done!
81 WX_DEFINE_OBJARRAY(wxmswDisplayInfoArray
);
83 // ===========================================================================
85 // ===========================================================================
87 BOOL CALLBACK
wxmswMonitorEnumProc (
88 HMONITOR hMonitor
, // handle to display monitor
89 HDC hdcMonitor
, // handle to monitor-appropriate device context
90 LPRECT lprcMonitor
, // pointer to monitor intersection rectangle
91 LPARAM dwData
// data passed from EnumDisplayMonitors
94 wxmswDisplayInfo
* info
= new wxmswDisplayInfo();
95 info
->m_hmon
= hMonitor
;
96 info
->m_rect
.SetX ( lprcMonitor
->left
);
97 info
->m_rect
.SetY ( lprcMonitor
->top
);
98 info
->m_rect
.SetWidth ( lprcMonitor
->right
- lprcMonitor
->left
);
99 info
->m_rect
.SetHeight ( lprcMonitor
->bottom
- lprcMonitor
->top
);
100 // now add this monitor to the array
101 g_wxmswDisplayInfoArray
->Add ( info
);
103 return TRUE
; // continue the enumeration
106 class wxmswDisplayModule
: public wxModule
108 DECLARE_DYNAMIC_CLASS(wxmswDisplayModule
)
110 wxmswDisplayModule() {}
115 IMPLEMENT_DYNAMIC_CLASS(wxmswDisplayModule
, wxModule
)
117 bool wxmswDisplayModule::OnInit()
119 g_wxmswDisplayInfoArray
= new wxmswDisplayInfoArray();
120 if ( !g_wxmswDisplayInfoArray
)
122 wxFAIL_MSG(wxT("Couldn't allocate array for display information"));
126 // Royce3: I'm assuming that the monitor's are enumerated in the same
127 // order as the calls to EnumDisplayDevices below. We shall soon see
128 // if that assumption is correct.
129 if ( !EnumDisplayMonitors ( NULL
, NULL
, wxmswMonitorEnumProc
, 0 ) )
130 wxLogLastError(wxT("EnumDisplayMonitors"));
132 size_t iDevNum
= 0, count
= g_wxmswDisplayInfoArray
->Count();
133 while ( iDevNum
< count
)
135 wxmswDisplayInfo
& info
= (*g_wxmswDisplayInfoArray
)[iDevNum
];
137 // MSDN: Before calling EnumDisplayDevices, you must initialize the cb
138 // member of DISPLAY_DEVICE to the size, in bytes, of DISPLAY_DEVICE
139 info
.m_dd
.cb
= sizeof(info
.m_dd
);
141 if ( !EnumDisplayDevices ( NULL
, iDevNum
, &info
.m_dd
, 0 ) )
142 wxLogLastError(wxT("EnumDisplayDevices"));
144 // get this display's Depth
146 memset ( &devmode
, 0, sizeof(devmode
) );
148 // MSDN: Before calling EnumDisplaySettings, set the dmSize member to
149 // sizeof(DEVMODE), and set the dmDriverExtra member to indicate the size,
150 // in bytes, of the additional space available to receive private
152 devmode
.dmSize
= sizeof(devmode
);
153 devmode
.dmDriverExtra
= 0;
155 if ( !EnumDisplaySettings ( info
.m_dd
.DeviceName
, ENUM_CURRENT_SETTINGS
, &devmode
) )
157 wxLogLastError(wxT("EnumDisplaySettings"));
158 devmode
.dmFields
= 0;
161 if ( !(devmode
.dmFields
&DM_BITSPERPEL
) )
164 info
.m_depth
= devmode
.dmBitsPerPel
;
172 void wxmswDisplayModule::OnExit()
174 size_t count
= g_wxmswDisplayInfoArray
->Count();
177 wxmswDisplayInfo
* info
= g_wxmswDisplayInfoArray
->Detach ( count
);
180 delete g_wxmswDisplayInfoArray
;
181 g_wxmswDisplayInfoArray
= 0;
184 // ---------------------------------------------------------------------------
186 // ---------------------------------------------------------------------------
188 size_t wxDisplayBase::GetCount()
190 return GetSystemMetrics ( SM_CMONITORS
);
193 int wxDisplayBase::GetFromPoint ( const wxPoint
& pt
)
199 HMONITOR hmon
= MonitorFromPoint ( pt2
, 0 );
202 size_t count
= wxDisplayBase::GetCount(), index
;
204 for ( index
= 0; index
< count
; index
++ )
206 if ( hmon
== (*g_wxmswDisplayInfoArray
)[index
].m_hmon
)
213 wxDisplay::wxDisplay ( size_t index
) : wxDisplayBase ( index
)
217 wxRect
wxDisplay::GetGeometry() const
219 return (*g_wxmswDisplayInfoArray
)[m_index
].m_rect
;
222 int wxDisplay::GetDepth() const
224 return (*g_wxmswDisplayInfoArray
)[m_index
].m_depth
;
227 wxString
wxDisplay::GetName() const
229 return wxString ( (*g_wxmswDisplayInfoArray
)[m_index
].m_dd
.DeviceName
);
232 #endif//wxUSE_DISPLAY