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
)
169 msflags
|= WS_THICKFRAME
;
170 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
171 *exflags
|= WS_EX_DLGMODALFRAME
;
172 else if ( !(style
& wxBORDER_NONE
) )
173 msflags
|= WS_BORDER
;
177 if ( style
& wxCAPTION
)
178 msflags
|= WS_CAPTION
;
182 // next translate the individual flags
183 if ( style
& wxMINIMIZE_BOX
)
184 msflags
|= WS_MINIMIZEBOX
;
185 if ( style
& wxMAXIMIZE_BOX
)
186 msflags
|= WS_MAXIMIZEBOX
;
187 if ( style
& wxSYSTEM_MENU
)
188 msflags
|= WS_SYSMENU
;
190 // under CE these 2 styles are not defined currently
192 if ( style
& wxMINIMIZE
)
193 msflags
|= WS_MINIMIZE
;
194 #endif // WS_MINIMIZE
196 if ( style
& wxMAXIMIZE
)
197 msflags
|= WS_MAXIMIZE
;
198 #endif // WS_MAXIMIZE
200 // Keep this here because it saves recoding this function in wxTinyFrame
201 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
202 msflags
|= WS_CAPTION
;
206 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
208 if ( style
& wxFRAME_TOOL_WINDOW
)
210 // create the palette-like window
211 *exflags
|= WS_EX_TOOLWINDOW
;
213 // tool windows shouldn't appear on the taskbar (as documented)
214 style
|= wxFRAME_NO_TASKBAR
;
217 // again, support for this is missing under CE
218 #ifdef WS_EX_APPWINDOW
219 // We have to solve 2 different problems here:
221 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
222 // taskbar even if they don't have a parent
224 // 2. frames without this style should appear in the taskbar even
225 // if they're owned (Windows only puts non owned windows into
226 // the taskbar normally)
228 // The second one is solved here by using WS_EX_APPWINDOW flag, the
229 // first one is dealt with in our MSWGetParent() method
231 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
233 // need to force the frame to appear in the taskbar
234 *exflags
|= WS_EX_APPWINDOW
;
236 //else: nothing to do [here]
237 #endif // WS_EX_APPWINDOW
240 if ( style
& wxSTAY_ON_TOP
)
241 *exflags
|= WS_EX_TOPMOST
;
243 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
244 *exflags
|= WS_EX_CONTEXTHELP
;
250 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
252 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
253 // parent HWND or it would be always on top of its parent which is not what
254 // we usually want (in fact, we only want it for frames with the
255 // wxFRAME_FLOAT_ON_PARENT flag)
256 HWND hwndParent
= NULL
;
257 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
259 const wxWindow
*parent
= GetParent();
263 // this flag doesn't make sense then and will be ignored
264 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
268 hwndParent
= GetHwndOf(parent
);
271 //else: don't float on parent, must not be owned
273 // now deal with the 2nd taskbar-related problem (see comments above in
275 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
278 hwndParent
= wxTLWHiddenParentModule::GetHWND();
281 return (WXHWND
)hwndParent
;
284 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
285 const wxString
& title
,
289 #ifdef __WXMICROWIN__
290 // no dialogs support under MicroWin yet
291 return CreateFrame(title
, pos
, size
);
292 #else // !__WXMICROWIN__
293 wxWindow
*parent
= GetParent();
295 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
296 // app window as parent - this avoids creating modal dialogs without
298 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
300 parent
= wxTheApp
->GetTopWindow();
304 // don't use transient windows as parents, this is dangerous as it
305 // can lead to a crash if the parent is destroyed before the child
307 // also don't use the window which is currently hidden as then the
308 // dialog would be hidden as well
309 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
317 m_hWnd
= (WXHWND
)::CreateDialogIndirect
320 (DLGTEMPLATE
*)dlgTemplate
,
321 parent
? GetHwndOf(parent
) : NULL
,
327 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
329 wxLogSysError(wxT("Can't create dialog using memory template"));
335 (void)MSWGetCreateWindowFlags(&exflags
);
339 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
340 ::SetWindowPos(GetHwnd(),
341 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
345 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
349 #if defined(__WIN95__)
350 // For some reason, the system menu is activated when we use the
351 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
352 if ( exflags
& WS_EX_CONTEXTHELP
)
354 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
357 wxIcon icon
= winTop
->GetIcon();
360 ::SendMessage(GetHwnd(), WM_SETICON
,
362 (LPARAM
)GetHiconOf(icon
));
368 // move the dialog to its initial position without forcing repainting
370 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
372 if ( x
== (int)CW_USEDEFAULT
)
374 // centre it on the screen - what else can we do?
375 wxSize sizeDpy
= wxGetDisplaySize();
377 x
= (sizeDpy
.x
- w
) / 2;
378 y
= (sizeDpy
.y
- h
) / 2;
381 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
383 wxLogLastError(wxT("MoveWindow"));
386 if ( !title
.empty() )
388 ::SetWindowText(GetHwnd(), title
);
394 #endif // __WXMICROWIN__/!__WXMICROWIN__
397 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
402 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
404 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
407 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
409 const wxString
& title
,
413 const wxString
& name
)
415 bool ret
wxDUMMY_INITIALIZE(false);
420 wxSize sizeReal
= size
;
421 if ( !sizeReal
.IsFullySpecified() )
423 sizeReal
.SetDefaults(GetDefaultSize());
426 m_windowStyle
= style
;
430 m_windowId
= id
== -1 ? NewControlId() : id
;
432 wxTopLevelWindows
.Append(this);
435 parent
->AddChild(this);
437 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
439 // we have different dialog templates to allows creation of dialogs
440 // with & without captions under MSWindows, resizeable or not (but a
441 // resizeable dialog always has caption - otherwise it would look too
444 // we need 3 additional WORDs for dialog menu, class and title (as we
445 // don't use DS_SETFONT we don't need the fourth WORD for the font)
446 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
447 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
448 memset(dlgTemplate
, 0, dlgsize
);
450 // these values are arbitrary, they won't be used normally anyhow
453 dlgTemplate
->cx
= 144;
454 dlgTemplate
->cy
= 75;
456 // reuse the code in MSWGetStyle() but correct the results slightly for
458 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
460 // all dialogs are popups
461 dlgTemplate
->style
|= WS_POPUP
;
463 // force 3D-look if necessary, it looks impossibly ugly otherwise
464 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
465 dlgTemplate
->style
|= DS_MODALFRAME
;
467 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
472 ret
= CreateFrame(title
, pos
, sizeReal
);
475 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
477 EnableCloseButton(false);
480 // for some reason we need to manually send ourselves this message as
481 // otherwise the mnemonics are always shown -- even if they're configured
482 // to be hidden until "Alt" is pressed in the control panel
484 // this could indicate a bug somewhere else but for now this is the only
492 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
500 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
502 if ( wxModelessWindows
.Find(this) )
503 wxModelessWindows
.DeleteObject(this);
505 // after destroying an owned window, Windows activates the next top level
506 // window in Z order but it may be different from our owner (to reproduce
507 // this simply Alt-TAB to another application and back before closing the
508 // owned frame) whereas we always want to yield activation to our parent
509 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
511 wxWindow
*parent
= GetParent();
514 ::BringWindowToTop(GetHwndOf(parent
));
519 // ----------------------------------------------------------------------------
520 // wxTopLevelWindowMSW showing
521 // ----------------------------------------------------------------------------
523 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
525 ::ShowWindow(GetHwnd(), nShowCmd
);
527 m_iconized
= nShowCmd
== SW_MINIMIZE
;
530 bool wxTopLevelWindowMSW::Show(bool show
)
532 // don't use wxWindow version as we want to call DoShowWindow() ourselves
533 if ( !wxWindowBase::Show(show
) )
539 if ( m_maximizeOnShow
)
542 nShowCmd
= SW_MAXIMIZE
;
544 m_maximizeOnShow
= FALSE
;
548 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
549 nShowCmd
= SW_SHOWNA
;
559 DoShowWindow(nShowCmd
);
563 ::BringWindowToTop(GetHwnd());
565 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
566 event
.SetEventObject( this );
567 GetEventHandler()->ProcessEvent(event
);
571 // Try to highlight the correct window (the parent)
574 HWND hWndParent
= GetHwndOf(GetParent());
576 ::BringWindowToTop(hWndParent
);
583 // ----------------------------------------------------------------------------
584 // wxTopLevelWindowMSW maximize/minimize
585 // ----------------------------------------------------------------------------
587 void wxTopLevelWindowMSW::Maximize(bool maximize
)
591 // just maximize it directly
592 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
596 // we can't maximize the hidden frame because it shows it as well, so
597 // just remember that we should do it later in this case
598 m_maximizeOnShow
= maximize
;
602 bool wxTopLevelWindowMSW::IsMaximized() const
607 return ::IsZoomed(GetHwnd()) != 0;
611 void wxTopLevelWindowMSW::Iconize(bool iconize
)
613 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
616 bool wxTopLevelWindowMSW::IsIconized() const
621 // also update the current state
622 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
628 void wxTopLevelWindowMSW::Restore()
630 DoShowWindow(SW_RESTORE
);
633 // ----------------------------------------------------------------------------
634 // wxTopLevelWindowMSW fullscreen
635 // ----------------------------------------------------------------------------
637 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
639 if ( show
== IsFullScreen() )
645 m_fsIsShowing
= show
;
651 // zap the frame borders
653 // save the 'normal' window style
654 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
656 // save the old position, width & height, maximize state
657 m_fsOldSize
= GetRect();
658 m_fsIsMaximized
= IsMaximized();
660 // decide which window style flags to turn off
661 LONG newStyle
= m_fsOldWindowStyle
;
664 if (style
& wxFULLSCREEN_NOBORDER
)
666 offFlags
|= WS_BORDER
;
668 offFlags
|= WS_THICKFRAME
;
671 if (style
& wxFULLSCREEN_NOCAPTION
)
672 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
674 newStyle
&= ~offFlags
;
676 // change our window style to be compatible with full-screen mode
677 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
681 // resize to the size of the display containing us
682 int dpy
= wxDisplay::GetFromWindow(this);
683 if ( dpy
!= wxNOT_FOUND
)
685 rect
= wxDisplay(dpy
).GetGeometry();
687 else // fall back to the main desktop
688 #else // wxUSE_DISPLAY
690 // resize to the size of the desktop
691 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
693 // FIXME: size of the bottom menu (toolbar)
694 // should be taken in account
695 rect
.height
+= rect
.y
;
699 #endif // wxUSE_DISPLAY
703 // now flush the window style cache and actually go full-screen
704 long flags
= SWP_FRAMECHANGED
;
706 // showing the frame full screen should also show it if it's still
710 // don't call wxWindow version to avoid flicker from calling
711 // ::ShowWindow() -- we're going to show the window at the correct
712 // location directly below -- but do call the wxWindowBase version
713 // to sync the internal m_isShown flag
714 wxWindowBase::Show();
716 flags
|= SWP_SHOWWINDOW
;
719 SetWindowPos(GetHwnd(), HWND_TOP
,
720 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
723 #if defined(__WXWINCE__) && _WIN32_WCE < 400
724 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
727 // finally send an event allowing the window to relayout itself &c
728 wxSizeEvent
event(rect
.GetSize(), GetId());
729 GetEventHandler()->ProcessEvent(event
);
731 else // stop showing full screen
733 #if defined(__WXWINCE__) && _WIN32_WCE < 400
734 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
736 Maximize(m_fsIsMaximized
);
737 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
738 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
739 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
745 // ----------------------------------------------------------------------------
746 // wxTopLevelWindowMSW misc
747 // ----------------------------------------------------------------------------
749 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
751 SetIcons( wxIconBundle( icon
) );
754 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
756 wxTopLevelWindowBase::SetIcons(icons
);
758 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
759 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
760 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
762 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
763 (LPARAM
)GetHiconOf(sml
) );
766 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
767 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
769 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
770 (LPARAM
)GetHiconOf(big
) );
775 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
777 #if !defined(__WXMICROWIN__)
778 // get system (a.k.a. window) menu
779 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
782 // no system menu at all -- ok if we want to remove the close button
783 // anyhow, but bad if we want to show it
787 // enabling/disabling the close item from it also automatically
788 // disables/enables the close title bar button
789 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
791 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
793 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
798 // update appearance immediately
799 if ( !::DrawMenuBar(GetHwnd()) )
801 wxLogLastError(_T("DrawMenuBar"));
803 #endif // !__WXMICROWIN__
810 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
812 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
813 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
815 // The empty region signifies that the shape should be removed from the
817 if ( region
.IsEmpty() )
819 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
821 wxLogLastError(_T("SetWindowRgn"));
827 // Windows takes ownership of the region, so
828 // we'll have to make a copy of the region to give to it.
829 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
830 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
831 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
832 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
833 delete[] (char*) rgnData
;
835 // SetWindowRgn expects the region to be in coordinants
836 // relative to the window, not the client area. Figure
837 // out the offset, if any.
839 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
840 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
841 ::GetClientRect(GetHwnd(), &rect
);
842 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
843 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
845 // Now call the shape API with the new region.
846 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
848 wxLogLastError(_T("SetWindowRgn"));
854 #endif // !__WXWINCE__
856 // ----------------------------------------------------------------------------
857 // wxTopLevelWindow event handling
858 // ----------------------------------------------------------------------------
860 // Default activation behaviour - set the focus for the first child
862 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
864 if ( event
.GetActive() )
866 // restore focus to the child which was last focused unless we already
868 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
870 wxWindow
*winFocus
= FindFocus();
871 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
873 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
880 wxSetFocusToChild(parent
, &m_winLastFocused
);
885 // remember the last focused child if it is our child
886 m_winLastFocused
= FindFocus();
888 if ( m_winLastFocused
)
890 // let it know that it doesn't have focus any more
891 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
893 // and don't remember it if it's a child from some other frame
894 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
896 m_winLastFocused
= NULL
;
900 wxLogTrace(_T("focus"),
901 _T("wxTLW %08x deactivated, last focused: %08x."),
903 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
910 // the DialogProc for all wxWindows dialogs
911 LONG APIENTRY _EXPORT
912 wxDlgProc(HWND
WXUNUSED(hDlg
),
914 WPARAM
WXUNUSED(wParam
),
915 LPARAM
WXUNUSED(lParam
))
920 // for this message, returning TRUE tells system to set focus to
921 // the first control in the dialog box, but as we set the focus
922 // ourselves, we return FALSE from here as well, so fall through
925 // for all the other ones, FALSE means that we didn't process the
931 // ============================================================================
932 // wxTLWHiddenParentModule implementation
933 // ============================================================================
935 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
937 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
939 bool wxTLWHiddenParentModule::OnInit()
947 void wxTLWHiddenParentModule::OnExit()
951 if ( !::DestroyWindow(ms_hwnd
) )
953 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
961 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
963 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
971 HWND
wxTLWHiddenParentModule::GetHWND()
977 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
980 wxZeroMemory(wndclass
);
982 wndclass
.lpfnWndProc
= DefWindowProc
;
983 wndclass
.hInstance
= wxGetInstance();
984 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
986 if ( !::RegisterClass(&wndclass
) )
988 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
992 ms_className
= HIDDEN_PARENT_CLASS
;
996 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
997 (HMENU
)NULL
, wxGetInstance(), NULL
);
1000 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));