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 // This can't be undefed in winundef.h or
57 // there are further errors
58 #if defined(__WXWINCE__) && defined(CreateDialog)
62 #include "wx/display.h"
72 // ----------------------------------------------------------------------------
73 // stubs for missing functions under MicroWindows
74 // ----------------------------------------------------------------------------
78 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
79 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
81 #endif // __WXMICROWIN__
83 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
84 // is not included by wxUniv build which does need wxDlgProc
86 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // list of all frames and modeless dialogs
93 wxWindowList wxModelessWindows
;
95 // the name of the default wxWindows class
96 extern const wxChar
*wxCanvasClassName
;
98 // ----------------------------------------------------------------------------
99 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
100 // module to ensure that the window is always deleted)
101 // ----------------------------------------------------------------------------
103 class wxTLWHiddenParentModule
: public wxModule
106 // module init/finalize
107 virtual bool OnInit();
108 virtual void OnExit();
110 // get the hidden window (creates on demand)
111 static HWND
GetHWND();
114 // the HWND of the hidden parent
117 // the class used to create it
118 static const wxChar
*ms_className
;
120 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
123 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
125 // ============================================================================
126 // wxTopLevelWindowMSW implementation
127 // ============================================================================
129 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
130 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
133 // ----------------------------------------------------------------------------
134 // wxTopLevelWindowMSW creation
135 // ----------------------------------------------------------------------------
137 void wxTopLevelWindowMSW::Init()
140 m_maximizeOnShow
= FALSE
;
142 // Data to save/restore when calling ShowFullScreen
144 m_fsOldWindowStyle
= 0;
145 m_fsIsMaximized
= FALSE
;
146 m_fsIsShowing
= FALSE
;
148 m_winLastFocused
= (wxWindow
*)NULL
;
151 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
153 // let the base class deal with the common styles but fix the ones which
154 // don't make sense for us (we also deal with the borders ourselves)
155 WXDWORD msflags
= wxWindow::MSWGetStyle
157 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
158 ) & ~WS_CHILD
& ~WS_VISIBLE
;
160 // first select the kind of window being created
162 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
163 // creates a window with both caption and border, hence we also test it
164 // below in some other cases
165 if ( style
& wxFRAME_TOOL_WINDOW
)
170 if (msflags
& WS_BORDER
)
172 msflags
|= WS_OVERLAPPED
;
175 // border and caption styles
176 if ( style
& wxRESIZE_BORDER
)
179 msflags
|= WS_THICKFRAME
;
182 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
183 *exflags
|= WS_EX_DLGMODALFRAME
;
184 else if ( !(style
& wxBORDER_NONE
) )
185 msflags
|= WS_BORDER
;
191 if ( style
& wxCAPTION
)
192 msflags
|= WS_CAPTION
;
198 // next translate the individual flags
199 if ( style
& wxMINIMIZE_BOX
)
200 msflags
|= WS_MINIMIZEBOX
;
201 if ( style
& wxMAXIMIZE_BOX
)
202 msflags
|= WS_MAXIMIZEBOX
;
203 if ( style
& wxSYSTEM_MENU
)
204 msflags
|= WS_SYSMENU
;
206 if ( style
& wxMINIMIZE
)
207 msflags
|= WS_MINIMIZE
;
208 if ( style
& wxMAXIMIZE
)
209 msflags
|= WS_MAXIMIZE
;
212 // Keep this here because it saves recoding this function in wxTinyFrame
213 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
214 if ( style
& wxTINY_CAPTION_VERT
)
215 msflags
|= IBS_VERTCAPTION
;
216 if ( style
& wxTINY_CAPTION_HORIZ
)
217 msflags
|= IBS_HORZCAPTION
;
219 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
220 msflags
|= WS_CAPTION
;
225 #if !defined(__WIN16__)
226 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
228 if ( style
& wxFRAME_TOOL_WINDOW
)
230 // create the palette-like window
231 *exflags
|= WS_EX_TOOLWINDOW
;
233 // tool windows shouldn't appear on the taskbar (as documented)
234 style
|= wxFRAME_NO_TASKBAR
;
237 // We have to solve 2 different problems here:
239 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
240 // taskbar even if they don't have a parent
242 // 2. frames without this style should appear in the taskbar even
243 // if they're owned (Windows only puts non owned windows into
244 // the taskbar normally)
246 // The second one is solved here by using WS_EX_APPWINDOW flag, the
247 // first one is dealt with in our MSWGetParent() method
250 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
252 // need to force the frame to appear in the taskbar
253 *exflags
|= WS_EX_APPWINDOW
;
256 //else: nothing to do [here]
260 if ( style
& wxSTAY_ON_TOP
)
261 *exflags
|= WS_EX_TOPMOST
;
264 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
265 *exflags
|= WS_EX_CONTEXTHELP
;
272 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
274 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
275 // parent HWND or it would be always on top of its parent which is not what
276 // we usually want (in fact, we only want it for frames with the
277 // wxFRAME_FLOAT_ON_PARENT flag)
278 HWND hwndParent
= NULL
;
279 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
281 const wxWindow
*parent
= GetParent();
285 // this flag doesn't make sense then and will be ignored
286 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
290 hwndParent
= GetHwndOf(parent
);
293 //else: don't float on parent, must not be owned
295 // now deal with the 2nd taskbar-related problem (see comments above in
297 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
300 hwndParent
= wxTLWHiddenParentModule::GetHWND();
303 return (WXHWND
)hwndParent
;
306 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
307 const wxString
& title
,
311 #ifdef __WXMICROWIN__
312 // no dialogs support under MicroWin yet
313 return CreateFrame(title
, pos
, size
);
314 #else // !__WXMICROWIN__
315 wxWindow
*parent
= GetParent();
317 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
318 // app window as parent - this avoids creating modal dialogs without
320 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
322 parent
= wxTheApp
->GetTopWindow();
326 // don't use transient windows as parents, this is dangerous as it
327 // can lead to a crash if the parent is destroyed before the child
329 // also don't use the window which is currently hidden as then the
330 // dialog would be hidden as well
331 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
339 m_hWnd
= (WXHWND
)::CreateDialogIndirect
342 (DLGTEMPLATE
*)dlgTemplate
,
343 parent
? GetHwndOf(parent
) : NULL
,
349 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
351 wxLogSysError(wxT("Can't create dialog using memory template"));
357 (void)MSWGetCreateWindowFlags(&exflags
);
361 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
362 ::SetWindowPos(GetHwnd(),
363 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
367 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
371 #if defined(__WIN95__)
372 // For some reason, the system menu is activated when we use the
373 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
374 if ( exflags
& WS_EX_CONTEXTHELP
)
376 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
379 wxIcon icon
= winTop
->GetIcon();
382 ::SendMessage(GetHwnd(), WM_SETICON
,
384 (LPARAM
)GetHiconOf(icon
));
390 // move the dialog to its initial position without forcing repainting
392 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
394 if ( x
== (int)CW_USEDEFAULT
)
396 // centre it on the screen - what else can we do?
397 wxSize sizeDpy
= wxGetDisplaySize();
399 x
= (sizeDpy
.x
- w
) / 2;
400 y
= (sizeDpy
.y
- h
) / 2;
403 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
405 wxLogLastError(wxT("MoveWindow"));
408 if ( !title
.empty() )
410 ::SetWindowText(GetHwnd(), title
);
416 #endif // __WXMICROWIN__/!__WXMICROWIN__
419 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
424 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
426 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
429 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
431 const wxString
& title
,
435 const wxString
& name
)
437 bool ret
wxDUMMY_INITIALIZE(false);
442 w
= WidthDefault(size
.x
);
443 h
= HeightDefault(size
.y
);
445 m_windowStyle
= style
;
449 m_windowId
= id
== -1 ? NewControlId() : id
;
451 wxTopLevelWindows
.Append(this);
454 parent
->AddChild(this);
456 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
458 // we have different dialog templates to allows creation of dialogs
459 // with & without captions under MSWindows, resizeable or not (but a
460 // resizeable dialog always has caption - otherwise it would look too
463 // we need 3 additional WORDs for dialog menu, class and title (as we
464 // don't use DS_SETFONT we don't need the fourth WORD for the font)
465 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
466 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
467 memset(dlgTemplate
, 0, dlgsize
);
469 // these values are arbitrary, they won't be used normally anyhow
472 dlgTemplate
->cx
= 144;
473 dlgTemplate
->cy
= 75;
475 // reuse the code in MSWGetStyle() but correct the results slightly for
477 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
479 // all dialogs are popups
480 dlgTemplate
->style
|= WS_POPUP
;
482 // force 3D-look if necessary, it looks impossibly ugly otherwise
483 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
484 dlgTemplate
->style
|= DS_MODALFRAME
;
486 ret
= CreateDialog(dlgTemplate
, title
, pos
, wxSize(w
,h
));
491 ret
= CreateFrame(title
, pos
, wxSize(w
,h
));
494 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
496 EnableCloseButton(false);
499 // for some reason we need to manually send ourselves this message as
500 // otherwise the mnemonics are always shown -- even if they're configured
501 // to be hidden until "Alt" is pressed in the control panel
503 // this could indicate a bug somewhere else but for now this is the only
511 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
519 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
521 if ( wxModelessWindows
.Find(this) )
522 wxModelessWindows
.DeleteObject(this);
524 // after destroying an owned window, Windows activates the next top level
525 // window in Z order but it may be different from our owner (to reproduce
526 // this simply Alt-TAB to another application and back before closing the
527 // owned frame) whereas we always want to yield activation to our parent
528 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
530 wxWindow
*parent
= GetParent();
533 ::BringWindowToTop(GetHwndOf(parent
));
538 // ----------------------------------------------------------------------------
539 // wxTopLevelWindowMSW showing
540 // ----------------------------------------------------------------------------
542 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
544 ::ShowWindow(GetHwnd(), nShowCmd
);
546 m_iconized
= nShowCmd
== SW_MINIMIZE
;
549 bool wxTopLevelWindowMSW::Show(bool show
)
551 // don't use wxWindow version as we want to call DoShowWindow() ourselves
552 if ( !wxWindowBase::Show(show
) )
558 if ( m_maximizeOnShow
)
561 nShowCmd
= SW_MAXIMIZE
;
563 m_maximizeOnShow
= FALSE
;
567 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
568 nShowCmd
= SW_SHOWNA
;
578 DoShowWindow(nShowCmd
);
582 ::BringWindowToTop(GetHwnd());
584 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
585 event
.SetEventObject( this );
586 GetEventHandler()->ProcessEvent(event
);
590 // Try to highlight the correct window (the parent)
593 HWND hWndParent
= GetHwndOf(GetParent());
595 ::BringWindowToTop(hWndParent
);
602 // ----------------------------------------------------------------------------
603 // wxTopLevelWindowMSW maximize/minimize
604 // ----------------------------------------------------------------------------
606 void wxTopLevelWindowMSW::Maximize(bool maximize
)
610 // just maximize it directly
611 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
615 // we can't maximize the hidden frame because it shows it as well, so
616 // just remember that we should do it later in this case
617 m_maximizeOnShow
= maximize
;
621 bool wxTopLevelWindowMSW::IsMaximized() const
626 return ::IsZoomed(GetHwnd()) != 0;
630 void wxTopLevelWindowMSW::Iconize(bool iconize
)
632 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
635 bool wxTopLevelWindowMSW::IsIconized() const
640 // also update the current state
641 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
647 void wxTopLevelWindowMSW::Restore()
649 DoShowWindow(SW_RESTORE
);
652 // ----------------------------------------------------------------------------
653 // wxTopLevelWindowMSW fullscreen
654 // ----------------------------------------------------------------------------
656 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
658 if ( show
== IsFullScreen() )
664 m_fsIsShowing
= show
;
670 // zap the frame borders
672 // save the 'normal' window style
673 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
675 // save the old position, width & height, maximize state
676 m_fsOldSize
= GetRect();
677 m_fsIsMaximized
= IsMaximized();
679 // decide which window style flags to turn off
680 LONG newStyle
= m_fsOldWindowStyle
;
683 if (style
& wxFULLSCREEN_NOBORDER
)
685 offFlags
|= WS_BORDER
;
687 offFlags
|= WS_THICKFRAME
;
690 if (style
& wxFULLSCREEN_NOCAPTION
)
691 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
693 newStyle
&= ~offFlags
;
695 // change our window style to be compatible with full-screen mode
696 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
700 // resize to the size of the display containing us
701 int dpy
= wxDisplay::GetFromWindow(this);
702 if ( dpy
!= wxNOT_FOUND
)
704 rect
= wxDisplay(dpy
).GetGeometry();
706 else // fall back to the main desktop
707 #else // wxUSE_DISPLAY
709 // resize to the size of the desktop
710 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
712 // FIXME: size of the bottom menu (toolbar)
713 // should be taken in account
714 rect
.height
+= rect
.y
;
718 #endif // wxUSE_DISPLAY
722 // now flush the window style cache and actually go full-screen
723 long flags
= SWP_FRAMECHANGED
;
725 // showing the frame full screen should also show it if it's still
729 // don't call wxWindow version to avoid flicker from calling
730 // ::ShowWindow() -- we're going to show the window at the correct
731 // location directly below -- but do call the wxWindowBase version
732 // to sync the internal m_isShown flag
733 wxWindowBase::Show();
735 flags
|= SWP_SHOWWINDOW
;
738 SetWindowPos(GetHwnd(), HWND_TOP
,
739 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
742 #if defined(__WXWINCE__) && _WIN32_WCE < 400
743 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
746 // finally send an event allowing the window to relayout itself &c
747 wxSizeEvent
event(rect
.GetSize(), GetId());
748 GetEventHandler()->ProcessEvent(event
);
750 else // stop showing full screen
752 #if defined(__WXWINCE__) && _WIN32_WCE < 400
753 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
755 Maximize(m_fsIsMaximized
);
756 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
757 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
758 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
764 // ----------------------------------------------------------------------------
765 // wxTopLevelWindowMSW misc
766 // ----------------------------------------------------------------------------
768 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
770 SetIcons( wxIconBundle( icon
) );
773 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
775 wxTopLevelWindowBase::SetIcons(icons
);
777 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
778 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
779 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
781 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
782 (LPARAM
)GetHiconOf(sml
) );
785 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
786 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
788 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
789 (LPARAM
)GetHiconOf(big
) );
794 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
796 #if !defined(__WXMICROWIN__)
797 // get system (a.k.a. window) menu
798 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
801 // no system menu at all -- ok if we want to remove the close button
802 // anyhow, but bad if we want to show it
806 // enabling/disabling the close item from it also automatically
807 // disables/enables the close title bar button
808 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
810 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
812 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
817 // update appearance immediately
818 if ( !::DrawMenuBar(GetHwnd()) )
820 wxLogLastError(_T("DrawMenuBar"));
822 #endif // !__WXMICROWIN__
827 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
832 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
833 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
835 // The empty region signifies that the shape should be removed from the
837 if ( region
.IsEmpty() )
839 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
841 wxLogLastError(_T("SetWindowRgn"));
847 // Windows takes ownership of the region, so
848 // we'll have to make a copy of the region to give to it.
849 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
850 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
851 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
852 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
853 delete[] (char*) rgnData
;
855 // SetWindowRgn expects the region to be in coordinants
856 // relative to the window, not the client area. Figure
857 // out the offset, if any.
859 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
860 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
861 ::GetClientRect(GetHwnd(), &rect
);
862 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
863 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
865 // Now call the shape API with the new region.
866 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
868 wxLogLastError(_T("SetWindowRgn"));
875 // ----------------------------------------------------------------------------
876 // wxTopLevelWindow event handling
877 // ----------------------------------------------------------------------------
879 // Default activation behaviour - set the focus for the first child
881 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
883 if ( event
.GetActive() )
885 // restore focus to the child which was last focused unless we already
887 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
889 wxWindow
*winFocus
= FindFocus();
890 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
892 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
899 wxSetFocusToChild(parent
, &m_winLastFocused
);
904 // remember the last focused child if it is our child
905 m_winLastFocused
= FindFocus();
907 if ( m_winLastFocused
)
909 // let it know that it doesn't have focus any more
910 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
912 // and don't remember it if it's a child from some other frame
913 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
915 m_winLastFocused
= NULL
;
919 wxLogTrace(_T("focus"),
920 _T("wxTLW %08x deactivated, last focused: %08x."),
922 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
929 // the DialogProc for all wxWindows dialogs
930 LONG APIENTRY _EXPORT
931 wxDlgProc(HWND
WXUNUSED(hDlg
),
933 WPARAM
WXUNUSED(wParam
),
934 LPARAM
WXUNUSED(lParam
))
939 // for this message, returning TRUE tells system to set focus to
940 // the first control in the dialog box, but as we set the focus
941 // ourselves, we return FALSE from here as well, so fall through
944 // for all the other ones, FALSE means that we didn't process the
950 // ============================================================================
951 // wxTLWHiddenParentModule implementation
952 // ============================================================================
954 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
956 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
958 bool wxTLWHiddenParentModule::OnInit()
966 void wxTLWHiddenParentModule::OnExit()
970 if ( !::DestroyWindow(ms_hwnd
) )
972 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
980 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
982 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
990 HWND
wxTLWHiddenParentModule::GetHWND()
996 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
999 wxZeroMemory(wndclass
);
1001 wndclass
.lpfnWndProc
= DefWindowProc
;
1002 wndclass
.hInstance
= wxGetInstance();
1003 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1005 if ( !::RegisterClass(&wndclass
) )
1007 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1011 ms_className
= HIDDEN_PARENT_CLASS
;
1015 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1016 (HMENU
)NULL
, wxGetInstance(), NULL
);
1019 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));