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 #include "wx/msw/winundef.h"
46 // This can't be undefed in winundef.h or
47 // there are further errors
48 #if defined(__WXWINCE__) && defined(CreateDialog)
52 #include "wx/display.h"
62 // ----------------------------------------------------------------------------
63 // stubs for missing functions under MicroWindows
64 // ----------------------------------------------------------------------------
68 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
69 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
71 #endif // __WXMICROWIN__
73 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
74 // is not included by wxUniv build which does need wxDlgProc
76 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 // list of all frames and modeless dialogs
83 wxWindowList wxModelessWindows
;
85 // the name of the default wxWindows class
86 extern const wxChar
*wxCanvasClassName
;
88 // ----------------------------------------------------------------------------
89 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
90 // module to ensure that the window is always deleted)
91 // ----------------------------------------------------------------------------
93 class wxTLWHiddenParentModule
: public wxModule
96 // module init/finalize
97 virtual bool OnInit();
98 virtual void OnExit();
100 // get the hidden window (creates on demand)
101 static HWND
GetHWND();
104 // the HWND of the hidden parent
107 // the class used to create it
108 static const wxChar
*ms_className
;
110 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
113 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
115 // ============================================================================
116 // wxTopLevelWindowMSW implementation
117 // ============================================================================
119 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
120 EVT_ACTIVATE(wxTopLevelWindowMSW
::OnActivate
)
123 // ----------------------------------------------------------------------------
124 // wxTopLevelWindowMSW creation
125 // ----------------------------------------------------------------------------
127 void wxTopLevelWindowMSW
::Init()
130 m_maximizeOnShow
= FALSE
;
132 // unlike (almost?) all other windows, frames are created hidden
135 // Data to save/restore when calling ShowFullScreen
137 m_fsOldWindowStyle
= 0;
138 m_fsIsMaximized
= FALSE
;
139 m_fsIsShowing
= FALSE
;
141 m_winLastFocused
= (wxWindow
*)NULL
;
144 WXDWORD wxTopLevelWindowMSW
::MSWGetStyle(long style
, WXDWORD
*exflags
) const
146 // let the base class deal with the common styles but fix the ones which
147 // don't make sense for us (we also deal with the borders ourselves)
148 WXDWORD msflags
= wxWindow
::MSWGetStyle
150 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
151 ) & ~WS_CHILD
& ~WS_VISIBLE
;
153 // first select the kind of window being created
155 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
156 // creates a window with both caption and border, hence we also test it
157 // below in some other cases
158 if ( style
& wxFRAME_TOOL_WINDOW
)
163 if (msflags
& WS_BORDER
)
165 msflags
|= WS_OVERLAPPED
;
168 // border and caption styles
169 if ( style
& wxRESIZE_BORDER
)
172 msflags
|= WS_THICKFRAME
;
175 else if ( !(style
& wxBORDER_NONE
) )
176 msflags
|= WS_BORDER
;
182 if ( style
& wxCAPTION
)
183 msflags
|= WS_CAPTION
;
189 // next translate the individual flags
190 if ( style
& wxMINIMIZE_BOX
)
191 msflags
|= WS_MINIMIZEBOX
;
192 if ( style
& wxMAXIMIZE_BOX
)
193 msflags
|= WS_MAXIMIZEBOX
;
194 if ( style
& wxSYSTEM_MENU
)
195 msflags
|= WS_SYSMENU
;
197 if ( style
& wxMINIMIZE
)
198 msflags
|= WS_MINIMIZE
;
199 if ( style
& wxMAXIMIZE
)
200 msflags
|= WS_MAXIMIZE
;
203 // Keep this here because it saves recoding this function in wxTinyFrame
204 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
205 if ( style
& wxTINY_CAPTION_VERT
)
206 msflags
|= IBS_VERTCAPTION
;
207 if ( style
& wxTINY_CAPTION_HORIZ
)
208 msflags
|= IBS_HORZCAPTION
;
210 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
211 msflags
|= WS_CAPTION
;
216 #if !defined(__WIN16__)
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 // We have to solve 2 different problems here:
230 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
231 // taskbar even if they don't have a parent
233 // 2. frames without this style should appear in the taskbar even
234 // if they're owned (Windows only puts non owned windows into
235 // the taskbar normally)
237 // The second one is solved here by using WS_EX_APPWINDOW flag, the
238 // first one is dealt with in our MSWGetParent() method
241 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
243 // need to force the frame to appear in the taskbar
244 *exflags
|= WS_EX_APPWINDOW
;
247 //else: nothing to do [here]
251 if ( style
& wxSTAY_ON_TOP
)
252 *exflags
|= WS_EX_TOPMOST
;
255 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
256 *exflags
|= WS_EX_CONTEXTHELP
;
263 WXHWND wxTopLevelWindowMSW
::MSWGetParent() const
265 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
266 // parent HWND or it would be always on top of its parent which is not what
267 // we usually want (in fact, we only want it for frames with the
268 // wxFRAME_FLOAT_ON_PARENT flag)
269 HWND hwndParent
= NULL
;
270 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
272 const wxWindow
*parent
= GetParent();
276 // this flag doesn't make sense then and will be ignored
277 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
281 hwndParent
= GetHwndOf(parent
);
284 //else: don't float on parent, must not be owned
286 // now deal with the 2nd taskbar-related problem (see comments above in
288 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
291 hwndParent
= wxTLWHiddenParentModule
::GetHWND();
294 return (WXHWND
)hwndParent
;
297 bool wxTopLevelWindowMSW
::CreateDialog(const void *dlgTemplate
,
298 const wxString
& title
,
302 #ifdef __WXMICROWIN__
303 // no dialogs support under MicroWin yet
304 return CreateFrame(title
, pos
, size
);
305 #else // !__WXMICROWIN__
306 wxWindow
*parent
= GetParent();
308 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
309 // app window as parent - this avoids creating modal dialogs without
311 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
313 parent
= wxTheApp
->GetTopWindow();
317 // don't use transient windows as parents, this is dangerous as it
318 // can lead to a crash if the parent is destroyed before the child
320 // also don't use the window which is currently hidden as then the
321 // dialog would be hidden as well
322 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
330 m_hWnd
= (WXHWND
)::CreateDialogIndirect
333 (DLGTEMPLATE
*)dlgTemplate
,
334 parent ?
GetHwndOf(parent
) : NULL
,
340 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
342 wxLogSysError(wxT("Can't create dialog using memory template"));
348 (void)MSWGetCreateWindowFlags(&exflags
);
352 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
353 ::SetWindowPos(GetHwnd(),
354 exflags
& WS_EX_TOPMOST ? HWND_TOPMOST
: 0,
358 (exflags
& WS_EX_TOPMOST ?
0 : SWP_NOZORDER
) |
362 #if defined(__WIN95__)
363 // For some reason, the system menu is activated when we use the
364 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
365 if ( exflags
& WS_EX_CONTEXTHELP
)
367 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
370 wxIcon icon
= winTop
->GetIcon();
373 ::SendMessage(GetHwnd(), WM_SETICON
,
375 (LPARAM
)GetHiconOf(icon
));
381 // move the dialog to its initial position without forcing repainting
383 if ( !MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
) )
386 w
= (int)CW_USEDEFAULT
;
389 // we can't use CW_USEDEFAULT here as we're not calling CreateWindow()
390 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
391 // window to (0, 0) size which breaks quite a lot of things, e.g. the
392 // sizer calculation in wxSizer::Fit()
393 if ( w
== (int)CW_USEDEFAULT
)
395 // the exact number doesn't matter, the dialog will be resized
396 // again soon anyhow but it should be big enough to allow
397 // calculation relying on "totalSize - clientSize > 0" work, i.e.
398 // at least greater than the title bar height
403 if ( x
== (int)CW_USEDEFAULT
)
405 // centre it on the screen - what else can we do?
406 wxSize sizeDpy
= wxGetDisplaySize();
408 x
= (sizeDpy
.x
- w
) / 2;
409 y
= (sizeDpy
.y
- h
) / 2;
412 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
414 wxLogLastError(wxT("MoveWindow"));
417 if ( !title
.empty() )
419 ::SetWindowText(GetHwnd(), title
);
425 #endif // __WXMICROWIN__/!__WXMICROWIN__
428 bool wxTopLevelWindowMSW
::CreateFrame(const wxString
& title
,
433 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
435 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
438 bool wxTopLevelWindowMSW
::Create(wxWindow
*parent
,
440 const wxString
& title
,
444 const wxString
& name
)
451 m_windowStyle
= style
;
455 m_windowId
= id
== -1 ?
NewControlId() : id
;
457 wxTopLevelWindows
.Append(this);
460 parent
->AddChild(this);
462 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
464 // we have different dialog templates to allows creation of dialogs
465 // with & without captions under MSWindows, resizeable or not (but a
466 // resizeable dialog always has caption - otherwise it would look too
469 // we need 3 additional WORDs for dialog menu, class and title (as we
470 // don't use DS_SETFONT we don't need the fourth WORD for the font)
471 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
472 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
473 memset(dlgTemplate
, 0, dlgsize
);
475 // these values are arbitrary, they won't be used normally anyhow
478 dlgTemplate
->cx
= 144;
479 dlgTemplate
->cy
= 75;
481 // reuse the code in MSWGetStyle() but correct the results slightly for
483 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
485 // all dialogs are popups
486 dlgTemplate
->style
|= WS_POPUP
;
488 // force 3D-look if necessary, it looks impossibly ugly otherwise
489 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
490 dlgTemplate
->style
|= DS_MODALFRAME
;
492 ret
= CreateDialog(dlgTemplate
, title
, pos
, size
);
497 ret
= CreateFrame(title
, pos
, size
);
500 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
502 EnableCloseButton(false);
508 wxTopLevelWindowMSW
::~wxTopLevelWindowMSW()
510 if ( wxModelessWindows
.Find(this) )
511 wxModelessWindows
.DeleteObject(this);
513 // after destroying an owned window, Windows activates the next top level
514 // window in Z order but it may be different from our owner (to reproduce
515 // this simply Alt-TAB to another application and back before closing the
516 // owned frame) whereas we always want to yield activation to our parent
517 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
519 wxWindow
*parent
= GetParent();
522 ::BringWindowToTop(GetHwndOf(parent
));
527 // ----------------------------------------------------------------------------
528 // wxTopLevelWindowMSW showing
529 // ----------------------------------------------------------------------------
531 void wxTopLevelWindowMSW
::DoShowWindow(int nShowCmd
)
533 ::ShowWindow(GetHwnd(), nShowCmd
);
535 m_iconized
= nShowCmd
== SW_MINIMIZE
;
538 bool wxTopLevelWindowMSW
::Show(bool show
)
540 // don't use wxWindow version as we want to call DoShowWindow() ourselves
541 if ( !wxWindowBase
::Show(show
) )
547 if ( m_maximizeOnShow
)
550 nShowCmd
= SW_MAXIMIZE
;
552 m_maximizeOnShow
= FALSE
;
556 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
557 nShowCmd
= SW_SHOWNA
;
567 DoShowWindow(nShowCmd
);
571 ::BringWindowToTop(GetHwnd());
573 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
574 event
.SetEventObject( this );
575 GetEventHandler()->ProcessEvent(event
);
579 // Try to highlight the correct window (the parent)
582 HWND hWndParent
= GetHwndOf(GetParent());
584 ::BringWindowToTop(hWndParent
);
591 // ----------------------------------------------------------------------------
592 // wxTopLevelWindowMSW maximize/minimize
593 // ----------------------------------------------------------------------------
595 void wxTopLevelWindowMSW
::Maximize(bool maximize
)
599 // just maximize it directly
600 DoShowWindow(maximize ? SW_MAXIMIZE
: SW_RESTORE
);
604 // we can't maximize the hidden frame because it shows it as well, so
605 // just remember that we should do it later in this case
606 m_maximizeOnShow
= maximize
;
610 bool wxTopLevelWindowMSW
::IsMaximized() const
615 return ::IsZoomed(GetHwnd()) != 0;
619 void wxTopLevelWindowMSW
::Iconize(bool iconize
)
621 DoShowWindow(iconize ? SW_MINIMIZE
: SW_RESTORE
);
624 bool wxTopLevelWindowMSW
::IsIconized() const
629 // also update the current state
630 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
636 void wxTopLevelWindowMSW
::Restore()
638 DoShowWindow(SW_RESTORE
);
641 // ----------------------------------------------------------------------------
642 // wxTopLevelWindowMSW fullscreen
643 // ----------------------------------------------------------------------------
645 bool wxTopLevelWindowMSW
::ShowFullScreen(bool show
, long style
)
647 if ( show
== IsFullScreen() )
653 m_fsIsShowing
= show
;
659 // zap the frame borders
661 // save the 'normal' window style
662 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
664 // save the old position, width & height, maximize state
665 m_fsOldSize
= GetRect();
666 m_fsIsMaximized
= IsMaximized();
668 // decide which window style flags to turn off
669 LONG newStyle
= m_fsOldWindowStyle
;
672 if (style
& wxFULLSCREEN_NOBORDER
)
674 offFlags
|= WS_BORDER
;
676 offFlags
|= WS_THICKFRAME
;
679 if (style
& wxFULLSCREEN_NOCAPTION
)
680 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
682 newStyle
&= ~offFlags
;
684 // change our window style to be compatible with full-screen mode
685 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
689 // resize to the size of the display containing us
690 int dpy
= wxDisplay
::GetFromWindow(this);
691 if ( dpy
!= wxNOT_FOUND
)
693 rect
= wxDisplay(dpy
).GetGeometry();
695 else // fall back to the main desktop
696 #else // wxUSE_DISPLAY
698 // FIXME: implement for WinCE
700 // resize to the size of the desktop
701 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
704 #endif // wxUSE_DISPLAY
708 // now flush the window style cache and actually go full-screen
709 long flags
= SWP_FRAMECHANGED
;
711 // showing the frame full screen should also show it if it's still
715 // don't call wxWindow version to avoid flicker from calling
716 // ::ShowWindow() -- we're going to show the window at the correct
717 // location directly below -- but do call the wxWindowBase version
718 // to sync the internal m_isShown flag
719 wxWindowBase
::Show();
721 flags
|= SWP_SHOWWINDOW
;
724 SetWindowPos(GetHwnd(), HWND_TOP
,
725 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
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 Maximize(m_fsIsMaximized
);
735 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
736 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
737 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
743 // ----------------------------------------------------------------------------
744 // wxTopLevelWindowMSW misc
745 // ----------------------------------------------------------------------------
747 void wxTopLevelWindowMSW
::SetIcon(const wxIcon
& icon
)
749 SetIcons( wxIconBundle( icon
) );
752 void wxTopLevelWindowMSW
::SetIcons(const wxIconBundle
& icons
)
754 wxTopLevelWindowBase
::SetIcons(icons
);
756 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
757 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
758 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
760 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
761 (LPARAM
)GetHiconOf(sml
) );
764 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
765 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
767 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
768 (LPARAM
)GetHiconOf(big
) );
773 bool wxTopLevelWindowMSW
::EnableCloseButton(bool enable
)
775 #if !defined(__WXMICROWIN__)
776 // get system (a.k.a. window) menu
777 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
780 // no system menu at all -- ok if we want to remove the close button
781 // anyhow, but bad if we want to show it
785 // enabling/disabling the close item from it also automatically
786 // disables/enables the close title bar button
787 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
789 (enable ? MF_ENABLED
: MF_GRAYED
)) == -1 )
791 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
796 // update appearance immediately
797 if ( !::DrawMenuBar(GetHwnd()) )
799 wxLogLastError(_T("DrawMenuBar"));
801 #endif // !__WXMICROWIN__
806 bool wxTopLevelWindowMSW
::SetShape(const wxRegion
& region
)
811 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
812 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
814 // The empty region signifies that the shape should be removed from the
816 if ( region
.IsEmpty() )
818 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
820 wxLogLastError(_T("SetWindowRgn"));
826 // Windows takes ownership of the region, so
827 // we'll have to make a copy of the region to give to it.
828 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
829 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
830 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
831 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
832 delete[] (char*) rgnData
;
834 // SetWindowRgn expects the region to be in coordinants
835 // relative to the window, not the client area. Figure
836 // out the offset, if any.
838 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
839 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
840 ::GetClientRect(GetHwnd(), &rect
);
841 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
842 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
844 // Now call the shape API with the new region.
845 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
847 wxLogLastError(_T("SetWindowRgn"));
854 // ----------------------------------------------------------------------------
855 // wxTopLevelWindow event handling
856 // ----------------------------------------------------------------------------
858 // Default activation behaviour - set the focus for the first child
860 void wxTopLevelWindowMSW
::OnActivate(wxActivateEvent
& event
)
862 if ( event
.GetActive() )
864 // restore focus to the child which was last focused
865 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
867 wxWindow
*parent
= m_winLastFocused ? m_winLastFocused
->GetParent()
874 wxSetFocusToChild(parent
, &m_winLastFocused
);
878 // remember the last focused child if it is our child
879 m_winLastFocused
= FindFocus();
881 if ( m_winLastFocused
)
883 // let it know that it doesn't have focus any more
884 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
887 // so we NULL it out if it's a child from some other frame
888 wxWindow
*win
= m_winLastFocused
;
891 if ( win
->IsTopLevel() )
895 m_winLastFocused
= NULL
;
901 win
= win
->GetParent();
904 wxLogTrace(_T("focus"),
905 _T("wxTLW %08x deactivated, last focused: %08x."),
907 (int) (m_winLastFocused ?
GetHwndOf(m_winLastFocused
)
914 // the DialogProc for all wxWindows dialogs
915 LONG APIENTRY _EXPORT
916 wxDlgProc(HWND
WXUNUSED(hDlg
),
918 WPARAM
WXUNUSED(wParam
),
919 LPARAM
WXUNUSED(lParam
))
924 // for this message, returning TRUE tells system to set focus to
925 // the first control in the dialog box, but as we set the focus
926 // ourselves, we return FALSE from here as well, so fall through
929 // for all the other ones, FALSE means that we didn't process the
935 // ============================================================================
936 // wxTLWHiddenParentModule implementation
937 // ============================================================================
939 HWND wxTLWHiddenParentModule
::ms_hwnd
= NULL
;
941 const wxChar
*wxTLWHiddenParentModule
::ms_className
= NULL
;
943 bool wxTLWHiddenParentModule
::OnInit()
951 void wxTLWHiddenParentModule
::OnExit()
955 if ( !::DestroyWindow(ms_hwnd
) )
957 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
965 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
967 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
975 HWND wxTLWHiddenParentModule
::GetHWND()
981 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
984 wxZeroMemory(wndclass
);
986 wndclass
.lpfnWndProc
= DefWindowProc
;
987 wndclass
.hInstance
= wxGetInstance();
988 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
990 if ( !::RegisterClass(&wndclass
) )
992 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
996 ms_className
= HIDDEN_PARENT_CLASS
;
1000 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1001 (HMENU
)NULL
, wxGetInstance(), NULL
);
1004 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));