]> git.saurik.com Git - wxWidgets.git/blob - src/msw/toplevel.cpp
Add support for large stdio files for VC 8+. What versions of the other Windows
[wxWidgets.git] / src / msw / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for MSW
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 24.09.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/toplevel.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/dialog.h"
32 #include "wx/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #include "wx/frame.h"
36 #include "wx/containr.h" // wxSetFocusToChild()
37 #include "wx/module.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/dynlib.h"
41
42 #include "wx/msw/private.h"
43 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
44 #include <ole2.h>
45 #include <shellapi.h>
46 // Standard SDK doesn't have aygshell.dll: see include/wx/msw/wince/libraries.h
47 #if _WIN32_WCE < 400 || !defined(__WINCE_STANDARDSDK__)
48 #include <aygshell.h>
49 #endif
50 #endif
51
52 #include "wx/msw/winundef.h"
53 #include "wx/msw/missing.h"
54
55 #include "wx/display.h"
56
57 #ifndef ICON_BIG
58 #define ICON_BIG 1
59 #endif
60
61 #ifndef ICON_SMALL
62 #define ICON_SMALL 0
63 #endif
64
65 // ----------------------------------------------------------------------------
66 // stubs for missing functions under MicroWindows
67 // ----------------------------------------------------------------------------
68
69 #ifdef __WXMICROWIN__
70
71 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return false; }
72 static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return false; }
73
74 #endif // __WXMICROWIN__
75
76 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
77 // is not included by wxUniv build which does need wxDlgProc
78 LONG APIENTRY _EXPORT
79 wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
80
81 // ----------------------------------------------------------------------------
82 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
83 // module to ensure that the window is always deleted)
84 // ----------------------------------------------------------------------------
85
86 class wxTLWHiddenParentModule : public wxModule
87 {
88 public:
89 // module init/finalize
90 virtual bool OnInit();
91 virtual void OnExit();
92
93 // get the hidden window (creates on demand)
94 static HWND GetHWND();
95
96 private:
97 // the HWND of the hidden parent
98 static HWND ms_hwnd;
99
100 // the class used to create it
101 static const wxChar *ms_className;
102
103 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule)
104 };
105
106 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule)
107
108 // ============================================================================
109 // wxTopLevelWindowMSW implementation
110 // ============================================================================
111
112 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW, wxTopLevelWindowBase)
113 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate)
114 END_EVENT_TABLE()
115
116 // ----------------------------------------------------------------------------
117 // wxTopLevelWindowMSW creation
118 // ----------------------------------------------------------------------------
119
120 void wxTopLevelWindowMSW::Init()
121 {
122 m_iconized =
123 m_maximizeOnShow = false;
124
125 // Data to save/restore when calling ShowFullScreen
126 m_fsStyle = 0;
127 m_fsOldWindowStyle = 0;
128 m_fsIsMaximized = false;
129 m_fsIsShowing = false;
130
131 m_winLastFocused = NULL;
132
133 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
134 m_MenuBarHWND = 0;
135 #endif
136
137 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
138 SHACTIVATEINFO* info = new SHACTIVATEINFO;
139 wxZeroMemory(*info);
140 info->cbSize = sizeof(SHACTIVATEINFO);
141
142 m_activateInfo = (void*) info;
143 #endif
144 }
145
146 WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
147 {
148 // let the base class deal with the common styles but fix the ones which
149 // don't make sense for us (we also deal with the borders ourselves)
150 WXDWORD msflags = wxWindow::MSWGetStyle
151 (
152 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags
153 ) & ~WS_CHILD & ~WS_VISIBLE;
154
155 // For some reason, WS_VISIBLE needs to be defined on creation for
156 // SmartPhone 2003. The title can fail to be displayed otherwise.
157 #if defined(__SMARTPHONE__) || (defined(__WXWINCE__) && _WIN32_WCE < 400)
158 msflags |= WS_VISIBLE;
159 ((wxTopLevelWindowMSW*)this)->wxWindowBase::Show(true);
160 #endif
161
162 // first select the kind of window being created
163 //
164 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
165 // creates a window with both caption and border, hence we need to use
166 // WS_POPUP in a few cases just to avoid having caption/border which we
167 // don't want
168
169 // border and caption styles
170 if ( ( style & wxRESIZE_BORDER ) && !IsAlwaysMaximized())
171 msflags |= WS_THICKFRAME;
172 else if ( exflags && ((style & wxBORDER_DOUBLE) || (style & wxBORDER_RAISED)) )
173 *exflags |= WS_EX_DLGMODALFRAME;
174 else if ( !(style & wxBORDER_NONE) )
175 msflags |= WS_BORDER;
176 #ifndef __POCKETPC__
177 else
178 msflags |= WS_POPUP;
179 #endif
180
181 // normally we consider that all windows without a caption must be popups,
182 // but CE is an exception: there windows normally do not have the caption
183 // but shouldn't be made popups as popups can't have menus and don't look
184 // like normal windows anyhow
185
186 // TODO: Smartphone appears to like wxCAPTION, but we should check that
187 // we need it.
188 #if defined(__SMARTPHONE__) || !defined(__WXWINCE__)
189 if ( style & wxCAPTION )
190 msflags |= WS_CAPTION;
191 #ifndef __WXWINCE__
192 else
193 msflags |= WS_POPUP;
194 #endif // !__WXWINCE__
195 #endif
196
197 // next translate the individual flags
198
199 // WS_EX_CONTEXTHELP is incompatible with WS_MINIMIZEBOX and WS_MAXIMIZEBOX
200 // and is ignored if we specify both of them, but chances are that if we
201 // use wxWS_EX_CONTEXTHELP, we really do want to have the context help
202 // button while wxMINIMIZE/wxMAXIMIZE are included by default, so the help
203 // takes precedence
204 if ( !(GetExtraStyle() & wxWS_EX_CONTEXTHELP) )
205 {
206 if ( style & wxMINIMIZE_BOX )
207 msflags |= WS_MINIMIZEBOX;
208 if ( style & wxMAXIMIZE_BOX )
209 msflags |= WS_MAXIMIZEBOX;
210 }
211
212 #ifndef __WXWINCE__
213 // notice that if wxCLOSE_BOX is specified we need to use WS_SYSMENU too as
214 // otherwise the close box doesn't appear
215 if ( style & (wxSYSTEM_MENU | wxCLOSE_BOX) )
216 msflags |= WS_SYSMENU;
217 #endif // !__WXWINCE__
218
219 // NB: under CE these 2 styles are not supported currently, we should
220 // call Minimize()/Maximize() "manually" if we want to support them
221 if ( style & wxMINIMIZE )
222 msflags |= WS_MINIMIZE;
223
224 if ( style & wxMAXIMIZE )
225 msflags |= WS_MAXIMIZE;
226
227 // Keep this here because it saves recoding this function in wxTinyFrame
228 if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) )
229 msflags |= WS_CAPTION;
230
231 if ( exflags )
232 {
233 // there is no taskbar under CE, so omit all this
234 #if !defined(__WXWINCE__)
235 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) )
236 {
237 if ( style & wxFRAME_TOOL_WINDOW )
238 {
239 // create the palette-like window
240 *exflags |= WS_EX_TOOLWINDOW;
241
242 // tool windows shouldn't appear on the taskbar (as documented)
243 style |= wxFRAME_NO_TASKBAR;
244 }
245
246 // We have to solve 2 different problems here:
247 //
248 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
249 // taskbar even if they don't have a parent
250 //
251 // 2. frames without this style should appear in the taskbar even
252 // if they're owned (Windows only puts non owned windows into
253 // the taskbar normally)
254 //
255 // The second one is solved here by using WS_EX_APPWINDOW flag, the
256 // first one is dealt with in our MSWGetParent() method
257 // implementation
258 if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() )
259 {
260 // need to force the frame to appear in the taskbar
261 *exflags |= WS_EX_APPWINDOW;
262 }
263 //else: nothing to do [here]
264 }
265
266 if ( GetExtraStyle() & wxWS_EX_CONTEXTHELP )
267 *exflags |= WS_EX_CONTEXTHELP;
268 #endif // !__WXWINCE__
269
270 if ( style & wxSTAY_ON_TOP )
271 *exflags |= WS_EX_TOPMOST;
272 }
273
274 return msflags;
275 }
276
277 WXHWND wxTopLevelWindowMSW::MSWGetParent() const
278 {
279 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
280 // parent HWND or it would be always on top of its parent which is not what
281 // we usually want (in fact, we only want it for frames with the
282 // wxFRAME_FLOAT_ON_PARENT flag)
283 HWND hwndParent = NULL;
284 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
285 {
286 const wxWindow *parent = GetParent();
287
288 if ( !parent )
289 {
290 // this flag doesn't make sense then and will be ignored
291 wxFAIL_MSG( wxT("wxFRAME_FLOAT_ON_PARENT but no parent?") );
292 }
293 else
294 {
295 hwndParent = GetHwndOf(parent);
296 }
297 }
298 //else: don't float on parent, must not be owned
299
300 // now deal with the 2nd taskbar-related problem (see comments above in
301 // MSWGetStyle())
302 if ( HasFlag(wxFRAME_NO_TASKBAR) && !hwndParent )
303 {
304 // use hidden parent
305 hwndParent = wxTLWHiddenParentModule::GetHWND();
306 }
307
308 return (WXHWND)hwndParent;
309 }
310
311 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
312 bool wxTopLevelWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam)
313 {
314 SHACTIVATEINFO *info = (SHACTIVATEINFO*) m_activateInfo;
315 if ( info )
316 {
317 SHHandleWMSettingChange(GetHwnd(), wParam, lParam, info);
318 }
319
320 return wxWindowMSW::HandleSettingChange(wParam, lParam);
321 }
322 #endif
323
324 WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
325 {
326 WXLRESULT rc = 0;
327 bool processed = false;
328
329 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
330 switch ( message )
331 {
332 case WM_ACTIVATE:
333 {
334 SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo;
335 if (info)
336 {
337 DWORD flags = 0;
338 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) flags = SHA_INPUTDIALOG;
339 SHHandleWMActivate(GetHwnd(), wParam, lParam, info, flags);
340 }
341
342 // This implicitly sends a wxEVT_ACTIVATE_APP event
343 if (wxTheApp)
344 wxTheApp->SetActive(wParam != 0, FindFocus());
345
346 break;
347 }
348 case WM_HIBERNATE:
349 {
350 if (wxTheApp)
351 {
352 wxActivateEvent event(wxEVT_HIBERNATE, true, wxID_ANY);
353 event.SetEventObject(wxTheApp);
354 processed = wxTheApp->ProcessEvent(event);
355 }
356 break;
357 }
358 }
359 #endif
360
361 if ( !processed )
362 rc = wxTopLevelWindowBase::MSWWindowProc(message, wParam, lParam);
363
364 return rc;
365 }
366
367 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate,
368 const wxString& title,
369 const wxPoint& pos,
370 const wxSize& size)
371 {
372 #ifdef __WXMICROWIN__
373 // no dialogs support under MicroWin yet
374 return CreateFrame(title, pos, size);
375 #else // !__WXMICROWIN__
376 // static cast is valid as we're only ever called for dialogs
377 wxWindow * const
378 parent = static_cast<wxDialog *>(this)->
379 GetParentForModalDialog(GetParent());
380
381 m_hWnd = (WXHWND)::CreateDialogIndirect
382 (
383 wxGetInstance(),
384 (DLGTEMPLATE*)dlgTemplate,
385 parent ? GetHwndOf(parent) : NULL,
386 (DLGPROC)wxDlgProc
387 );
388
389 if ( !m_hWnd )
390 {
391 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
392
393 wxLogSysError(wxT("Can't create dialog using memory template"));
394
395 return false;
396 }
397
398 #if !defined(__WXWINCE__)
399 // For some reason, the system menu is activated when we use the
400 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
401 if ( HasExtraStyle(wxWS_EX_CONTEXTHELP) )
402 {
403 wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
404 if ( winTop )
405 {
406 wxIcon icon = winTop->GetIcon();
407 if ( icon.Ok() )
408 {
409 ::SendMessage(GetHwnd(), WM_SETICON,
410 (WPARAM)TRUE,
411 (LPARAM)GetHiconOf(icon));
412 }
413 }
414 }
415 #endif // !__WXWINCE__
416
417 // move the dialog to its initial position without forcing repainting
418 int x, y, w, h;
419 (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
420
421 if ( x == (int)CW_USEDEFAULT )
422 {
423 // centre it on the screen - what else can we do?
424 wxSize sizeDpy = wxGetDisplaySize();
425
426 x = (sizeDpy.x - w) / 2;
427 y = (sizeDpy.y - h) / 2;
428 }
429
430 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
431 if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) )
432 {
433 wxLogLastError(wxT("MoveWindow"));
434 }
435 #endif
436
437 if ( !title.empty() )
438 {
439 ::SetWindowText(GetHwnd(), title.wx_str());
440 }
441
442 SubclassWin(m_hWnd);
443
444 #ifdef __SMARTPHONE__
445 // Work around title non-display glitch
446 Show(false);
447 #endif
448
449 return true;
450 #endif // __WXMICROWIN__/!__WXMICROWIN__
451 }
452
453 bool wxTopLevelWindowMSW::CreateFrame(const wxString& title,
454 const wxPoint& pos,
455 const wxSize& size)
456 {
457 WXDWORD exflags;
458 WXDWORD flags = MSWGetCreateWindowFlags(&exflags);
459
460 const wxSize sz = IsAlwaysMaximized() ? wxDefaultSize : size;
461
462 #ifndef __WXWINCE__
463 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
464 exflags |= WS_EX_LAYOUTRTL;
465 #endif
466
467 return MSWCreate(MSWGetRegisteredClassName(),
468 title.wx_str(), pos, sz, flags, exflags);
469 }
470
471 bool wxTopLevelWindowMSW::Create(wxWindow *parent,
472 wxWindowID id,
473 const wxString& title,
474 const wxPoint& pos,
475 const wxSize& size,
476 long style,
477 const wxString& name)
478 {
479 wxSize sizeReal = size;
480 if ( !sizeReal.IsFullySpecified() )
481 {
482 sizeReal.SetDefaults(GetDefaultSize());
483 }
484
485 bool ret = CreateBase(parent, id, pos, sizeReal, style, name);
486 if ( !ret )
487 return false;
488
489 wxTopLevelWindows.Append(this);
490
491 if ( parent )
492 parent->AddChild(this);
493
494 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
495 {
496 // we have different dialog templates to allows creation of dialogs
497 // with & without captions under MSWindows, resizeable or not (but a
498 // resizeable dialog always has caption - otherwise it would look too
499 // strange)
500
501 // we need 3 additional WORDs for dialog menu, class and title (as we
502 // don't use DS_SETFONT we don't need the fourth WORD for the font)
503 static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3);
504 DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize);
505 memset(dlgTemplate, 0, dlgsize);
506
507 // these values are arbitrary, they won't be used normally anyhow
508 dlgTemplate->x = 34;
509 dlgTemplate->y = 22;
510 dlgTemplate->cx = 144;
511 dlgTemplate->cy = 75;
512
513 // reuse the code in MSWGetStyle() but correct the results slightly for
514 // the dialog
515 //
516 // NB: we need a temporary variable as we can't pass pointer to
517 // dwExtendedStyle directly, it's not aligned correctly for 64 bit
518 // architectures
519 WXDWORD dwExtendedStyle;
520 dlgTemplate->style = MSWGetStyle(style, &dwExtendedStyle);
521 dlgTemplate->dwExtendedStyle = dwExtendedStyle;
522
523 // all dialogs are popups
524 dlgTemplate->style |= WS_POPUP;
525
526 #ifndef __WXWINCE__
527 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
528 {
529 dlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL;
530 }
531
532 // force 3D-look if necessary, it looks impossibly ugly otherwise
533 if ( style & (wxRESIZE_BORDER | wxCAPTION) )
534 dlgTemplate->style |= DS_MODALFRAME;
535 #endif
536
537 ret = CreateDialog(dlgTemplate, title, pos, sizeReal);
538 free(dlgTemplate);
539 }
540 else // !dialog
541 {
542 ret = CreateFrame(title, pos, sizeReal);
543 }
544
545 #ifndef __WXWINCE__
546 if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) )
547 {
548 EnableCloseButton(false);
549 }
550 #endif
551
552 // for standard dialogs the dialog manager generates WM_CHANGEUISTATE
553 // itself but for custom windows we have to do it ourselves in order to
554 // make the keyboard indicators (such as underlines for accelerators and
555 // focus rectangles) work under Win2k+
556 if ( ret )
557 {
558 MSWUpdateUIState(UIS_INITIALIZE);
559 }
560
561 // Note: if we include PocketPC in this test, dialogs can fail to show up,
562 // for example the text entry dialog in the dialogs sample. Problem with Maximise()?
563 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__))
564 if ( ( style & wxMAXIMIZE ) || IsAlwaysMaximized() )
565 {
566 this->Maximize();
567 }
568 #endif
569
570 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
571 SetRightMenu(); // to nothing for initialization
572 #endif
573
574 return ret;
575 }
576
577 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
578 {
579 SendDestroyEvent();
580
581 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
582 SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo;
583 delete info;
584 m_activateInfo = NULL;
585 #endif
586
587 // after destroying an owned window, Windows activates the next top level
588 // window in Z order but it may be different from our owner (to reproduce
589 // this simply Alt-TAB to another application and back before closing the
590 // owned frame) whereas we always want to yield activation to our parent
591 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
592 {
593 wxWindow *parent = GetParent();
594 if ( parent )
595 {
596 ::BringWindowToTop(GetHwndOf(parent));
597 }
598 }
599 }
600
601 // ----------------------------------------------------------------------------
602 // wxTopLevelWindowMSW showing
603 // ----------------------------------------------------------------------------
604
605 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd)
606 {
607 ::ShowWindow(GetHwnd(), nShowCmd);
608
609 m_iconized = nShowCmd == SW_MINIMIZE;
610 }
611
612 void wxTopLevelWindowMSW::ShowWithoutActivating()
613 {
614 if ( !wxWindowBase::Show(true) )
615 return;
616
617 DoShowWindow(SW_SHOWNA);
618 }
619
620 bool wxTopLevelWindowMSW::Show(bool show)
621 {
622 // don't use wxWindow version as we want to call DoShowWindow() ourselves
623 if ( !wxWindowBase::Show(show) )
624 return false;
625
626 int nShowCmd;
627 if ( show )
628 {
629 if ( m_maximizeOnShow )
630 {
631 // show and maximize
632 nShowCmd = SW_MAXIMIZE;
633
634 // This is necessary, or no window appears
635 #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__)
636 DoShowWindow(SW_SHOW);
637 #endif
638
639 m_maximizeOnShow = false;
640 }
641 else if ( m_iconized )
642 {
643 // iconize and show
644 nShowCmd = SW_MINIMIZE;
645 }
646 else // just show
647 {
648 // we shouldn't use SW_SHOW which also activates the window for
649 // tool frames (as they shouldn't steal focus from the main window)
650 // nor for the currently disabled windows as they would be enabled
651 // as a side effect
652 if ( HasFlag(wxFRAME_TOOL_WINDOW) || !IsEnabled() )
653 nShowCmd = SW_SHOWNA;
654 else
655 nShowCmd = SW_SHOW;
656 }
657 }
658 else // hide
659 {
660 nShowCmd = SW_HIDE;
661 }
662
663 DoShowWindow(nShowCmd);
664
665 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
666 // Addornments have to be added when the frame is the correct size
667 wxFrame* frame = wxDynamicCast(this, wxFrame);
668 if (frame && frame->GetMenuBar())
669 frame->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
670 #endif
671
672 // we only set pending size if we're maximized before being shown, now that
673 // we're shown we don't need it any more (it is reset in size event handler
674 // for child windows but we have to do it ourselves for this parent window)
675 m_pendingSize = wxDefaultSize;
676
677 return true;
678 }
679
680 // ----------------------------------------------------------------------------
681 // wxTopLevelWindowMSW maximize/minimize
682 // ----------------------------------------------------------------------------
683
684 void wxTopLevelWindowMSW::Maximize(bool maximize)
685 {
686 if ( IsShown() )
687 {
688 // just maximize it directly
689 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
690 }
691 else // hidden
692 {
693 // we can't maximize the hidden frame because it shows it as well,
694 // so just remember that we should do it later in this case
695 m_maximizeOnShow = maximize;
696
697 // after calling Maximize() the client code expects to get the frame
698 // "real" size and doesn't want to know that, because of implementation
699 // details, the frame isn't really maximized yet but will be only once
700 // it's shown, so return our size as it will be then in this case
701 if ( maximize )
702 {
703 // we must only change pending size here, and not call SetSize()
704 // because otherwise Windows would think that this (full screen)
705 // size is the natural size for the frame and so would use it when
706 // the user clicks on "restore" title bar button instead of the
707 // correct initial frame size
708 //
709 // NB: unfortunately we don't know which display we're on yet so we
710 // have to use the default one
711 m_pendingSize = wxGetClientDisplayRect().GetSize();
712 }
713 //else: can't do anything in this case, we don't have the old size
714 }
715 }
716
717 bool wxTopLevelWindowMSW::IsMaximized() const
718 {
719 return IsAlwaysMaximized() ||
720 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) && !defined(__WINCE_STANDARDSDK__)
721
722 (::IsZoomed(GetHwnd()) != 0) ||
723 #endif
724 m_maximizeOnShow;
725 }
726
727 void wxTopLevelWindowMSW::Iconize(bool iconize)
728 {
729 if ( IsShown() )
730 {
731 // change the window state immediately
732 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
733 }
734 else // hidden
735 {
736 // iconizing the window shouldn't show it so just remember that we need
737 // to become iconized when shown later
738 m_iconized = true;
739 }
740 }
741
742 bool wxTopLevelWindowMSW::IsIconized() const
743 {
744 #ifdef __WXWINCE__
745 return false;
746 #else
747 if ( !IsShown() )
748 return m_iconized;
749
750 // don't use m_iconized, it may be briefly out of sync with the real state
751 // as it's only modified when we receive a WM_SIZE and we could be called
752 // from an event handler from one of the messages we receive before it,
753 // such as WM_MOVE
754 return ::IsIconic(GetHwnd()) != 0;
755 #endif
756 }
757
758 void wxTopLevelWindowMSW::Restore()
759 {
760 DoShowWindow(SW_RESTORE);
761 }
762
763 void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
764 {
765 if ( dir == wxLayout_Default )
766 dir = wxTheApp->GetLayoutDirection();
767
768 if ( dir != wxLayout_Default )
769 wxTopLevelWindowBase::SetLayoutDirection(dir);
770 }
771
772 // ----------------------------------------------------------------------------
773 // wxTopLevelWindowMSW geometry
774 // ----------------------------------------------------------------------------
775
776 #ifndef __WXWINCE__
777
778 void wxTopLevelWindowMSW::DoGetPosition(int *x, int *y) const
779 {
780 if ( IsIconized() )
781 {
782 WINDOWPLACEMENT wp;
783 wp.length = sizeof(WINDOWPLACEMENT);
784 if ( ::GetWindowPlacement(GetHwnd(), &wp) )
785 {
786 RECT& rc = wp.rcNormalPosition;
787
788 // the position returned by GetWindowPlacement() is in workspace
789 // coordinates except for windows with WS_EX_TOOLWINDOW style
790 if ( !HasFlag(wxFRAME_TOOL_WINDOW) )
791 {
792 // we must use the correct display for the translation as the
793 // task bar might be shown on one display but not the other one
794 int n = wxDisplay::GetFromWindow(this);
795 wxDisplay dpy(n == wxNOT_FOUND ? 0 : n);
796 const wxPoint ptOfs = dpy.GetClientArea().GetPosition() -
797 dpy.GetGeometry().GetPosition();
798
799 rc.left += ptOfs.x;
800 rc.top += ptOfs.y;
801 }
802
803 if ( x )
804 *x = rc.left;
805 if ( y )
806 *y = rc.top;
807
808 return;
809 }
810
811 wxLogLastError(wxT("GetWindowPlacement"));
812 }
813 //else: normal case
814
815 wxTopLevelWindowBase::DoGetPosition(x, y);
816 }
817
818 void wxTopLevelWindowMSW::DoGetSize(int *width, int *height) const
819 {
820 if ( IsIconized() )
821 {
822 WINDOWPLACEMENT wp;
823 wp.length = sizeof(WINDOWPLACEMENT);
824 if ( ::GetWindowPlacement(GetHwnd(), &wp) )
825 {
826 const RECT& rc = wp.rcNormalPosition;
827
828 if ( width )
829 *width = rc.right - rc.left;
830 if ( height )
831 *height = rc.bottom - rc.top;
832
833 return;
834 }
835
836 wxLogLastError(wxT("GetWindowPlacement"));
837 }
838 //else: normal case
839
840 wxTopLevelWindowBase::DoGetSize(width, height);
841 }
842
843 #endif // __WXWINCE__
844
845 // ----------------------------------------------------------------------------
846 // wxTopLevelWindowMSW fullscreen
847 // ----------------------------------------------------------------------------
848
849 bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style)
850 {
851 if ( show == IsFullScreen() )
852 {
853 // nothing to do
854 return true;
855 }
856
857 m_fsIsShowing = show;
858
859 if ( show )
860 {
861 m_fsStyle = style;
862
863 // zap the frame borders
864
865 // save the 'normal' window style
866 m_fsOldWindowStyle = GetWindowLong(GetHwnd(), GWL_STYLE);
867
868 // save the old position, width & height, maximize state
869 m_fsOldSize = GetRect();
870 m_fsIsMaximized = IsMaximized();
871
872 // decide which window style flags to turn off
873 LONG newStyle = m_fsOldWindowStyle;
874 LONG offFlags = 0;
875
876 if (style & wxFULLSCREEN_NOBORDER)
877 {
878 offFlags |= WS_BORDER;
879 #ifndef __WXWINCE__
880 offFlags |= WS_THICKFRAME;
881 #endif
882 }
883 if (style & wxFULLSCREEN_NOCAPTION)
884 offFlags |= WS_CAPTION | WS_SYSMENU;
885
886 newStyle &= ~offFlags;
887
888 // change our window style to be compatible with full-screen mode
889 ::SetWindowLong(GetHwnd(), GWL_STYLE, newStyle);
890
891 wxRect rect;
892 #if wxUSE_DISPLAY
893 // resize to the size of the display containing us
894 int dpy = wxDisplay::GetFromWindow(this);
895 if ( dpy != wxNOT_FOUND )
896 {
897 rect = wxDisplay(dpy).GetGeometry();
898 }
899 else // fall back to the main desktop
900 #endif // wxUSE_DISPLAY
901 {
902 // resize to the size of the desktop
903 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect);
904 #ifdef __WXWINCE__
905 // FIXME: size of the bottom menu (toolbar)
906 // should be taken in account
907 rect.height += rect.y;
908 rect.y = 0;
909 #endif
910 }
911
912 SetSize(rect);
913
914 // now flush the window style cache and actually go full-screen
915 long flags = SWP_FRAMECHANGED;
916
917 // showing the frame full screen should also show it if it's still
918 // hidden
919 if ( !IsShown() )
920 {
921 // don't call wxWindow version to avoid flicker from calling
922 // ::ShowWindow() -- we're going to show the window at the correct
923 // location directly below -- but do call the wxWindowBase version
924 // to sync the internal m_isShown flag
925 wxWindowBase::Show();
926
927 flags |= SWP_SHOWWINDOW;
928 }
929
930 SetWindowPos(GetHwnd(), HWND_TOP,
931 rect.x, rect.y, rect.width, rect.height,
932 flags);
933
934 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
935 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON);
936 #endif
937
938 // finally send an event allowing the window to relayout itself &c
939 wxSizeEvent event(rect.GetSize(), GetId());
940 HandleWindowEvent(event);
941 }
942 else // stop showing full screen
943 {
944 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
945 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON);
946 #endif
947 Maximize(m_fsIsMaximized);
948 SetWindowLong(GetHwnd(),GWL_STYLE, m_fsOldWindowStyle);
949 SetWindowPos(GetHwnd(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
950 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
951 }
952
953 return true;
954 }
955
956 // ----------------------------------------------------------------------------
957 // wxTopLevelWindowMSW misc
958 // ----------------------------------------------------------------------------
959
960 void wxTopLevelWindowMSW::SetTitle( const wxString& title)
961 {
962 SetLabel(title);
963 }
964
965 wxString wxTopLevelWindowMSW::GetTitle() const
966 {
967 return GetLabel();
968 }
969
970 bool wxTopLevelWindowMSW::DoSelectAndSetIcon(const wxIconBundle& icons,
971 int smX,
972 int smY,
973 int i)
974 {
975 const wxSize size(::GetSystemMetrics(smX), ::GetSystemMetrics(smY));
976
977 const wxIcon icon = icons.GetIconOfExactSize(size);
978 if ( icon.Ok() )
979 {
980 ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon));
981 return true;
982 }
983
984 return false;
985 }
986
987 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons)
988 {
989 wxTopLevelWindowBase::SetIcons(icons);
990
991 if ( icons.IsEmpty() )
992 {
993 // FIXME: SetIcons(wxNullIconBundle) should unset existing icons,
994 // but we currently don't do that
995 wxASSERT_MSG( m_icons.IsEmpty(), "unsetting icons doesn't work" );
996 return;
997 }
998
999 bool anySet =
1000 DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL);
1001 if ( DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG) )
1002 anySet = true;
1003
1004 if ( !anySet )
1005 {
1006 wxFAIL_MSG( "icon bundle doesn't contain any suitable icon" );
1007 }
1008 }
1009
1010 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)
1011 {
1012 #if !defined(__WXMICROWIN__)
1013 // get system (a.k.a. window) menu
1014 HMENU hmenu = GetSystemMenu(GetHwnd(), FALSE /* get it */);
1015 if ( !hmenu )
1016 {
1017 // no system menu at all -- ok if we want to remove the close button
1018 // anyhow, but bad if we want to show it
1019 return !enable;
1020 }
1021
1022 // enabling/disabling the close item from it also automatically
1023 // disables/enables the close title bar button
1024 if ( ::EnableMenuItem(hmenu, SC_CLOSE,
1025 MF_BYCOMMAND |
1026 (enable ? MF_ENABLED : MF_GRAYED)) == -1 )
1027 {
1028 wxLogLastError(wxT("EnableMenuItem(SC_CLOSE)"));
1029
1030 return false;
1031 }
1032 #ifndef __WXWINCE__
1033 // update appearance immediately
1034 if ( !::DrawMenuBar(GetHwnd()) )
1035 {
1036 wxLogLastError(wxT("DrawMenuBar"));
1037 }
1038 #endif
1039 #endif // !__WXMICROWIN__
1040
1041 return true;
1042 }
1043
1044 #ifndef __WXWINCE__
1045
1046 bool wxTopLevelWindowMSW::SetShape(const wxRegion& region)
1047 {
1048 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
1049 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
1050
1051 // The empty region signifies that the shape should be removed from the
1052 // window.
1053 if ( region.IsEmpty() )
1054 {
1055 if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
1056 {
1057 wxLogLastError(wxT("SetWindowRgn"));
1058 return false;
1059 }
1060 return true;
1061 }
1062
1063 // Windows takes ownership of the region, so
1064 // we'll have to make a copy of the region to give to it.
1065 DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
1066 RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
1067 ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
1068 HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
1069 delete[] (char*) rgnData;
1070
1071 // SetWindowRgn expects the region to be in coordinants
1072 // relative to the window, not the client area. Figure
1073 // out the offset, if any.
1074 RECT rect;
1075 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
1076 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1077 ::GetClientRect(GetHwnd(), &rect);
1078 ::AdjustWindowRectEx(&rect, dwStyle, ::GetMenu(GetHwnd()) != NULL, dwExStyle);
1079 ::OffsetRgn(hrgn, -rect.left, -rect.top);
1080
1081 // Now call the shape API with the new region.
1082 if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
1083 {
1084 wxLogLastError(wxT("SetWindowRgn"));
1085 return false;
1086 }
1087 return true;
1088 }
1089
1090 #endif // !__WXWINCE__
1091
1092 void wxTopLevelWindowMSW::RequestUserAttention(int flags)
1093 {
1094 // check if we can use FlashWindowEx(): unfortunately a simple test for
1095 // FLASHW_STOP doesn't work because MSVC6 headers do #define it but don't
1096 // provide FlashWindowEx() declaration, so try to detect whether we have
1097 // real headers for WINVER 0x0500 by checking for existence of a symbol not
1098 // declated in MSVC6 header
1099 #if defined(FLASHW_STOP) && defined(VK_XBUTTON1) && wxUSE_DYNLIB_CLASS
1100 // available in the headers, check if it is supported by the system
1101 typedef BOOL (WINAPI *FlashWindowEx_t)(FLASHWINFO *pfwi);
1102 static FlashWindowEx_t s_pfnFlashWindowEx = NULL;
1103 if ( !s_pfnFlashWindowEx )
1104 {
1105 wxDynamicLibrary dllUser32(wxT("user32.dll"));
1106 s_pfnFlashWindowEx = (FlashWindowEx_t)
1107 dllUser32.GetSymbol(wxT("FlashWindowEx"));
1108
1109 // we can safely unload user32.dll here, it's going to remain loaded as
1110 // long as the program is running anyhow
1111 }
1112
1113 if ( s_pfnFlashWindowEx )
1114 {
1115 WinStruct<FLASHWINFO> fwi;
1116 fwi.hwnd = GetHwnd();
1117 fwi.dwFlags = FLASHW_ALL;
1118 if ( flags & wxUSER_ATTENTION_INFO )
1119 {
1120 // just flash a few times
1121 fwi.uCount = 3;
1122 }
1123 else // wxUSER_ATTENTION_ERROR
1124 {
1125 // flash until the user notices it
1126 fwi.dwFlags |= FLASHW_TIMERNOFG;
1127 }
1128
1129 s_pfnFlashWindowEx(&fwi);
1130 }
1131 else // FlashWindowEx() not available
1132 #endif // FlashWindowEx() defined
1133 {
1134 wxUnusedVar(flags);
1135 #ifndef __WXWINCE__
1136 ::FlashWindow(GetHwnd(), TRUE);
1137 #endif // __WXWINCE__
1138 }
1139 }
1140
1141 // ---------------------------------------------------------------------------
1142
1143 bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha)
1144 {
1145 #if wxUSE_DYNLIB_CLASS
1146 typedef DWORD (WINAPI *PSETLAYEREDWINDOWATTR)(HWND, DWORD, BYTE, DWORD);
1147 static PSETLAYEREDWINDOWATTR
1148 pSetLayeredWindowAttributes = (PSETLAYEREDWINDOWATTR)-1;
1149
1150 if ( pSetLayeredWindowAttributes == (PSETLAYEREDWINDOWATTR)-1 )
1151 {
1152 wxDynamicLibrary dllUser32(wxT("user32.dll"));
1153
1154 // use RawGetSymbol() and not GetSymbol() to avoid error messages under
1155 // Windows 95: there is nothing the user can do about this anyhow
1156 pSetLayeredWindowAttributes = (PSETLAYEREDWINDOWATTR)
1157 dllUser32.RawGetSymbol(wxT("SetLayeredWindowAttributes"));
1158
1159 // it's ok to destroy dllUser32 here, we link statically to user32.dll
1160 // anyhow so it won't be unloaded
1161 }
1162
1163 if ( !pSetLayeredWindowAttributes )
1164 return false;
1165 #endif // wxUSE_DYNLIB_CLASS
1166
1167 LONG exstyle = GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1168
1169 // if setting alpha to fully opaque then turn off the layered style
1170 if (alpha == 255)
1171 {
1172 SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle & ~WS_EX_LAYERED);
1173 Refresh();
1174 return true;
1175 }
1176
1177 #if wxUSE_DYNLIB_CLASS
1178 // Otherwise, set the layered style if needed and set the alpha value
1179 if ((exstyle & WS_EX_LAYERED) == 0 )
1180 SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle | WS_EX_LAYERED);
1181
1182 if ( pSetLayeredWindowAttributes(GetHwnd(), 0, (BYTE)alpha, LWA_ALPHA) )
1183 return true;
1184 #endif // wxUSE_DYNLIB_CLASS
1185
1186 return false;
1187 }
1188
1189 bool wxTopLevelWindowMSW::CanSetTransparent()
1190 {
1191 // The API is available on win2k and above
1192
1193 static int os_type = -1;
1194 static int ver_major = -1;
1195
1196 if (os_type == -1)
1197 os_type = ::wxGetOsVersion(&ver_major);
1198
1199 return (os_type == wxOS_WINDOWS_NT && ver_major >= 5);
1200 }
1201
1202
1203 void wxTopLevelWindowMSW::DoFreeze()
1204 {
1205 // do nothing: freezing toplevel window causes paint and mouse events
1206 // to go through it any TLWs under it, so the best we can do is to freeze
1207 // all children -- and wxWindowBase::Freeze() does that
1208 }
1209
1210 void wxTopLevelWindowMSW::DoThaw()
1211 {
1212 // intentionally empty -- see DoFreeze()
1213 }
1214
1215
1216 // ----------------------------------------------------------------------------
1217 // wxTopLevelWindow event handling
1218 // ----------------------------------------------------------------------------
1219
1220 // Default activation behaviour - set the focus for the first child
1221 // subwindow found.
1222 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
1223 {
1224 if ( event.GetActive() )
1225 {
1226 // restore focus to the child which was last focused unless we already
1227 // have it
1228 wxLogTrace(wxT("focus"), wxT("wxTLW %p activated."), m_hWnd);
1229
1230 wxWindow *winFocus = FindFocus();
1231 if ( !winFocus || wxGetTopLevelParent(winFocus) != this )
1232 {
1233 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
1234 : NULL;
1235 if ( !parent )
1236 {
1237 parent = this;
1238 }
1239
1240 wxSetFocusToChild(parent, &m_winLastFocused);
1241 }
1242 }
1243 else // deactivating
1244 {
1245 // remember the last focused child if it is our child
1246 m_winLastFocused = FindFocus();
1247
1248 if ( m_winLastFocused )
1249 {
1250 // let it know that it doesn't have focus any more
1251 // But this will already be done via WM_KILLFOCUS, so we'll get two kill
1252 // focus events if we call it explicitly.
1253 // m_winLastFocused->HandleKillFocus((WXHWND)NULL);
1254
1255 // and don't remember it if it's a child from some other frame
1256 if ( wxGetTopLevelParent(m_winLastFocused) != this )
1257 {
1258 m_winLastFocused = NULL;
1259 }
1260 }
1261
1262 wxLogTrace(wxT("focus"),
1263 wxT("wxTLW %p deactivated, last focused: %p."),
1264 m_hWnd,
1265 m_winLastFocused ? GetHwndOf(m_winLastFocused) : NULL);
1266
1267 event.Skip();
1268 }
1269 }
1270
1271 // the DialogProc for all wxWidgets dialogs
1272 LONG APIENTRY _EXPORT
1273 wxDlgProc(HWND hDlg,
1274 UINT message,
1275 WPARAM WXUNUSED(wParam),
1276 LPARAM WXUNUSED(lParam))
1277 {
1278 switch ( message )
1279 {
1280 case WM_INITDIALOG:
1281 {
1282 // under CE, add a "Ok" button in the dialog title bar and make it full
1283 // screen
1284 //
1285 // TODO: find the window for this HWND, and take into account
1286 // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present.
1287 //
1288 // Standard SDK doesn't have aygshell.dll: see
1289 // include/wx/msw/wince/libraries.h
1290 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1291 SHINITDLGINFO shidi;
1292 shidi.dwMask = SHIDIM_FLAGS;
1293 shidi.dwFlags = SHIDIF_SIZEDLG // take account of the SIP or menubar
1294 #ifndef __SMARTPHONE__
1295 | SHIDIF_DONEBUTTON
1296 #endif
1297 ;
1298 shidi.hDlg = hDlg;
1299 SHInitDialog( &shidi );
1300 #else // no SHInitDialog()
1301 wxUnusedVar(hDlg);
1302 #endif
1303 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1304 // the first control in the dialog box, but as we set the focus
1305 // ourselves, we return FALSE for it as well
1306 return FALSE;
1307 }
1308 }
1309
1310 // for almost all messages, returning FALSE means that we didn't process
1311 // the message
1312 return FALSE;
1313 }
1314
1315 // ============================================================================
1316 // wxTLWHiddenParentModule implementation
1317 // ============================================================================
1318
1319 HWND wxTLWHiddenParentModule::ms_hwnd = NULL;
1320
1321 const wxChar *wxTLWHiddenParentModule::ms_className = NULL;
1322
1323 bool wxTLWHiddenParentModule::OnInit()
1324 {
1325 ms_hwnd = NULL;
1326 ms_className = NULL;
1327
1328 return true;
1329 }
1330
1331 void wxTLWHiddenParentModule::OnExit()
1332 {
1333 if ( ms_hwnd )
1334 {
1335 if ( !::DestroyWindow(ms_hwnd) )
1336 {
1337 wxLogLastError(wxT("DestroyWindow(hidden TLW parent)"));
1338 }
1339
1340 ms_hwnd = NULL;
1341 }
1342
1343 if ( ms_className )
1344 {
1345 if ( !::UnregisterClass(ms_className, wxGetInstance()) )
1346 {
1347 wxLogLastError(wxT("UnregisterClass(\"wxTLWHiddenParent\")"));
1348 }
1349
1350 ms_className = NULL;
1351 }
1352 }
1353
1354 /* static */
1355 HWND wxTLWHiddenParentModule::GetHWND()
1356 {
1357 if ( !ms_hwnd )
1358 {
1359 if ( !ms_className )
1360 {
1361 static const wxChar *HIDDEN_PARENT_CLASS = wxT("wxTLWHiddenParent");
1362
1363 WNDCLASS wndclass;
1364 wxZeroMemory(wndclass);
1365
1366 wndclass.lpfnWndProc = DefWindowProc;
1367 wndclass.hInstance = wxGetInstance();
1368 wndclass.lpszClassName = HIDDEN_PARENT_CLASS;
1369
1370 if ( !::RegisterClass(&wndclass) )
1371 {
1372 wxLogLastError(wxT("RegisterClass(\"wxTLWHiddenParent\")"));
1373 }
1374 else
1375 {
1376 ms_className = HIDDEN_PARENT_CLASS;
1377 }
1378 }
1379
1380 ms_hwnd = ::CreateWindow(ms_className, wxEmptyString, 0, 0, 0, 0, 0, NULL,
1381 (HMENU)NULL, wxGetInstance(), NULL);
1382 if ( !ms_hwnd )
1383 {
1384 wxLogLastError(wxT("CreateWindow(hidden TLW parent)"));
1385 }
1386 }
1387
1388 return ms_hwnd;
1389 }