1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for MSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
34 #include "wx/string.h"
38 #include "wx/containr.h" // wxSetFocusToChild()
41 #include "wx/module.h"
43 #include "wx/msw/private.h"
44 #if defined(__WXWINCE__)
50 #include "wx/msw/wince/missing.h"
53 #include "wx/msw/missing.h"
54 #include "wx/msw/winundef.h"
56 #include "wx/display.h"
66 // ----------------------------------------------------------------------------
67 // stubs for missing functions under MicroWindows
68 // ----------------------------------------------------------------------------
72 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
73 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
75 #endif // __WXMICROWIN__
77 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
78 // is not included by wxUniv build which does need wxDlgProc
80 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 // list of all frames and modeless dialogs
87 wxWindowList wxModelessWindows
;
89 // the name of the default wxWindows class
90 extern const wxChar
*wxCanvasClassName
;
92 // ----------------------------------------------------------------------------
93 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
94 // module to ensure that the window is always deleted)
95 // ----------------------------------------------------------------------------
97 class wxTLWHiddenParentModule
: public wxModule
100 // module init/finalize
101 virtual bool OnInit();
102 virtual void OnExit();
104 // get the hidden window (creates on demand)
105 static HWND
GetHWND();
108 // the HWND of the hidden parent
111 // the class used to create it
112 static const wxChar
*ms_className
;
114 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
117 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
119 // ============================================================================
120 // wxTopLevelWindowMSW implementation
121 // ============================================================================
123 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
124 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
127 // ----------------------------------------------------------------------------
128 // wxTopLevelWindowMSW creation
129 // ----------------------------------------------------------------------------
131 void wxTopLevelWindowMSW::Init()
134 m_maximizeOnShow
= FALSE
;
136 // Data to save/restore when calling ShowFullScreen
138 m_fsOldWindowStyle
= 0;
139 m_fsIsMaximized
= FALSE
;
140 m_fsIsShowing
= FALSE
;
142 m_winLastFocused
= (wxWindow
*)NULL
;
145 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
147 // let the base class deal with the common styles but fix the ones which
148 // don't make sense for us (we also deal with the borders ourselves)
149 WXDWORD msflags
= wxWindow::MSWGetStyle
151 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
152 ) & ~WS_CHILD
& ~WS_VISIBLE
;
154 // first select the kind of window being created
156 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
157 // creates a window with both caption and border, hence we also test it
158 // below in some other cases
159 if ( style
& wxFRAME_TOOL_WINDOW
)
163 if (msflags
& WS_BORDER
)
164 msflags
|= WS_OVERLAPPED
;
167 // border and caption styles
168 if ( style
& wxRESIZE_BORDER
)
172 msflags
|= WS_THICKFRAME
;
174 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
175 *exflags
|= WS_EX_DLGMODALFRAME
;
176 else if ( !(style
& wxBORDER_NONE
) )
177 msflags
|= WS_BORDER
;
181 if ( style
& wxCAPTION
)
182 msflags
|= WS_CAPTION
;
186 // next translate the individual flags
187 if ( style
& wxMINIMIZE_BOX
)
188 msflags
|= WS_MINIMIZEBOX
;
189 if ( style
& wxMAXIMIZE_BOX
)
190 msflags
|= WS_MAXIMIZEBOX
;
191 if ( style
& wxSYSTEM_MENU
)
192 msflags
|= WS_SYSMENU
;
194 // under CE these 2 styles are not defined currently
196 if ( style
& wxMINIMIZE
)
197 msflags
|= WS_MINIMIZE
;
198 #endif // WS_MINIMIZE
200 if ( style
& wxMAXIMIZE
)
201 msflags
|= WS_MAXIMIZE
;
202 #endif // WS_MAXIMIZE
204 // Keep this here because it saves recoding this function in wxTinyFrame
205 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
206 msflags
|= WS_CAPTION
;
210 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
212 if ( style
& wxFRAME_TOOL_WINDOW
)
214 // create the palette-like window
215 *exflags
|= WS_EX_TOOLWINDOW
;
217 // tool windows shouldn't appear on the taskbar (as documented)
218 style
|= wxFRAME_NO_TASKBAR
;
221 // again, support for this is missing under CE
222 #ifdef WS_EX_APPWINDOW
223 // We have to solve 2 different problems here:
225 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
226 // taskbar even if they don't have a parent
228 // 2. frames without this style should appear in the taskbar even
229 // if they're owned (Windows only puts non owned windows into
230 // the taskbar normally)
232 // The second one is solved here by using WS_EX_APPWINDOW flag, the
233 // first one is dealt with in our MSWGetParent() method
235 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
237 // need to force the frame to appear in the taskbar
238 *exflags
|= WS_EX_APPWINDOW
;
240 //else: nothing to do [here]
241 #endif // WS_EX_APPWINDOW
244 if ( style
& wxSTAY_ON_TOP
)
245 *exflags
|= WS_EX_TOPMOST
;
247 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
248 *exflags
|= WS_EX_CONTEXTHELP
;
254 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
256 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
257 // parent HWND or it would be always on top of its parent which is not what
258 // we usually want (in fact, we only want it for frames with the
259 // wxFRAME_FLOAT_ON_PARENT flag)
260 HWND hwndParent
= NULL
;
261 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
263 const wxWindow
*parent
= GetParent();
267 // this flag doesn't make sense then and will be ignored
268 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
272 hwndParent
= GetHwndOf(parent
);
275 //else: don't float on parent, must not be owned
277 // now deal with the 2nd taskbar-related problem (see comments above in
279 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
282 hwndParent
= wxTLWHiddenParentModule::GetHWND();
285 return (WXHWND
)hwndParent
;
288 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
289 const wxString
& title
,
293 #ifdef __WXMICROWIN__
294 // no dialogs support under MicroWin yet
295 return CreateFrame(title
, pos
, size
);
296 #else // !__WXMICROWIN__
297 wxWindow
*parent
= GetParent();
299 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
300 // app window as parent - this avoids creating modal dialogs without
302 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
304 parent
= wxTheApp
->GetTopWindow();
308 // don't use transient windows as parents, this is dangerous as it
309 // can lead to a crash if the parent is destroyed before the child
311 // also don't use the window which is currently hidden as then the
312 // dialog would be hidden as well
313 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
321 m_hWnd
= (WXHWND
)::CreateDialogIndirect
324 (DLGTEMPLATE
*)dlgTemplate
,
325 parent
? GetHwndOf(parent
) : NULL
,
331 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
333 wxLogSysError(wxT("Can't create dialog using memory template"));
339 (void)MSWGetCreateWindowFlags(&exflags
);
343 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
344 ::SetWindowPos(GetHwnd(),
345 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
349 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
353 #if defined(__WIN95__)
354 // For some reason, the system menu is activated when we use the
355 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
356 if ( exflags
& WS_EX_CONTEXTHELP
)
358 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
361 wxIcon icon
= winTop
->GetIcon();
364 ::SendMessage(GetHwnd(), WM_SETICON
,
366 (LPARAM
)GetHiconOf(icon
));
372 // move the dialog to its initial position without forcing repainting
374 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
376 if ( x
== (int)CW_USEDEFAULT
)
378 // centre it on the screen - what else can we do?
379 wxSize sizeDpy
= wxGetDisplaySize();
381 x
= (sizeDpy
.x
- w
) / 2;
382 y
= (sizeDpy
.y
- h
) / 2;
385 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
387 wxLogLastError(wxT("MoveWindow"));
390 if ( !title
.empty() )
392 ::SetWindowText(GetHwnd(), title
);
398 #endif // __WXMICROWIN__/!__WXMICROWIN__
401 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
406 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
408 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
411 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
413 const wxString
& title
,
417 const wxString
& name
)
419 bool ret
wxDUMMY_INITIALIZE(false);
424 wxSize sizeReal
= size
;
425 if ( !sizeReal
.IsFullySpecified() )
427 sizeReal
.SetDefaults(GetDefaultSize());
430 m_windowStyle
= style
;
434 m_windowId
= id
== -1 ? NewControlId() : id
;
436 wxTopLevelWindows
.Append(this);
439 parent
->AddChild(this);
441 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
443 // we have different dialog templates to allows creation of dialogs
444 // with & without captions under MSWindows, resizeable or not (but a
445 // resizeable dialog always has caption - otherwise it would look too
448 // we need 3 additional WORDs for dialog menu, class and title (as we
449 // don't use DS_SETFONT we don't need the fourth WORD for the font)
450 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
451 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
452 memset(dlgTemplate
, 0, dlgsize
);
454 // these values are arbitrary, they won't be used normally anyhow
457 dlgTemplate
->cx
= 144;
458 dlgTemplate
->cy
= 75;
460 // reuse the code in MSWGetStyle() but correct the results slightly for
462 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
464 // all dialogs are popups
465 dlgTemplate
->style
|= WS_POPUP
;
467 // force 3D-look if necessary, it looks impossibly ugly otherwise
468 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
469 dlgTemplate
->style
|= DS_MODALFRAME
;
471 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
476 ret
= CreateFrame(title
, pos
, sizeReal
);
479 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
481 EnableCloseButton(false);
484 // for some reason we need to manually send ourselves this message as
485 // otherwise the mnemonics are always shown -- even if they're configured
486 // to be hidden until "Alt" is pressed in the control panel
488 // this could indicate a bug somewhere else but for now this is the only
496 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
504 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
506 if ( wxModelessWindows
.Find(this) )
507 wxModelessWindows
.DeleteObject(this);
509 // after destroying an owned window, Windows activates the next top level
510 // window in Z order but it may be different from our owner (to reproduce
511 // this simply Alt-TAB to another application and back before closing the
512 // owned frame) whereas we always want to yield activation to our parent
513 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
515 wxWindow
*parent
= GetParent();
518 ::BringWindowToTop(GetHwndOf(parent
));
523 // ----------------------------------------------------------------------------
524 // wxTopLevelWindowMSW showing
525 // ----------------------------------------------------------------------------
527 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
529 ::ShowWindow(GetHwnd(), nShowCmd
);
531 m_iconized
= nShowCmd
== SW_MINIMIZE
;
534 bool wxTopLevelWindowMSW::Show(bool show
)
536 // don't use wxWindow version as we want to call DoShowWindow() ourselves
537 if ( !wxWindowBase::Show(show
) )
543 if ( m_maximizeOnShow
)
546 nShowCmd
= SW_MAXIMIZE
;
548 m_maximizeOnShow
= FALSE
;
552 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
553 nShowCmd
= SW_SHOWNA
;
563 DoShowWindow(nShowCmd
);
567 ::BringWindowToTop(GetHwnd());
569 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
570 event
.SetEventObject( this );
571 GetEventHandler()->ProcessEvent(event
);
575 // Try to highlight the correct window (the parent)
578 HWND hWndParent
= GetHwndOf(GetParent());
580 ::BringWindowToTop(hWndParent
);
587 // ----------------------------------------------------------------------------
588 // wxTopLevelWindowMSW maximize/minimize
589 // ----------------------------------------------------------------------------
591 void wxTopLevelWindowMSW::Maximize(bool maximize
)
595 // just maximize it directly
596 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
600 // we can't maximize the hidden frame because it shows it as well, so
601 // just remember that we should do it later in this case
602 m_maximizeOnShow
= maximize
;
606 bool wxTopLevelWindowMSW::IsMaximized() const
611 return ::IsZoomed(GetHwnd()) != 0;
615 void wxTopLevelWindowMSW::Iconize(bool iconize
)
617 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
620 bool wxTopLevelWindowMSW::IsIconized() const
625 // also update the current state
626 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
632 void wxTopLevelWindowMSW::Restore()
634 DoShowWindow(SW_RESTORE
);
637 // ----------------------------------------------------------------------------
638 // wxTopLevelWindowMSW fullscreen
639 // ----------------------------------------------------------------------------
641 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
643 if ( show
== IsFullScreen() )
649 m_fsIsShowing
= show
;
655 // zap the frame borders
657 // save the 'normal' window style
658 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
660 // save the old position, width & height, maximize state
661 m_fsOldSize
= GetRect();
662 m_fsIsMaximized
= IsMaximized();
664 // decide which window style flags to turn off
665 LONG newStyle
= m_fsOldWindowStyle
;
668 if (style
& wxFULLSCREEN_NOBORDER
)
670 offFlags
|= WS_BORDER
;
672 offFlags
|= WS_THICKFRAME
;
675 if (style
& wxFULLSCREEN_NOCAPTION
)
676 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
678 newStyle
&= ~offFlags
;
680 // change our window style to be compatible with full-screen mode
681 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
685 // resize to the size of the display containing us
686 int dpy
= wxDisplay::GetFromWindow(this);
687 if ( dpy
!= wxNOT_FOUND
)
689 rect
= wxDisplay(dpy
).GetGeometry();
691 else // fall back to the main desktop
692 #else // wxUSE_DISPLAY
694 // resize to the size of the desktop
695 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
697 // FIXME: size of the bottom menu (toolbar)
698 // should be taken in account
699 rect
.height
+= rect
.y
;
703 #endif // wxUSE_DISPLAY
707 // now flush the window style cache and actually go full-screen
708 long flags
= SWP_FRAMECHANGED
;
710 // showing the frame full screen should also show it if it's still
714 // don't call wxWindow version to avoid flicker from calling
715 // ::ShowWindow() -- we're going to show the window at the correct
716 // location directly below -- but do call the wxWindowBase version
717 // to sync the internal m_isShown flag
718 wxWindowBase::Show();
720 flags
|= SWP_SHOWWINDOW
;
723 SetWindowPos(GetHwnd(), HWND_TOP
,
724 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
727 #if defined(__WXWINCE__) && _WIN32_WCE < 400
728 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
731 // finally send an event allowing the window to relayout itself &c
732 wxSizeEvent
event(rect
.GetSize(), GetId());
733 GetEventHandler()->ProcessEvent(event
);
735 else // stop showing full screen
737 #if defined(__WXWINCE__) && _WIN32_WCE < 400
738 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
740 Maximize(m_fsIsMaximized
);
741 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
742 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
743 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
749 // ----------------------------------------------------------------------------
750 // wxTopLevelWindowMSW misc
751 // ----------------------------------------------------------------------------
753 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
755 SetIcons( wxIconBundle( icon
) );
758 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
760 wxTopLevelWindowBase::SetIcons(icons
);
762 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
763 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
764 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
766 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
767 (LPARAM
)GetHiconOf(sml
) );
770 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
771 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
773 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
774 (LPARAM
)GetHiconOf(big
) );
779 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
781 #if !defined(__WXMICROWIN__)
782 // get system (a.k.a. window) menu
783 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
786 // no system menu at all -- ok if we want to remove the close button
787 // anyhow, but bad if we want to show it
791 // enabling/disabling the close item from it also automatically
792 // disables/enables the close title bar button
793 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
795 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
797 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
802 // update appearance immediately
803 if ( !::DrawMenuBar(GetHwnd()) )
805 wxLogLastError(_T("DrawMenuBar"));
807 #endif // !__WXMICROWIN__
814 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
816 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
817 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
819 // The empty region signifies that the shape should be removed from the
821 if ( region
.IsEmpty() )
823 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
825 wxLogLastError(_T("SetWindowRgn"));
831 // Windows takes ownership of the region, so
832 // we'll have to make a copy of the region to give to it.
833 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
834 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
835 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
836 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
837 delete[] (char*) rgnData
;
839 // SetWindowRgn expects the region to be in coordinants
840 // relative to the window, not the client area. Figure
841 // out the offset, if any.
843 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
844 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
845 ::GetClientRect(GetHwnd(), &rect
);
846 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
847 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
849 // Now call the shape API with the new region.
850 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
852 wxLogLastError(_T("SetWindowRgn"));
858 #endif // !__WXWINCE__
860 // ----------------------------------------------------------------------------
861 // wxTopLevelWindow event handling
862 // ----------------------------------------------------------------------------
864 // Default activation behaviour - set the focus for the first child
866 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
868 if ( event
.GetActive() )
870 // restore focus to the child which was last focused unless we already
872 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
874 wxWindow
*winFocus
= FindFocus();
875 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
877 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
884 wxSetFocusToChild(parent
, &m_winLastFocused
);
889 // remember the last focused child if it is our child
890 m_winLastFocused
= FindFocus();
892 if ( m_winLastFocused
)
894 // let it know that it doesn't have focus any more
895 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
897 // and don't remember it if it's a child from some other frame
898 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
900 m_winLastFocused
= NULL
;
904 wxLogTrace(_T("focus"),
905 _T("wxTLW %08x deactivated, last focused: %08x."),
907 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
914 // the DialogProc for all wxWindows dialogs
915 LONG APIENTRY _EXPORT
916 wxDlgProc(HWND
WXUNUSED(hDlg
),
918 WPARAM
WXUNUSED(wParam
),
919 LPARAM
WXUNUSED(lParam
))
924 // for this message, returning TRUE tells system to set focus to
925 // the first control in the dialog box, but as we set the focus
926 // ourselves, we return FALSE from here as well, so fall through
929 // for all the other ones, FALSE means that we didn't process the
935 // ============================================================================
936 // wxTLWHiddenParentModule implementation
937 // ============================================================================
939 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
941 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
943 bool wxTLWHiddenParentModule::OnInit()
951 void wxTLWHiddenParentModule::OnExit()
955 if ( !::DestroyWindow(ms_hwnd
) )
957 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
965 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
967 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
975 HWND
wxTLWHiddenParentModule::GetHWND()
981 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
984 wxZeroMemory(wndclass
);
986 wndclass
.lpfnWndProc
= DefWindowProc
;
987 wndclass
.hInstance
= wxGetInstance();
988 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
990 if ( !::RegisterClass(&wndclass
) )
992 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
996 ms_className
= HIDDEN_PARENT_CLASS
;
1000 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1001 (HMENU
)NULL
, wxGetInstance(), NULL
);
1004 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));