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/dialog.h"
35 #include "wx/string.h"
39 #include "wx/containr.h" // wxSetFocusToChild()
42 #include "wx/module.h"
44 #include "wx/msw/private.h"
45 #if defined(__WXWINCE__)
51 #include "wx/msw/wince/missing.h"
54 #include "wx/msw/missing.h"
55 #include "wx/msw/winundef.h"
57 #include "wx/display.h"
67 // ----------------------------------------------------------------------------
68 // stubs for missing functions under MicroWindows
69 // ----------------------------------------------------------------------------
73 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
74 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
76 #endif // __WXMICROWIN__
78 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
79 // is not included by wxUniv build which does need wxDlgProc
81 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // list of all frames and modeless dialogs
88 wxWindowList wxModelessWindows
;
90 // the name of the default wxWindows class
91 extern const wxChar
*wxCanvasClassName
;
93 // ----------------------------------------------------------------------------
94 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
95 // module to ensure that the window is always deleted)
96 // ----------------------------------------------------------------------------
98 class wxTLWHiddenParentModule
: public wxModule
101 // module init/finalize
102 virtual bool OnInit();
103 virtual void OnExit();
105 // get the hidden window (creates on demand)
106 static HWND
GetHWND();
109 // the HWND of the hidden parent
112 // the class used to create it
113 static const wxChar
*ms_className
;
115 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
118 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
120 // ============================================================================
121 // wxTopLevelWindowMSW implementation
122 // ============================================================================
124 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
125 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
128 // ----------------------------------------------------------------------------
129 // wxTopLevelWindowMSW creation
130 // ----------------------------------------------------------------------------
132 void wxTopLevelWindowMSW::Init()
135 m_maximizeOnShow
= FALSE
;
137 // Data to save/restore when calling ShowFullScreen
139 m_fsOldWindowStyle
= 0;
140 m_fsIsMaximized
= FALSE
;
141 m_fsIsShowing
= FALSE
;
143 m_winLastFocused
= (wxWindow
*)NULL
;
146 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
148 // let the base class deal with the common styles but fix the ones which
149 // don't make sense for us (we also deal with the borders ourselves)
150 WXDWORD msflags
= wxWindow::MSWGetStyle
152 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
153 ) & ~WS_CHILD
& ~WS_VISIBLE
;
155 #if defined(__WXWINCE__) && _WIN32_WCE < 400
156 msflags
|= WS_VISIBLE
;
159 // first select the kind of window being created
161 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
162 // creates a window with both caption and border, hence we also test it
163 // below in some other cases
164 if ( style
& wxFRAME_TOOL_WINDOW
)
168 //else: WS_OVERLAPPED is 0 anyhow, so it is on by default
170 // border and caption styles
171 if ( style
& wxRESIZE_BORDER
)
172 msflags
|= WS_THICKFRAME
;
173 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
174 *exflags
|= WS_EX_DLGMODALFRAME
;
175 else if ( !(style
& wxBORDER_NONE
) )
176 msflags
|= WS_BORDER
;
180 // normally we consider that all windows without caption must be popups,
181 // but CE is an exception: there windows normally do not have the caption
182 // but shouldn't be made popups as popups can't have menus and don't look
183 // like normal windows anyhow
184 if ( style
& wxCAPTION
)
185 msflags
|= WS_CAPTION
;
189 #endif // !__WXWINCE__
191 // next translate the individual flags
192 if ( style
& wxMINIMIZE_BOX
)
193 msflags
|= WS_MINIMIZEBOX
;
194 if ( style
& wxMAXIMIZE_BOX
)
195 msflags
|= WS_MAXIMIZEBOX
;
196 if ( style
& wxSYSTEM_MENU
)
197 msflags
|= WS_SYSMENU
;
199 // NB: under CE these 2 styles are not supported currently, we should
200 // call Minimize()/Maximize() "manually" if we want to support them
201 if ( style
& wxMINIMIZE
)
202 msflags
|= WS_MINIMIZE
;
203 if ( style
& wxMAXIMIZE
)
204 msflags
|= WS_MAXIMIZE
;
206 // Keep this here because it saves recoding this function in wxTinyFrame
207 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
208 msflags
|= WS_CAPTION
;
212 // there is no taskbar under CE, so omit all this
214 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
216 if ( style
& wxFRAME_TOOL_WINDOW
)
218 // create the palette-like window
219 *exflags
|= WS_EX_TOOLWINDOW
;
221 // tool windows shouldn't appear on the taskbar (as documented)
222 style
|= wxFRAME_NO_TASKBAR
;
225 // We have to solve 2 different problems here:
227 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
228 // taskbar even if they don't have a parent
230 // 2. frames without this style should appear in the taskbar even
231 // if they're owned (Windows only puts non owned windows into
232 // the taskbar normally)
234 // The second one is solved here by using WS_EX_APPWINDOW flag, the
235 // first one is dealt with in our MSWGetParent() method
237 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
239 // need to force the frame to appear in the taskbar
240 *exflags
|= WS_EX_APPWINDOW
;
242 //else: nothing to do [here]
244 #endif // !__WXWINCE__
246 if ( style
& wxSTAY_ON_TOP
)
247 *exflags
|= WS_EX_TOPMOST
;
249 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
250 *exflags
|= WS_EX_CONTEXTHELP
;
256 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
258 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
259 // parent HWND or it would be always on top of its parent which is not what
260 // we usually want (in fact, we only want it for frames with the
261 // wxFRAME_FLOAT_ON_PARENT flag)
262 HWND hwndParent
= NULL
;
263 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
265 const wxWindow
*parent
= GetParent();
269 // this flag doesn't make sense then and will be ignored
270 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
274 hwndParent
= GetHwndOf(parent
);
277 //else: don't float on parent, must not be owned
279 // now deal with the 2nd taskbar-related problem (see comments above in
281 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
284 hwndParent
= wxTLWHiddenParentModule::GetHWND();
287 return (WXHWND
)hwndParent
;
290 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
291 const wxString
& title
,
295 #ifdef __WXMICROWIN__
296 // no dialogs support under MicroWin yet
297 return CreateFrame(title
, pos
, size
);
298 #else // !__WXMICROWIN__
299 wxWindow
*parent
= GetParent();
301 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
302 // app window as parent - this avoids creating modal dialogs without
304 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
306 parent
= wxTheApp
->GetTopWindow();
310 // don't use transient windows as parents, this is dangerous as it
311 // can lead to a crash if the parent is destroyed before the child
313 // also don't use the window which is currently hidden as then the
314 // dialog would be hidden as well
315 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
323 m_hWnd
= (WXHWND
)::CreateDialogIndirect
326 (DLGTEMPLATE
*)dlgTemplate
,
327 parent
? GetHwndOf(parent
) : NULL
,
333 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
335 wxLogSysError(wxT("Can't create dialog using memory template"));
341 (void)MSWGetCreateWindowFlags(&exflags
);
345 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
346 ::SetWindowPos(GetHwnd(),
347 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
351 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
355 #if defined(__WIN95__)
356 // For some reason, the system menu is activated when we use the
357 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
358 if ( exflags
& WS_EX_CONTEXTHELP
)
360 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
363 wxIcon icon
= winTop
->GetIcon();
366 ::SendMessage(GetHwnd(), WM_SETICON
,
368 (LPARAM
)GetHiconOf(icon
));
374 // move the dialog to its initial position without forcing repainting
376 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
378 if ( x
== (int)CW_USEDEFAULT
)
380 // centre it on the screen - what else can we do?
381 wxSize sizeDpy
= wxGetDisplaySize();
383 x
= (sizeDpy
.x
- w
) / 2;
384 y
= (sizeDpy
.y
- h
) / 2;
387 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
389 wxLogLastError(wxT("MoveWindow"));
392 if ( !title
.empty() )
394 ::SetWindowText(GetHwnd(), title
);
400 #endif // __WXMICROWIN__/!__WXMICROWIN__
403 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
408 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
410 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
413 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
415 const wxString
& title
,
419 const wxString
& name
)
421 bool ret
wxDUMMY_INITIALIZE(false);
426 wxSize sizeReal
= size
;
427 if ( !sizeReal
.IsFullySpecified() )
429 sizeReal
.SetDefaults(GetDefaultSize());
432 m_windowStyle
= style
;
436 m_windowId
= id
== -1 ? NewControlId() : id
;
438 wxTopLevelWindows
.Append(this);
441 parent
->AddChild(this);
443 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
445 // we have different dialog templates to allows creation of dialogs
446 // with & without captions under MSWindows, resizeable or not (but a
447 // resizeable dialog always has caption - otherwise it would look too
450 // we need 3 additional WORDs for dialog menu, class and title (as we
451 // don't use DS_SETFONT we don't need the fourth WORD for the font)
452 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
453 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
454 memset(dlgTemplate
, 0, dlgsize
);
456 // these values are arbitrary, they won't be used normally anyhow
459 dlgTemplate
->cx
= 144;
460 dlgTemplate
->cy
= 75;
462 // reuse the code in MSWGetStyle() but correct the results slightly for
464 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
466 // all dialogs are popups
467 dlgTemplate
->style
|= WS_POPUP
;
469 // force 3D-look if necessary, it looks impossibly ugly otherwise
470 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
471 dlgTemplate
->style
|= DS_MODALFRAME
;
473 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
478 ret
= CreateFrame(title
, pos
, sizeReal
);
481 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
483 EnableCloseButton(false);
486 // for some reason we need to manually send ourselves this message as
487 // otherwise the mnemonics are always shown -- even if they're configured
488 // to be hidden until "Alt" is pressed in the control panel
490 // this could indicate a bug somewhere else but for now this is the only
498 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
506 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
508 if ( wxModelessWindows
.Find(this) )
509 wxModelessWindows
.DeleteObject(this);
511 // after destroying an owned window, Windows activates the next top level
512 // window in Z order but it may be different from our owner (to reproduce
513 // this simply Alt-TAB to another application and back before closing the
514 // owned frame) whereas we always want to yield activation to our parent
515 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
517 wxWindow
*parent
= GetParent();
520 ::BringWindowToTop(GetHwndOf(parent
));
525 // ----------------------------------------------------------------------------
526 // wxTopLevelWindowMSW showing
527 // ----------------------------------------------------------------------------
529 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
531 ::ShowWindow(GetHwnd(), nShowCmd
);
533 m_iconized
= nShowCmd
== SW_MINIMIZE
;
536 bool wxTopLevelWindowMSW::Show(bool show
)
538 // don't use wxWindow version as we want to call DoShowWindow() ourselves
539 if ( !wxWindowBase::Show(show
) )
545 if ( m_maximizeOnShow
)
548 nShowCmd
= SW_MAXIMIZE
;
550 m_maximizeOnShow
= FALSE
;
554 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
555 nShowCmd
= SW_SHOWNA
;
565 DoShowWindow(nShowCmd
);
569 ::BringWindowToTop(GetHwnd());
571 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
572 event
.SetEventObject( this );
573 GetEventHandler()->ProcessEvent(event
);
577 // Try to highlight the correct window (the parent)
580 HWND hWndParent
= GetHwndOf(GetParent());
582 ::BringWindowToTop(hWndParent
);
589 // ----------------------------------------------------------------------------
590 // wxTopLevelWindowMSW maximize/minimize
591 // ----------------------------------------------------------------------------
593 void wxTopLevelWindowMSW::Maximize(bool maximize
)
597 // just maximize it directly
598 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
602 // we can't maximize the hidden frame because it shows it as well, so
603 // just remember that we should do it later in this case
604 m_maximizeOnShow
= maximize
;
608 bool wxTopLevelWindowMSW::IsMaximized() const
613 return ::IsZoomed(GetHwnd()) != 0;
617 void wxTopLevelWindowMSW::Iconize(bool iconize
)
619 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
622 bool wxTopLevelWindowMSW::IsIconized() const
627 // also update the current state
628 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
634 void wxTopLevelWindowMSW::Restore()
636 DoShowWindow(SW_RESTORE
);
639 // ----------------------------------------------------------------------------
640 // wxTopLevelWindowMSW fullscreen
641 // ----------------------------------------------------------------------------
643 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
645 if ( show
== IsFullScreen() )
651 m_fsIsShowing
= show
;
657 // zap the frame borders
659 // save the 'normal' window style
660 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
662 // save the old position, width & height, maximize state
663 m_fsOldSize
= GetRect();
664 m_fsIsMaximized
= IsMaximized();
666 // decide which window style flags to turn off
667 LONG newStyle
= m_fsOldWindowStyle
;
670 if (style
& wxFULLSCREEN_NOBORDER
)
672 offFlags
|= WS_BORDER
;
674 offFlags
|= WS_THICKFRAME
;
677 if (style
& wxFULLSCREEN_NOCAPTION
)
678 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
680 newStyle
&= ~offFlags
;
682 // change our window style to be compatible with full-screen mode
683 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
687 // resize to the size of the display containing us
688 int dpy
= wxDisplay::GetFromWindow(this);
689 if ( dpy
!= wxNOT_FOUND
)
691 rect
= wxDisplay(dpy
).GetGeometry();
693 else // fall back to the main desktop
694 #else // wxUSE_DISPLAY
696 // resize to the size of the desktop
697 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
699 // FIXME: size of the bottom menu (toolbar)
700 // should be taken in account
701 rect
.height
+= rect
.y
;
705 #endif // wxUSE_DISPLAY
709 // now flush the window style cache and actually go full-screen
710 long flags
= SWP_FRAMECHANGED
;
712 // showing the frame full screen should also show it if it's still
716 // don't call wxWindow version to avoid flicker from calling
717 // ::ShowWindow() -- we're going to show the window at the correct
718 // location directly below -- but do call the wxWindowBase version
719 // to sync the internal m_isShown flag
720 wxWindowBase::Show();
722 flags
|= SWP_SHOWWINDOW
;
725 SetWindowPos(GetHwnd(), HWND_TOP
,
726 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
729 #if defined(__WXWINCE__) && _WIN32_WCE < 400
730 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
733 // finally send an event allowing the window to relayout itself &c
734 wxSizeEvent
event(rect
.GetSize(), GetId());
735 GetEventHandler()->ProcessEvent(event
);
737 else // stop showing full screen
739 #if defined(__WXWINCE__) && _WIN32_WCE < 400
740 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
742 Maximize(m_fsIsMaximized
);
743 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
744 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
745 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
751 // ----------------------------------------------------------------------------
752 // wxTopLevelWindowMSW misc
753 // ----------------------------------------------------------------------------
755 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
757 SetIcons( wxIconBundle( icon
) );
760 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
762 wxTopLevelWindowBase::SetIcons(icons
);
764 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
765 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
766 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
768 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
769 (LPARAM
)GetHiconOf(sml
) );
772 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
773 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
775 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
776 (LPARAM
)GetHiconOf(big
) );
781 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
783 #if !defined(__WXMICROWIN__)
784 // get system (a.k.a. window) menu
785 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
788 // no system menu at all -- ok if we want to remove the close button
789 // anyhow, but bad if we want to show it
793 // enabling/disabling the close item from it also automatically
794 // disables/enables the close title bar button
795 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
797 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
799 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
804 // update appearance immediately
805 if ( !::DrawMenuBar(GetHwnd()) )
807 wxLogLastError(_T("DrawMenuBar"));
809 #endif // !__WXMICROWIN__
816 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
818 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
819 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
821 // The empty region signifies that the shape should be removed from the
823 if ( region
.IsEmpty() )
825 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
827 wxLogLastError(_T("SetWindowRgn"));
833 // Windows takes ownership of the region, so
834 // we'll have to make a copy of the region to give to it.
835 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
836 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
837 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
838 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
839 delete[] (char*) rgnData
;
841 // SetWindowRgn expects the region to be in coordinants
842 // relative to the window, not the client area. Figure
843 // out the offset, if any.
845 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
846 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
847 ::GetClientRect(GetHwnd(), &rect
);
848 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
849 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
851 // Now call the shape API with the new region.
852 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
854 wxLogLastError(_T("SetWindowRgn"));
860 #endif // !__WXWINCE__
862 // ----------------------------------------------------------------------------
863 // wxTopLevelWindow event handling
864 // ----------------------------------------------------------------------------
866 // Default activation behaviour - set the focus for the first child
868 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
870 if ( event
.GetActive() )
872 // restore focus to the child which was last focused unless we already
874 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
876 wxWindow
*winFocus
= FindFocus();
877 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
879 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
886 wxSetFocusToChild(parent
, &m_winLastFocused
);
891 // remember the last focused child if it is our child
892 m_winLastFocused
= FindFocus();
894 if ( m_winLastFocused
)
896 // let it know that it doesn't have focus any more
897 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
899 // and don't remember it if it's a child from some other frame
900 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
902 m_winLastFocused
= NULL
;
906 wxLogTrace(_T("focus"),
907 _T("wxTLW %08x deactivated, last focused: %08x."),
909 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
916 // the DialogProc for all wxWindows dialogs
917 LONG APIENTRY _EXPORT
918 wxDlgProc(HWND
WXUNUSED(hDlg
),
920 WPARAM
WXUNUSED(wParam
),
921 LPARAM
WXUNUSED(lParam
))
926 // for this message, returning TRUE tells system to set focus to
927 // the first control in the dialog box, but as we set the focus
928 // ourselves, we return FALSE from here as well, so fall through
931 // for all the other ones, FALSE means that we didn't process the
937 // ============================================================================
938 // wxTLWHiddenParentModule implementation
939 // ============================================================================
941 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
943 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
945 bool wxTLWHiddenParentModule::OnInit()
953 void wxTLWHiddenParentModule::OnExit()
957 if ( !::DestroyWindow(ms_hwnd
) )
959 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
967 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
969 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
977 HWND
wxTLWHiddenParentModule::GetHWND()
983 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
986 wxZeroMemory(wndclass
);
988 wndclass
.lpfnWndProc
= DefWindowProc
;
989 wndclass
.hInstance
= wxGetInstance();
990 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
992 if ( !::RegisterClass(&wndclass
) )
994 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
998 ms_className
= HIDDEN_PARENT_CLASS
;
1002 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1003 (HMENU
)NULL
, wxGetInstance(), NULL
);
1006 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));