]> git.saurik.com Git - wxWidgets.git/blob - src/msw/display.cpp
Moved GetDefaultAttributes outside wxUSE_RICHEDIT block
[wxWidgets.git] / src / msw / display.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: display.cpp
3 // Purpose: MSW Implementation of wxDisplay class
4 // Author: Royce Mitchell III
5 // Modified by: VZ (resolutions enumeration/change support, DirectDraw, ...)
6 // Ryan Norton (IsPrimary override)
7 // Created: 06/21/02
8 // RCS-ID: $Id$
9 // Copyright: (c) wxWidgets team
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // ===========================================================================
14 // declarations
15 // ===========================================================================
16
17 // ---------------------------------------------------------------------------
18 // headers
19 // ---------------------------------------------------------------------------
20
21 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
22 #pragma implementation "display.h"
23 #endif
24
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
27
28 #ifdef __BORLANDC__
29 #pragma hdrstop
30 #endif
31
32 #if wxUSE_DISPLAY
33
34 #ifndef WX_PRECOMP
35 #include "wx/app.h"
36 #include "wx/dynarray.h"
37 #include "wx/frame.h"
38 #endif
39
40 #include "wx/dynload.h"
41
42 #include "wx/display.h"
43
44 // the following define is necessary to access the multi-monitor function
45 // declarations in a manner safe to use w/ Windows 95
46 #define COMPILE_MULTIMON_STUBS
47
48 // if you don't have multimon.h you can download the file from:
49 //
50 // http://www.microsoft.com/msj/0697/monitor/monitortextfigs.htm#fig4
51 //
52
53 #ifdef _MSC_VER
54 // as (m)any standard header(s), this one doesn't compile without warnings
55 // with VC++ 6 <sigh>
56 #pragma warning(disable:4706)
57 #endif
58
59 #include <multimon.h>
60
61 #ifdef _MSC_VER
62 #pragma warning(default:4706)
63 #endif
64
65 #include <ddraw.h>
66
67 // we don't want to link with ddraw.lib which contains the real
68 // IID_IDirectDraw2 definition
69 const GUID wxIID_IDirectDraw2 =
70 { 0xB3A6F3E0, 0x2B43, 0x11CF, { 0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 } };
71
72 // ----------------------------------------------------------------------------
73 // macros
74 // ----------------------------------------------------------------------------
75
76 #ifdef _UNICODE
77 #define WINFUNC(x) _T(#x) L"W"
78 #else
79 #define WINFUNC(x) #x "A"
80 #endif
81
82 // ----------------------------------------------------------------------------
83 // typedefs for dynamically loaded Windows functions
84 // ----------------------------------------------------------------------------
85
86 typedef LONG (WINAPI *ChangeDisplaySettingsEx_t)(LPCTSTR lpszDeviceName,
87 LPDEVMODE lpDevMode,
88 HWND hwnd,
89 DWORD dwFlags,
90 LPVOID lParam);
91
92 typedef BOOL (PASCAL *DDEnumExCallback_t)(GUID *pGuid,
93 LPTSTR driverDescription,
94 LPTSTR driverName,
95 LPVOID lpContext,
96 HMONITOR hmon);
97
98 typedef HRESULT (WINAPI *DirectDrawEnumerateEx_t)(DDEnumExCallback_t lpCallback,
99 LPVOID lpContext,
100 DWORD dwFlags);
101
102 typedef HRESULT (WINAPI *DirectDrawCreate_t)(GUID *lpGUID,
103 LPDIRECTDRAW *lplpDD,
104 IUnknown *pUnkOuter);
105
106 // ----------------------------------------------------------------------------
107 // private classes
108 // ----------------------------------------------------------------------------
109
110 class wxDisplayInfo
111 {
112 public:
113 // handle of this monitor used by MonitorXXX() functions, never NULL
114 HMONITOR m_hmon;
115
116 // IDirectDraw object used to control this display, may be NULL
117 IDirectDraw2 *m_pDD2;
118
119 // DirectDraw GUID for this display, only valid when using DirectDraw
120 GUID m_guid;
121
122 // the entire area of this monitor in virtual screen coordinates
123 wxRect m_rect;
124
125 // the display device name for this monitor, empty initially and retrieved
126 // on demand by DoGetName()
127 wxString m_devName;
128
129 wxDisplayInfo() { m_hmon = NULL; m_pDD2 = NULL; }
130 ~wxDisplayInfo() { if ( m_pDD2 ) m_pDD2->Release(); }
131 };
132
133 WX_DECLARE_OBJARRAY(wxDisplayInfo, wxDisplayInfoArray);
134 #include "wx/arrimpl.cpp"
135 WX_DEFINE_OBJARRAY(wxDisplayInfoArray);
136
137 // this module is used to cleanup gs_displays array
138 class wxDisplayModule : public wxModule
139 {
140 public:
141 virtual bool OnInit() { return true; }
142 virtual void OnExit();
143
144 DECLARE_DYNAMIC_CLASS(wxDisplayModule)
145 };
146
147 IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
148
149 // ----------------------------------------------------------------------------
150 // globals
151 // ----------------------------------------------------------------------------
152
153 // do we use DirectX?
154 static bool gs_useDirectX = false;
155
156 // dynamically resolved DirectDrawCreate()
157 static DirectDrawCreate_t gs_DirectDrawCreate = NULL;
158
159 // this is not really MT-unsafe as wxDisplay is only going to be used from the
160 // main thread, i.e. we consider that it's a GUI class and so don't protect it
161 static wxDisplayInfoArray *gs_displays = NULL;
162
163 // ===========================================================================
164 // implementation
165 // ===========================================================================
166
167 // ----------------------------------------------------------------------------
168 // callbacks for monitor/modes enumeration stuff
169 // ----------------------------------------------------------------------------
170
171 static BOOL CALLBACK wxmswMonitorEnumProc (
172 HMONITOR hMonitor, // handle to display monitor
173 HDC WXUNUSED(hdcMonitor), // handle to monitor-appropriate device context
174 LPRECT lprcMonitor, // pointer to monitor intersection rectangle
175 LPARAM WXUNUSED(dwData) // data passed from EnumDisplayMonitors (unused)
176 )
177 {
178 wxDisplayInfo *info = new wxDisplayInfo();
179
180 // we need hMonitor to be able to map display id to it which is needed for
181 // MonitorXXX() functions, in particular MonitorFromPoint()
182 info->m_hmon = hMonitor;
183
184 // we also store the display geometry
185 info->m_rect.SetX ( lprcMonitor->left );
186 info->m_rect.SetY ( lprcMonitor->top );
187 info->m_rect.SetWidth ( lprcMonitor->right - lprcMonitor->left );
188 info->m_rect.SetHeight ( lprcMonitor->bottom - lprcMonitor->top );
189
190 // now add this monitor to the array
191 gs_displays->Add(info);
192
193 // continue the enumeration
194 return true;
195 }
196
197 BOOL PASCAL
198 wxDDEnumExCallback(GUID *pGuid,
199 LPTSTR WXUNUSED(driverDescription),
200 LPTSTR driverName,
201 LPVOID WXUNUSED(lpContext),
202 HMONITOR hmon)
203 {
204 if ( pGuid )
205 {
206 wxDisplayInfo *info = new wxDisplayInfo();
207
208 info->m_hmon = hmon;
209 info->m_guid = *pGuid;
210 info->m_devName = driverName;
211
212 gs_displays->Add(info);
213 }
214 //else: we're called for the primary monitor, skip it
215
216 // continue the enumeration
217 return true;
218 }
219
220 HRESULT WINAPI wxDDEnumModesCallback(LPDDSURFACEDESC lpDDSurfaceDesc,
221 LPVOID lpContext)
222 {
223 // we need at least the mode size
224 static const DWORD FLAGS_REQUIRED = DDSD_HEIGHT | DDSD_WIDTH;
225 if ( (lpDDSurfaceDesc->dwFlags & FLAGS_REQUIRED) == FLAGS_REQUIRED )
226 {
227 wxArrayVideoModes * const modes = (wxArrayVideoModes *)lpContext;
228
229 modes->Add(wxVideoMode(lpDDSurfaceDesc->dwWidth,
230 lpDDSurfaceDesc->dwHeight,
231 lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount,
232 lpDDSurfaceDesc->dwRefreshRate));
233 }
234
235 // continue the enumeration
236 return DDENUMRET_OK;
237 }
238
239 // ----------------------------------------------------------------------------
240 // local functions
241 // ----------------------------------------------------------------------------
242
243 // initialize gs_displays using DirectX functions
244 static bool DoInitDirectX()
245 {
246 #if wxUSE_LOG
247 // suppress the errors if ddraw.dll is not found
248 wxLog::EnableLogging(false);
249 #endif
250
251 wxDynamicLibrary dllDX(_T("ddraw.dll"));
252
253 #if wxUSE_LOG
254 wxLog::EnableLogging();
255 #endif
256
257 if ( !dllDX.IsLoaded() )
258 return false;
259
260 DirectDrawEnumerateEx_t pDDEnumEx = (DirectDrawEnumerateEx_t)
261 dllDX.GetSymbol(WINFUNC(DirectDrawEnumerateEx));
262 if ( !pDDEnumEx )
263 return false;
264
265 // we'll also need DirectDrawCreate() later, resolve it right now
266 gs_DirectDrawCreate = (DirectDrawCreate_t)
267 dllDX.GetSymbol(_T("DirectDrawCreate"));
268 if ( !gs_DirectDrawCreate )
269 return false;
270
271 if ( (*pDDEnumEx)(wxDDEnumExCallback,
272 NULL,
273 DDENUM_ATTACHEDSECONDARYDEVICES) != DD_OK )
274 {
275 return false;
276 }
277
278 // ok, it seems like we're going to use DirectDraw and so we're going to
279 // need ddraw.dll all the time, don't unload it
280 dllDX.Detach();
281
282 return true;
283 }
284
285 // initialize gs_displays using the standard Windows functions
286 static void DoInitStdWindows()
287 {
288 // enumerate all displays
289 if ( !::EnumDisplayMonitors(NULL, NULL, wxmswMonitorEnumProc, 0) )
290 {
291 wxLogLastError(wxT("EnumDisplayMonitors"));
292
293 // TODO: still create at least one (valid) entry in gs_displays for the
294 // primary display!
295 }
296 }
297
298 // this function must be called before accessing gs_displays array as it
299 // creates and initializes it
300 static void InitDisplays()
301 {
302 if ( gs_displays )
303 return;
304
305 gs_displays = new wxDisplayInfoArray();
306
307 if ( !gs_useDirectX || !DoInitDirectX() )
308 {
309 // either we were told not to try to use DirectX or fall back to std
310 // functions if DirectX method failed
311 gs_useDirectX = false;
312
313 DoInitStdWindows();
314 }
315 }
316
317 // convert a DEVMODE to our wxVideoMode
318 wxVideoMode ConvertToVideoMode(const DEVMODE& dm)
319 {
320 // note that dmDisplayFrequency may be 0 or 1 meaning "standard one" and
321 // although 0 is ok for us we don't want to return modes with 1hz refresh
322 return wxVideoMode(dm.dmPelsWidth,
323 dm.dmPelsHeight,
324 dm.dmBitsPerPel,
325 dm.dmDisplayFrequency > 1 ? dm.dmDisplayFrequency : 0);
326 }
327
328 // emulation of ChangeDisplaySettingsEx() for Win95
329 LONG WINAPI ChangeDisplaySettingsExForWin95(LPCTSTR WXUNUSED(lpszDeviceName),
330 LPDEVMODE lpDevMode,
331 HWND WXUNUSED(hwnd),
332 DWORD dwFlags,
333 LPVOID WXUNUSED(lParam))
334 {
335 return ::ChangeDisplaySettings(lpDevMode, dwFlags);
336 }
337
338 // ----------------------------------------------------------------------------
339 // wxDisplayModule
340 // ----------------------------------------------------------------------------
341
342 void wxDisplayModule::OnExit()
343 {
344 delete gs_displays;
345 }
346
347 // ---------------------------------------------------------------------------
348 // wxDisplay
349 // ---------------------------------------------------------------------------
350
351 /* static */
352 void wxDisplay::UseDirectX(bool useDX)
353 {
354 wxCHECK_RET( !gs_displays, _T("it is too late to call UseDirectX") );
355
356 gs_useDirectX = useDX;
357 }
358
359 // helper of GetFromPoint() and GetFromWindow()
360 static int DisplayFromHMONITOR(HMONITOR hmon)
361 {
362 if ( hmon )
363 {
364 const size_t count = wxDisplay::GetCount();
365
366 for ( size_t n = 0; n < count; n++ )
367 {
368 if ( hmon == (*gs_displays)[n].m_hmon )
369 return n;
370 }
371 }
372
373 return wxNOT_FOUND;
374 }
375
376 /* static */
377 size_t wxDisplayBase::GetCount()
378 {
379 InitDisplays();
380
381 // I'm not sure if they really always return the same thing and if this is
382 // not true I'd like to know in which situation does it happen
383 wxASSERT_MSG( gs_displays->GetCount() == (size_t)::GetSystemMetrics(SM_CMONITORS),
384 _T("So how many displays does this system have?") );
385
386 return gs_displays->GetCount();
387 }
388
389 /* static */
390 int wxDisplayBase::GetFromPoint ( const wxPoint& pt )
391 {
392 POINT pt2;
393 pt2.x = pt.x;
394 pt2.y = pt.y;
395
396 return DisplayFromHMONITOR(::MonitorFromPoint(pt2, MONITOR_DEFAULTTONULL));
397 }
398
399 /* static */
400 int wxDisplayBase::GetFromWindow(wxWindow *window)
401 {
402 return DisplayFromHMONITOR
403 (
404 ::MonitorFromWindow(GetHwndOf(window), MONITOR_DEFAULTTONULL)
405 );
406 }
407
408 // ----------------------------------------------------------------------------
409 // wxDisplay ctor/dtor
410 // ----------------------------------------------------------------------------
411
412 wxDisplay::wxDisplay ( size_t n )
413 : wxDisplayBase ( n )
414 {
415 // if we do this in ctor we won't have to call it from all the member
416 // functions
417 InitDisplays();
418
419 if ( gs_useDirectX )
420 {
421 wxDisplayInfo& dpyInfo = (*gs_displays)[n];
422
423 LPDIRECTDRAW2& pDD2 = dpyInfo.m_pDD2;
424 if ( !pDD2 )
425 {
426 if ( !gs_DirectDrawCreate )
427 {
428 // what to do??
429 return;
430 }
431
432 IDirectDraw *pDD;
433 HRESULT hr = (*gs_DirectDrawCreate)(&dpyInfo.m_guid, &pDD, NULL);
434
435 if ( FAILED(hr) || !pDD )
436 {
437 // what to do??
438 wxLogApiError(_T("DirectDrawCreate"), hr);
439 }
440 else // got IDirectDraw, we want IDirectDraw2
441 {
442 hr = pDD->QueryInterface(wxIID_IDirectDraw2, (void **)&pDD2);
443 if ( FAILED(hr) || !pDD2 )
444 {
445 wxLogApiError(_T("IDirectDraw::QueryInterface(IDD2)"), hr);
446 }
447
448 pDD->Release();
449 }
450 }
451 //else: DirectDraw object corresponding to our display already exists
452
453 // increment its ref count to account for Release() in dtor
454 //
455 // NB: pDD2 will be only really Release()d when gs_displays is
456 // destroyed which is ok as we don't want to recreate DD objects
457 // all the time
458 pDD2->AddRef();
459 }
460 }
461
462 wxDisplay::~wxDisplay()
463 {
464 wxDisplayInfo& dpyInfo = (*gs_displays)[m_index];
465
466 LPDIRECTDRAW2& pDD2 = dpyInfo.m_pDD2;
467 if ( pDD2 )
468 {
469 pDD2->Release();
470 }
471 }
472
473 // ----------------------------------------------------------------------------
474 // wxDisplay simple accessors
475 // ----------------------------------------------------------------------------
476
477 bool wxDisplay::IsOk() const
478 {
479 return m_index < GetCount() &&
480 (!gs_useDirectX || (*gs_displays)[m_index].m_pDD2);
481 }
482
483 wxRect wxDisplay::GetGeometry() const
484 {
485 wxDisplayInfo& dpyInfo = (*gs_displays)[m_index];
486 wxRect& rect = dpyInfo.m_rect;
487 if ( !rect.width )
488 {
489 MONITORINFO monInfo;
490 wxZeroMemory(monInfo);
491 monInfo.cbSize = sizeof(monInfo);
492
493 if ( !::GetMonitorInfo(dpyInfo.m_hmon, &monInfo) )
494 {
495 wxLogLastError(_T("GetMonitorInfo"));
496 }
497 else
498 {
499 wxCopyRECTToRect(monInfo.rcMonitor, rect);
500 }
501 }
502
503 return rect;
504 }
505
506 wxString wxDisplay::GetName() const
507 {
508 wxDisplayInfo& dpyInfo = (*gs_displays)[m_index];
509 if ( dpyInfo.m_devName.empty() )
510 {
511 MONITORINFOEX monInfo;
512 wxZeroMemory(monInfo);
513 monInfo.cbSize = sizeof(monInfo);
514
515 // NB: Cast from MONITORINFOEX* to MONITORINFO* is done because
516 // Mingw headers - unlike the ones from Microsoft's Platform SDK -
517 // don't derive the former from the latter in C++ mode and so
518 // the pointer's type is not converted implicitly.
519 if ( !::GetMonitorInfo(dpyInfo.m_hmon, (LPMONITORINFO)&monInfo) )
520 {
521 wxLogLastError(_T("GetMonitorInfo"));
522 }
523 else
524 {
525 dpyInfo.m_devName = monInfo.szDevice;
526 }
527 }
528
529 return dpyInfo.m_devName;
530 }
531
532 wxString wxDisplay::GetNameForEnumSettings() const
533 {
534 int major, minor;
535 const bool isWin95 = wxGetOsVersion(&major, &minor) == wxWIN95 &&
536 major == 4 && minor == 0;
537
538 // the first parameter of EnumDisplaySettings() must be NULL under Win95
539 // according to MSDN but GetMonitorInfo() stub in multimon.h still returns
540 // something even in this case, so we have to correct this manually
541 wxString name;
542 if ( !isWin95 )
543 name = GetName();
544
545 return name;
546 }
547
548 // ----------------------------------------------------------------------------
549 // determine if this is the primary display
550 // ----------------------------------------------------------------------------
551
552 bool wxDisplay::IsPrimary() const
553 {
554 wxDisplayInfo& dpyInfo = (*gs_displays)[m_index];
555
556 MONITORINFOEX monInfo;
557 wxZeroMemory(monInfo);
558 monInfo.cbSize = sizeof(monInfo);
559
560 // NB: Cast from MONITORINFOEX* to MONITORINFO* is done because
561 // Mingw headers - unlike the ones from Microsoft's Platform SDK -
562 // don't derive the former from the latter in C++ mode and so
563 // the pointer's type is not converted implicitly.
564 if ( !::GetMonitorInfo(dpyInfo.m_hmon, (LPMONITORINFO)&monInfo) )
565 {
566 wxLogLastError(_T("GetMonitorInfo"));
567 }
568
569 return (monInfo.dwFlags & MONITORINFOF_PRIMARY) == MONITORINFOF_PRIMARY;
570 }
571
572 // ----------------------------------------------------------------------------
573 // video modes enumeration
574 // ----------------------------------------------------------------------------
575
576 wxArrayVideoModes
577 wxDisplay::DoGetModesDirectX(const wxVideoMode& WXUNUSED(modeMatch)) const
578 {
579 wxArrayVideoModes modes;
580
581 IDirectDraw2 *pDD = (*gs_displays)[m_index].m_pDD2;
582
583 if ( pDD )
584 {
585 HRESULT hr = pDD->EnumDisplayModes
586 (
587 DDEDM_REFRESHRATES,
588 NULL, // all modes (TODO: use modeMatch!)
589 &modes, // callback parameter
590 wxDDEnumModesCallback
591 );
592
593 if ( FAILED(hr) )
594 {
595 wxLogApiError(_T("IDirectDraw::EnumDisplayModes"), hr);
596 }
597 }
598
599 return modes;
600 }
601
602 wxArrayVideoModes
603 wxDisplay::DoGetModesWindows(const wxVideoMode& modeMatch) const
604 {
605 wxArrayVideoModes modes;
606
607 const wxString name = GetNameForEnumSettings();
608
609 const wxChar * const deviceName = name.empty() ? NULL : name.c_str();
610
611 DEVMODE dm;
612 for ( int iModeNum = 0;
613 ::EnumDisplaySettings(deviceName, iModeNum, &dm);
614 iModeNum++ )
615 {
616 const wxVideoMode mode = ConvertToVideoMode(dm);
617 if ( mode.Matches(modeMatch) )
618 {
619 modes.Add(mode);
620 }
621 }
622
623 return modes;
624 }
625
626 wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& modeMatch) const
627 {
628 return gs_useDirectX ? DoGetModesDirectX(modeMatch)
629 : DoGetModesWindows(modeMatch);
630 }
631
632 wxVideoMode wxDisplay::GetCurrentMode() const
633 {
634 wxVideoMode mode;
635
636 const wxString name = GetNameForEnumSettings();
637
638 DEVMODE dm;
639 if ( !::EnumDisplaySettings(name.empty() ? NULL : name.c_str(),
640 ENUM_CURRENT_SETTINGS,
641 &dm) )
642 {
643 wxLogLastError(_T("EnumDisplaySettings(ENUM_CURRENT_SETTINGS)"));
644 }
645 else
646 {
647 mode = ConvertToVideoMode(dm);
648 }
649
650 return mode;
651 }
652
653 // ----------------------------------------------------------------------------
654 // video mode switching
655 // ----------------------------------------------------------------------------
656
657 bool wxDisplay::DoChangeModeDirectX(const wxVideoMode& mode)
658 {
659 IDirectDraw2 *pDD = (*gs_displays)[m_index].m_pDD2;
660 if ( !pDD )
661 return false;
662
663 wxWindow *winTop = wxTheApp->GetTopWindow();
664 wxCHECK_MSG( winTop, false, _T("top level window required for DirectX") );
665
666 HRESULT hr = pDD->SetCooperativeLevel
667 (
668 GetHwndOf(winTop),
669 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN
670 );
671 if ( FAILED(hr) )
672 {
673 wxLogApiError(_T("IDirectDraw::SetCooperativeLevel"), hr);
674
675 return false;
676 }
677
678 hr = pDD->SetDisplayMode(mode.w, mode.h, mode.bpp, mode.refresh, 0);
679 if ( FAILED(hr) )
680 {
681 wxLogApiError(_T("IDirectDraw::SetDisplayMode"), hr);
682
683 return false;
684 }
685
686
687 return true;
688 }
689
690 bool wxDisplay::DoChangeModeWindows(const wxVideoMode& mode)
691 {
692 // prepare ChangeDisplaySettingsEx() parameters
693 DEVMODE dm,
694 *pDevMode;
695 int flags;
696
697 if ( mode == wxDefaultVideoMode )
698 {
699 // reset the video mode to default
700 pDevMode = NULL;
701 flags = 0;
702 }
703 else // change to the given mode
704 {
705 wxCHECK_MSG( mode.w && mode.h, false,
706 _T("at least the width and height must be specified") );
707
708 wxZeroMemory(dm);
709 dm.dmSize = sizeof(dm);
710 dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
711 dm.dmPelsWidth = mode.w;
712 dm.dmPelsHeight = mode.h;
713
714 if ( mode.bpp )
715 {
716 dm.dmFields |= DM_BITSPERPEL;
717 dm.dmBitsPerPel = mode.bpp;
718 }
719
720 if ( mode.refresh )
721 {
722 dm.dmFields |= DM_DISPLAYFREQUENCY;
723 dm.dmDisplayFrequency = mode.refresh;
724 }
725
726 pDevMode = &dm;
727
728 flags = CDS_FULLSCREEN;
729 }
730
731
732 // get pointer to the function dynamically
733 //
734 // we're only called from the main thread, so it's ok to use static
735 // variable
736 static ChangeDisplaySettingsEx_t pfnChangeDisplaySettingsEx = NULL;
737 if ( !pfnChangeDisplaySettingsEx )
738 {
739 wxDynamicLibrary dllUser32(_T("user32.dll"));
740 if ( dllUser32.IsLoaded() )
741 {
742 pfnChangeDisplaySettingsEx = (ChangeDisplaySettingsEx_t)
743 dllUser32.GetSymbol(WINFUNC(ChangeDisplaySettingsEx));
744 }
745 //else: huh, no user32.dll??
746
747 if ( !pfnChangeDisplaySettingsEx )
748 {
749 // we must be under Win95 and so there is no multiple monitors
750 // support anyhow
751 pfnChangeDisplaySettingsEx = ChangeDisplaySettingsExForWin95;
752 }
753 }
754
755 // do change the mode
756 switch ( pfnChangeDisplaySettingsEx
757 (
758 GetName(), // display name
759 pDevMode, // dev mode or NULL to reset
760 NULL, // reserved
761 flags,
762 NULL // pointer to video parameters (not used)
763 ) )
764 {
765 case DISP_CHANGE_SUCCESSFUL:
766 // ok
767 {
768 // If we have a top-level, full-screen frame, emulate
769 // the DirectX behavior and resize it. This makes this
770 // API quite a bit easier to use.
771 wxWindow *winTop = wxTheApp->GetTopWindow();
772 wxFrame *frameTop = wxDynamicCast(winTop, wxFrame);
773 if (frameTop && frameTop->IsFullScreen())
774 {
775 wxVideoMode current = GetCurrentMode();
776 frameTop->SetClientSize(current.w, current.h);
777 }
778 }
779 return true;
780
781 case DISP_CHANGE_BADMODE:
782 // don't complain about this, this is the only "expected" error
783 break;
784
785 default:
786 wxFAIL_MSG( _T("unexpected ChangeDisplaySettingsEx() return value") );
787 }
788
789 return false;
790 }
791
792 bool wxDisplay::ChangeMode(const wxVideoMode& mode)
793 {
794 return gs_useDirectX ? DoChangeModeDirectX(mode)
795 : DoChangeModeWindows(mode);
796 }
797
798 #endif // wxUSE_DISPLAY
799