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
;
168 // border and caption styles
169 if ( style
& wxRESIZE_BORDER
)
170 #ifndef WS_THICKFRAME
173 msflags
|= WS_THICKFRAME
;
175 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
176 *exflags
|= WS_EX_DLGMODALFRAME
;
177 else if ( !(style
& wxBORDER_NONE
) )
178 msflags
|= WS_BORDER
;
182 if ( style
& wxCAPTION
)
186 msflags
|= WS_CAPTION
;
193 // next translate the individual flags
194 if ( style
& wxMINIMIZE_BOX
)
195 msflags
|= WS_MINIMIZEBOX
;
196 if ( style
& wxMAXIMIZE_BOX
)
197 msflags
|= WS_MAXIMIZEBOX
;
198 if ( style
& wxSYSTEM_MENU
)
199 msflags
|= WS_SYSMENU
;
201 // under CE these 2 styles are not defined currently
203 if ( style
& wxMINIMIZE
)
204 msflags
|= WS_MINIMIZE
;
205 #endif // WS_MINIMIZE
207 if ( style
& wxMAXIMIZE
)
208 msflags
|= WS_MAXIMIZE
;
209 #endif // WS_MAXIMIZE
211 // Keep this here because it saves recoding this function in wxTinyFrame
212 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
213 msflags
|= WS_CAPTION
;
217 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
219 if ( style
& wxFRAME_TOOL_WINDOW
)
221 // create the palette-like window
222 *exflags
|= WS_EX_TOOLWINDOW
;
224 // tool windows shouldn't appear on the taskbar (as documented)
225 style
|= wxFRAME_NO_TASKBAR
;
228 // again, support for this is missing under CE
229 #ifdef WS_EX_APPWINDOW
230 // We have to solve 2 different problems here:
232 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
233 // taskbar even if they don't have a parent
235 // 2. frames without this style should appear in the taskbar even
236 // if they're owned (Windows only puts non owned windows into
237 // the taskbar normally)
239 // The second one is solved here by using WS_EX_APPWINDOW flag, the
240 // first one is dealt with in our MSWGetParent() method
242 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
244 // need to force the frame to appear in the taskbar
245 *exflags
|= WS_EX_APPWINDOW
;
247 //else: nothing to do [here]
248 #endif // WS_EX_APPWINDOW
251 if ( style
& wxSTAY_ON_TOP
)
252 *exflags
|= WS_EX_TOPMOST
;
254 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
255 *exflags
|= WS_EX_CONTEXTHELP
;
261 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
263 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
264 // parent HWND or it would be always on top of its parent which is not what
265 // we usually want (in fact, we only want it for frames with the
266 // wxFRAME_FLOAT_ON_PARENT flag)
267 HWND hwndParent
= NULL
;
268 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
270 const wxWindow
*parent
= GetParent();
274 // this flag doesn't make sense then and will be ignored
275 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
279 hwndParent
= GetHwndOf(parent
);
282 //else: don't float on parent, must not be owned
284 // now deal with the 2nd taskbar-related problem (see comments above in
286 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
289 hwndParent
= wxTLWHiddenParentModule::GetHWND();
292 return (WXHWND
)hwndParent
;
295 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
296 const wxString
& title
,
300 #ifdef __WXMICROWIN__
301 // no dialogs support under MicroWin yet
302 return CreateFrame(title
, pos
, size
);
303 #else // !__WXMICROWIN__
304 wxWindow
*parent
= GetParent();
306 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
307 // app window as parent - this avoids creating modal dialogs without
309 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
311 parent
= wxTheApp
->GetTopWindow();
315 // don't use transient windows as parents, this is dangerous as it
316 // can lead to a crash if the parent is destroyed before the child
318 // also don't use the window which is currently hidden as then the
319 // dialog would be hidden as well
320 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
328 m_hWnd
= (WXHWND
)::CreateDialogIndirect
331 (DLGTEMPLATE
*)dlgTemplate
,
332 parent
? GetHwndOf(parent
) : NULL
,
338 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
340 wxLogSysError(wxT("Can't create dialog using memory template"));
346 (void)MSWGetCreateWindowFlags(&exflags
);
350 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
351 ::SetWindowPos(GetHwnd(),
352 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
356 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
360 #if defined(__WIN95__)
361 // For some reason, the system menu is activated when we use the
362 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
363 if ( exflags
& WS_EX_CONTEXTHELP
)
365 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
368 wxIcon icon
= winTop
->GetIcon();
371 ::SendMessage(GetHwnd(), WM_SETICON
,
373 (LPARAM
)GetHiconOf(icon
));
379 // move the dialog to its initial position without forcing repainting
381 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
383 if ( x
== (int)CW_USEDEFAULT
)
385 // centre it on the screen - what else can we do?
386 wxSize sizeDpy
= wxGetDisplaySize();
388 x
= (sizeDpy
.x
- w
) / 2;
389 y
= (sizeDpy
.y
- h
) / 2;
392 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
394 wxLogLastError(wxT("MoveWindow"));
397 if ( !title
.empty() )
399 ::SetWindowText(GetHwnd(), title
);
405 #endif // __WXMICROWIN__/!__WXMICROWIN__
408 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
413 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
415 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
418 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
420 const wxString
& title
,
424 const wxString
& name
)
426 bool ret
wxDUMMY_INITIALIZE(false);
431 wxSize sizeReal
= size
;
432 if ( !sizeReal
.IsFullySpecified() )
434 sizeReal
.SetDefaults(GetDefaultSize());
437 m_windowStyle
= style
;
441 m_windowId
= id
== -1 ? NewControlId() : id
;
443 wxTopLevelWindows
.Append(this);
446 parent
->AddChild(this);
448 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
450 // we have different dialog templates to allows creation of dialogs
451 // with & without captions under MSWindows, resizeable or not (but a
452 // resizeable dialog always has caption - otherwise it would look too
455 // we need 3 additional WORDs for dialog menu, class and title (as we
456 // don't use DS_SETFONT we don't need the fourth WORD for the font)
457 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
458 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
459 memset(dlgTemplate
, 0, dlgsize
);
461 // these values are arbitrary, they won't be used normally anyhow
464 dlgTemplate
->cx
= 144;
465 dlgTemplate
->cy
= 75;
467 // reuse the code in MSWGetStyle() but correct the results slightly for
469 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
471 // all dialogs are popups
472 dlgTemplate
->style
|= WS_POPUP
;
474 // force 3D-look if necessary, it looks impossibly ugly otherwise
475 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
476 dlgTemplate
->style
|= DS_MODALFRAME
;
478 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
483 ret
= CreateFrame(title
, pos
, sizeReal
);
486 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
488 EnableCloseButton(false);
491 // for some reason we need to manually send ourselves this message as
492 // otherwise the mnemonics are always shown -- even if they're configured
493 // to be hidden until "Alt" is pressed in the control panel
495 // this could indicate a bug somewhere else but for now this is the only
503 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
511 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
513 if ( wxModelessWindows
.Find(this) )
514 wxModelessWindows
.DeleteObject(this);
516 // after destroying an owned window, Windows activates the next top level
517 // window in Z order but it may be different from our owner (to reproduce
518 // this simply Alt-TAB to another application and back before closing the
519 // owned frame) whereas we always want to yield activation to our parent
520 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
522 wxWindow
*parent
= GetParent();
525 ::BringWindowToTop(GetHwndOf(parent
));
530 // ----------------------------------------------------------------------------
531 // wxTopLevelWindowMSW showing
532 // ----------------------------------------------------------------------------
534 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
536 ::ShowWindow(GetHwnd(), nShowCmd
);
538 m_iconized
= nShowCmd
== SW_MINIMIZE
;
541 bool wxTopLevelWindowMSW::Show(bool show
)
543 // don't use wxWindow version as we want to call DoShowWindow() ourselves
544 if ( !wxWindowBase::Show(show
) )
550 if ( m_maximizeOnShow
)
553 nShowCmd
= SW_MAXIMIZE
;
555 m_maximizeOnShow
= FALSE
;
559 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
560 nShowCmd
= SW_SHOWNA
;
570 DoShowWindow(nShowCmd
);
574 ::BringWindowToTop(GetHwnd());
576 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
577 event
.SetEventObject( this );
578 GetEventHandler()->ProcessEvent(event
);
582 // Try to highlight the correct window (the parent)
585 HWND hWndParent
= GetHwndOf(GetParent());
587 ::BringWindowToTop(hWndParent
);
594 // ----------------------------------------------------------------------------
595 // wxTopLevelWindowMSW maximize/minimize
596 // ----------------------------------------------------------------------------
598 void wxTopLevelWindowMSW::Maximize(bool maximize
)
602 // just maximize it directly
603 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
607 // we can't maximize the hidden frame because it shows it as well, so
608 // just remember that we should do it later in this case
609 m_maximizeOnShow
= maximize
;
613 bool wxTopLevelWindowMSW::IsMaximized() const
618 return ::IsZoomed(GetHwnd()) != 0;
622 void wxTopLevelWindowMSW::Iconize(bool iconize
)
624 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
627 bool wxTopLevelWindowMSW::IsIconized() const
632 // also update the current state
633 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
639 void wxTopLevelWindowMSW::Restore()
641 DoShowWindow(SW_RESTORE
);
644 // ----------------------------------------------------------------------------
645 // wxTopLevelWindowMSW fullscreen
646 // ----------------------------------------------------------------------------
648 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
650 if ( show
== IsFullScreen() )
656 m_fsIsShowing
= show
;
662 // zap the frame borders
664 // save the 'normal' window style
665 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
667 // save the old position, width & height, maximize state
668 m_fsOldSize
= GetRect();
669 m_fsIsMaximized
= IsMaximized();
671 // decide which window style flags to turn off
672 LONG newStyle
= m_fsOldWindowStyle
;
675 if (style
& wxFULLSCREEN_NOBORDER
)
677 offFlags
|= WS_BORDER
;
679 offFlags
|= WS_THICKFRAME
;
682 if (style
& wxFULLSCREEN_NOCAPTION
)
683 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
685 newStyle
&= ~offFlags
;
687 // change our window style to be compatible with full-screen mode
688 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
692 // resize to the size of the display containing us
693 int dpy
= wxDisplay::GetFromWindow(this);
694 if ( dpy
!= wxNOT_FOUND
)
696 rect
= wxDisplay(dpy
).GetGeometry();
698 else // fall back to the main desktop
699 #else // wxUSE_DISPLAY
701 // resize to the size of the desktop
702 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
704 // FIXME: size of the bottom menu (toolbar)
705 // should be taken in account
706 rect
.height
+= rect
.y
;
710 #endif // wxUSE_DISPLAY
714 // now flush the window style cache and actually go full-screen
715 long flags
= SWP_FRAMECHANGED
;
717 // showing the frame full screen should also show it if it's still
721 // don't call wxWindow version to avoid flicker from calling
722 // ::ShowWindow() -- we're going to show the window at the correct
723 // location directly below -- but do call the wxWindowBase version
724 // to sync the internal m_isShown flag
725 wxWindowBase::Show();
727 flags
|= SWP_SHOWWINDOW
;
730 SetWindowPos(GetHwnd(), HWND_TOP
,
731 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
734 #if defined(__WXWINCE__) && _WIN32_WCE < 400
735 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
738 // finally send an event allowing the window to relayout itself &c
739 wxSizeEvent
event(rect
.GetSize(), GetId());
740 GetEventHandler()->ProcessEvent(event
);
742 else // stop showing full screen
744 #if defined(__WXWINCE__) && _WIN32_WCE < 400
745 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
747 Maximize(m_fsIsMaximized
);
748 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
749 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
750 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
756 // ----------------------------------------------------------------------------
757 // wxTopLevelWindowMSW misc
758 // ----------------------------------------------------------------------------
760 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
762 SetIcons( wxIconBundle( icon
) );
765 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
767 wxTopLevelWindowBase::SetIcons(icons
);
769 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
770 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
771 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
773 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
774 (LPARAM
)GetHiconOf(sml
) );
777 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
778 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
780 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
781 (LPARAM
)GetHiconOf(big
) );
786 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
788 #if !defined(__WXMICROWIN__)
789 // get system (a.k.a. window) menu
790 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
793 // no system menu at all -- ok if we want to remove the close button
794 // anyhow, but bad if we want to show it
798 // enabling/disabling the close item from it also automatically
799 // disables/enables the close title bar button
800 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
802 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
804 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
809 // update appearance immediately
810 if ( !::DrawMenuBar(GetHwnd()) )
812 wxLogLastError(_T("DrawMenuBar"));
814 #endif // !__WXMICROWIN__
821 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
823 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
824 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
826 // The empty region signifies that the shape should be removed from the
828 if ( region
.IsEmpty() )
830 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
832 wxLogLastError(_T("SetWindowRgn"));
838 // Windows takes ownership of the region, so
839 // we'll have to make a copy of the region to give to it.
840 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
841 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
842 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
843 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
844 delete[] (char*) rgnData
;
846 // SetWindowRgn expects the region to be in coordinants
847 // relative to the window, not the client area. Figure
848 // out the offset, if any.
850 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
851 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
852 ::GetClientRect(GetHwnd(), &rect
);
853 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
854 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
856 // Now call the shape API with the new region.
857 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
859 wxLogLastError(_T("SetWindowRgn"));
865 #endif // !__WXWINCE__
867 // ----------------------------------------------------------------------------
868 // wxTopLevelWindow event handling
869 // ----------------------------------------------------------------------------
871 // Default activation behaviour - set the focus for the first child
873 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
875 if ( event
.GetActive() )
877 // restore focus to the child which was last focused unless we already
879 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
881 wxWindow
*winFocus
= FindFocus();
882 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
884 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
891 wxSetFocusToChild(parent
, &m_winLastFocused
);
896 // remember the last focused child if it is our child
897 m_winLastFocused
= FindFocus();
899 if ( m_winLastFocused
)
901 // let it know that it doesn't have focus any more
902 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
904 // and don't remember it if it's a child from some other frame
905 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
907 m_winLastFocused
= NULL
;
911 wxLogTrace(_T("focus"),
912 _T("wxTLW %08x deactivated, last focused: %08x."),
914 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
921 // the DialogProc for all wxWindows dialogs
922 LONG APIENTRY _EXPORT
923 wxDlgProc(HWND
WXUNUSED(hDlg
),
925 WPARAM
WXUNUSED(wParam
),
926 LPARAM
WXUNUSED(lParam
))
931 // for this message, returning TRUE tells system to set focus to
932 // the first control in the dialog box, but as we set the focus
933 // ourselves, we return FALSE from here as well, so fall through
936 // for all the other ones, FALSE means that we didn't process the
942 // ============================================================================
943 // wxTLWHiddenParentModule implementation
944 // ============================================================================
946 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
948 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
950 bool wxTLWHiddenParentModule::OnInit()
958 void wxTLWHiddenParentModule::OnExit()
962 if ( !::DestroyWindow(ms_hwnd
) )
964 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
972 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
974 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
982 HWND
wxTLWHiddenParentModule::GetHWND()
988 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
991 wxZeroMemory(wndclass
);
993 wndclass
.lpfnWndProc
= DefWindowProc
;
994 wndclass
.hInstance
= wxGetInstance();
995 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
997 if ( !::RegisterClass(&wndclass
) )
999 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1003 ms_className
= HIDDEN_PARENT_CLASS
;
1007 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1008 (HMENU
)NULL
, wxGetInstance(), NULL
);
1011 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));