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