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 //else: WS_OVERLAPPED is 0 anyhow, so it is on by default
165 // border and caption styles
166 if ( style
& wxRESIZE_BORDER
)
167 msflags
|= WS_THICKFRAME
;
168 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
169 *exflags
|= WS_EX_DLGMODALFRAME
;
170 else if ( !(style
& wxBORDER_NONE
) )
171 msflags
|= WS_BORDER
;
175 // normally we consider that all windows without caption must be popups,
176 // but CE is an exception: there windows normally do not have the caption
177 // but shouldn't be made popups as popups can't have menus and don't look
178 // like normal windows anyhow
179 if ( style
& wxCAPTION
)
180 msflags
|= WS_CAPTION
;
184 #endif // !__WXWINCE__
186 // next translate the individual flags
187 if ( style
& wxMINIMIZE_BOX
)
188 msflags
|= WS_MINIMIZEBOX
;
189 if ( style
& wxMAXIMIZE_BOX
)
190 msflags
|= WS_MAXIMIZEBOX
;
191 if ( style
& wxSYSTEM_MENU
)
192 msflags
|= WS_SYSMENU
;
194 // NB: under CE these 2 styles are not supported currently, we should
195 // call Minimize()/Maximize() "manually" if we want to support them
196 if ( style
& wxMINIMIZE
)
197 msflags
|= WS_MINIMIZE
;
198 if ( style
& wxMAXIMIZE
)
199 msflags
|= WS_MAXIMIZE
;
201 // Keep this here because it saves recoding this function in wxTinyFrame
202 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
203 msflags
|= WS_CAPTION
;
207 // there is no taskbar under CE, so omit all this
209 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
211 if ( style
& wxFRAME_TOOL_WINDOW
)
213 // create the palette-like window
214 *exflags
|= WS_EX_TOOLWINDOW
;
216 // tool windows shouldn't appear on the taskbar (as documented)
217 style
|= wxFRAME_NO_TASKBAR
;
220 // We have to solve 2 different problems here:
222 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
223 // taskbar even if they don't have a parent
225 // 2. frames without this style should appear in the taskbar even
226 // if they're owned (Windows only puts non owned windows into
227 // the taskbar normally)
229 // The second one is solved here by using WS_EX_APPWINDOW flag, the
230 // first one is dealt with in our MSWGetParent() method
232 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
234 // need to force the frame to appear in the taskbar
235 *exflags
|= WS_EX_APPWINDOW
;
237 //else: nothing to do [here]
239 #endif // !__WXWINCE__
241 if ( style
& wxSTAY_ON_TOP
)
242 *exflags
|= WS_EX_TOPMOST
;
244 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
245 *exflags
|= WS_EX_CONTEXTHELP
;
251 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
253 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
254 // parent HWND or it would be always on top of its parent which is not what
255 // we usually want (in fact, we only want it for frames with the
256 // wxFRAME_FLOAT_ON_PARENT flag)
257 HWND hwndParent
= NULL
;
258 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
260 const wxWindow
*parent
= GetParent();
264 // this flag doesn't make sense then and will be ignored
265 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
269 hwndParent
= GetHwndOf(parent
);
272 //else: don't float on parent, must not be owned
274 // now deal with the 2nd taskbar-related problem (see comments above in
276 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
279 hwndParent
= wxTLWHiddenParentModule::GetHWND();
282 return (WXHWND
)hwndParent
;
285 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
286 const wxString
& title
,
290 #ifdef __WXMICROWIN__
291 // no dialogs support under MicroWin yet
292 return CreateFrame(title
, pos
, size
);
293 #else // !__WXMICROWIN__
294 wxWindow
*parent
= GetParent();
296 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
297 // app window as parent - this avoids creating modal dialogs without
299 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
301 parent
= wxTheApp
->GetTopWindow();
305 // don't use transient windows as parents, this is dangerous as it
306 // can lead to a crash if the parent is destroyed before the child
308 // also don't use the window which is currently hidden as then the
309 // dialog would be hidden as well
310 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
318 m_hWnd
= (WXHWND
)::CreateDialogIndirect
321 (DLGTEMPLATE
*)dlgTemplate
,
322 parent
? GetHwndOf(parent
) : NULL
,
328 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
330 wxLogSysError(wxT("Can't create dialog using memory template"));
336 (void)MSWGetCreateWindowFlags(&exflags
);
340 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
341 ::SetWindowPos(GetHwnd(),
342 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
346 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
350 #if defined(__WIN95__)
351 // For some reason, the system menu is activated when we use the
352 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
353 if ( exflags
& WS_EX_CONTEXTHELP
)
355 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
358 wxIcon icon
= winTop
->GetIcon();
361 ::SendMessage(GetHwnd(), WM_SETICON
,
363 (LPARAM
)GetHiconOf(icon
));
369 // move the dialog to its initial position without forcing repainting
371 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
373 if ( x
== (int)CW_USEDEFAULT
)
375 // centre it on the screen - what else can we do?
376 wxSize sizeDpy
= wxGetDisplaySize();
378 x
= (sizeDpy
.x
- w
) / 2;
379 y
= (sizeDpy
.y
- h
) / 2;
382 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
384 wxLogLastError(wxT("MoveWindow"));
387 if ( !title
.empty() )
389 ::SetWindowText(GetHwnd(), title
);
395 #endif // __WXMICROWIN__/!__WXMICROWIN__
398 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
403 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
405 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
408 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
410 const wxString
& title
,
414 const wxString
& name
)
416 bool ret
wxDUMMY_INITIALIZE(false);
421 wxSize sizeReal
= size
;
422 if ( !sizeReal
.IsFullySpecified() )
424 sizeReal
.SetDefaults(GetDefaultSize());
427 m_windowStyle
= style
;
431 m_windowId
= id
== -1 ? NewControlId() : id
;
433 wxTopLevelWindows
.Append(this);
436 parent
->AddChild(this);
438 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
440 // we have different dialog templates to allows creation of dialogs
441 // with & without captions under MSWindows, resizeable or not (but a
442 // resizeable dialog always has caption - otherwise it would look too
445 // we need 3 additional WORDs for dialog menu, class and title (as we
446 // don't use DS_SETFONT we don't need the fourth WORD for the font)
447 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
448 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
449 memset(dlgTemplate
, 0, dlgsize
);
451 // these values are arbitrary, they won't be used normally anyhow
454 dlgTemplate
->cx
= 144;
455 dlgTemplate
->cy
= 75;
457 // reuse the code in MSWGetStyle() but correct the results slightly for
459 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
461 // all dialogs are popups
462 dlgTemplate
->style
|= WS_POPUP
;
464 // force 3D-look if necessary, it looks impossibly ugly otherwise
465 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
466 dlgTemplate
->style
|= DS_MODALFRAME
;
468 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
473 ret
= CreateFrame(title
, pos
, sizeReal
);
476 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
478 EnableCloseButton(false);
481 // for some reason we need to manually send ourselves this message as
482 // otherwise the mnemonics are always shown -- even if they're configured
483 // to be hidden until "Alt" is pressed in the control panel
485 // this could indicate a bug somewhere else but for now this is the only
493 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
501 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
503 if ( wxModelessWindows
.Find(this) )
504 wxModelessWindows
.DeleteObject(this);
506 // after destroying an owned window, Windows activates the next top level
507 // window in Z order but it may be different from our owner (to reproduce
508 // this simply Alt-TAB to another application and back before closing the
509 // owned frame) whereas we always want to yield activation to our parent
510 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
512 wxWindow
*parent
= GetParent();
515 ::BringWindowToTop(GetHwndOf(parent
));
520 // ----------------------------------------------------------------------------
521 // wxTopLevelWindowMSW showing
522 // ----------------------------------------------------------------------------
524 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
526 ::ShowWindow(GetHwnd(), nShowCmd
);
528 m_iconized
= nShowCmd
== SW_MINIMIZE
;
531 bool wxTopLevelWindowMSW::Show(bool show
)
533 // don't use wxWindow version as we want to call DoShowWindow() ourselves
534 if ( !wxWindowBase::Show(show
) )
540 if ( m_maximizeOnShow
)
543 nShowCmd
= SW_MAXIMIZE
;
545 m_maximizeOnShow
= FALSE
;
549 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
550 nShowCmd
= SW_SHOWNA
;
560 DoShowWindow(nShowCmd
);
564 ::BringWindowToTop(GetHwnd());
566 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
567 event
.SetEventObject( this );
568 GetEventHandler()->ProcessEvent(event
);
572 // Try to highlight the correct window (the parent)
575 HWND hWndParent
= GetHwndOf(GetParent());
577 ::BringWindowToTop(hWndParent
);
584 // ----------------------------------------------------------------------------
585 // wxTopLevelWindowMSW maximize/minimize
586 // ----------------------------------------------------------------------------
588 void wxTopLevelWindowMSW::Maximize(bool maximize
)
592 // just maximize it directly
593 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
597 // we can't maximize the hidden frame because it shows it as well, so
598 // just remember that we should do it later in this case
599 m_maximizeOnShow
= maximize
;
603 bool wxTopLevelWindowMSW::IsMaximized() const
608 return ::IsZoomed(GetHwnd()) != 0;
612 void wxTopLevelWindowMSW::Iconize(bool iconize
)
614 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
617 bool wxTopLevelWindowMSW::IsIconized() const
622 // also update the current state
623 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
629 void wxTopLevelWindowMSW::Restore()
631 DoShowWindow(SW_RESTORE
);
634 // ----------------------------------------------------------------------------
635 // wxTopLevelWindowMSW fullscreen
636 // ----------------------------------------------------------------------------
638 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
640 if ( show
== IsFullScreen() )
646 m_fsIsShowing
= show
;
652 // zap the frame borders
654 // save the 'normal' window style
655 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
657 // save the old position, width & height, maximize state
658 m_fsOldSize
= GetRect();
659 m_fsIsMaximized
= IsMaximized();
661 // decide which window style flags to turn off
662 LONG newStyle
= m_fsOldWindowStyle
;
665 if (style
& wxFULLSCREEN_NOBORDER
)
667 offFlags
|= WS_BORDER
;
669 offFlags
|= WS_THICKFRAME
;
672 if (style
& wxFULLSCREEN_NOCAPTION
)
673 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
675 newStyle
&= ~offFlags
;
677 // change our window style to be compatible with full-screen mode
678 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
682 // resize to the size of the display containing us
683 int dpy
= wxDisplay::GetFromWindow(this);
684 if ( dpy
!= wxNOT_FOUND
)
686 rect
= wxDisplay(dpy
).GetGeometry();
688 else // fall back to the main desktop
689 #else // wxUSE_DISPLAY
691 // resize to the size of the desktop
692 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
694 // FIXME: size of the bottom menu (toolbar)
695 // should be taken in account
696 rect
.height
+= rect
.y
;
700 #endif // wxUSE_DISPLAY
704 // now flush the window style cache and actually go full-screen
705 long flags
= SWP_FRAMECHANGED
;
707 // showing the frame full screen should also show it if it's still
711 // don't call wxWindow version to avoid flicker from calling
712 // ::ShowWindow() -- we're going to show the window at the correct
713 // location directly below -- but do call the wxWindowBase version
714 // to sync the internal m_isShown flag
715 wxWindowBase::Show();
717 flags
|= SWP_SHOWWINDOW
;
720 SetWindowPos(GetHwnd(), HWND_TOP
,
721 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
724 #if defined(__WXWINCE__) && _WIN32_WCE < 400
725 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
728 // finally send an event allowing the window to relayout itself &c
729 wxSizeEvent
event(rect
.GetSize(), GetId());
730 GetEventHandler()->ProcessEvent(event
);
732 else // stop showing full screen
734 #if defined(__WXWINCE__) && _WIN32_WCE < 400
735 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
737 Maximize(m_fsIsMaximized
);
738 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
739 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
740 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
746 // ----------------------------------------------------------------------------
747 // wxTopLevelWindowMSW misc
748 // ----------------------------------------------------------------------------
750 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
752 SetIcons( wxIconBundle( icon
) );
755 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
757 wxTopLevelWindowBase::SetIcons(icons
);
759 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
760 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
761 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
763 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
764 (LPARAM
)GetHiconOf(sml
) );
767 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
768 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
770 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
771 (LPARAM
)GetHiconOf(big
) );
776 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
778 #if !defined(__WXMICROWIN__)
779 // get system (a.k.a. window) menu
780 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
783 // no system menu at all -- ok if we want to remove the close button
784 // anyhow, but bad if we want to show it
788 // enabling/disabling the close item from it also automatically
789 // disables/enables the close title bar button
790 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
792 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
794 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
799 // update appearance immediately
800 if ( !::DrawMenuBar(GetHwnd()) )
802 wxLogLastError(_T("DrawMenuBar"));
804 #endif // !__WXMICROWIN__
811 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
813 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
814 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
816 // The empty region signifies that the shape should be removed from the
818 if ( region
.IsEmpty() )
820 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
822 wxLogLastError(_T("SetWindowRgn"));
828 // Windows takes ownership of the region, so
829 // we'll have to make a copy of the region to give to it.
830 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
831 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
832 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
833 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
834 delete[] (char*) rgnData
;
836 // SetWindowRgn expects the region to be in coordinants
837 // relative to the window, not the client area. Figure
838 // out the offset, if any.
840 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
841 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
842 ::GetClientRect(GetHwnd(), &rect
);
843 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
844 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
846 // Now call the shape API with the new region.
847 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
849 wxLogLastError(_T("SetWindowRgn"));
855 #endif // !__WXWINCE__
857 // ----------------------------------------------------------------------------
858 // wxTopLevelWindow event handling
859 // ----------------------------------------------------------------------------
861 // Default activation behaviour - set the focus for the first child
863 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
865 if ( event
.GetActive() )
867 // restore focus to the child which was last focused unless we already
869 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
871 wxWindow
*winFocus
= FindFocus();
872 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
874 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
881 wxSetFocusToChild(parent
, &m_winLastFocused
);
886 // remember the last focused child if it is our child
887 m_winLastFocused
= FindFocus();
889 if ( m_winLastFocused
)
891 // let it know that it doesn't have focus any more
892 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
894 // and don't remember it if it's a child from some other frame
895 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
897 m_winLastFocused
= NULL
;
901 wxLogTrace(_T("focus"),
902 _T("wxTLW %08x deactivated, last focused: %08x."),
904 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
911 // the DialogProc for all wxWindows dialogs
912 LONG APIENTRY _EXPORT
913 wxDlgProc(HWND
WXUNUSED(hDlg
),
915 WPARAM
WXUNUSED(wParam
),
916 LPARAM
WXUNUSED(lParam
))
921 // for this message, returning TRUE tells system to set focus to
922 // the first control in the dialog box, but as we set the focus
923 // ourselves, we return FALSE from here as well, so fall through
926 // for all the other ones, FALSE means that we didn't process the
932 // ============================================================================
933 // wxTLWHiddenParentModule implementation
934 // ============================================================================
936 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
938 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
940 bool wxTLWHiddenParentModule::OnInit()
948 void wxTLWHiddenParentModule::OnExit()
952 if ( !::DestroyWindow(ms_hwnd
) )
954 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
962 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
964 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
972 HWND
wxTLWHiddenParentModule::GetHWND()
978 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
981 wxZeroMemory(wndclass
);
983 wndclass
.lpfnWndProc
= DefWindowProc
;
984 wndclass
.hInstance
= wxGetInstance();
985 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
987 if ( !::RegisterClass(&wndclass
) )
989 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
993 ms_className
= HIDDEN_PARENT_CLASS
;
997 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
998 (HMENU
)NULL
, wxGetInstance(), NULL
);
1001 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));