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 ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
176 *exflags
|= WS_EX_DLGMODALFRAME
;
177 else if ( !(style
& wxBORDER_NONE
) )
178 msflags
|= WS_BORDER
;
184 if ( style
& wxCAPTION
)
185 msflags
|= WS_CAPTION
;
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 if ( style
& wxMINIMIZE
)
200 msflags
|= WS_MINIMIZE
;
201 if ( style
& wxMAXIMIZE
)
202 msflags
|= WS_MAXIMIZE
;
205 // Keep this here because it saves recoding this function in wxTinyFrame
206 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
207 if ( style
& wxTINY_CAPTION_VERT
)
208 msflags
|= IBS_VERTCAPTION
;
209 if ( style
& wxTINY_CAPTION_HORIZ
)
210 msflags
|= IBS_HORZCAPTION
;
212 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
213 msflags
|= WS_CAPTION
;
218 #if !defined(__WIN16__)
219 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
221 if ( style
& wxFRAME_TOOL_WINDOW
)
223 // create the palette-like window
224 *exflags
|= WS_EX_TOOLWINDOW
;
226 // tool windows shouldn't appear on the taskbar (as documented)
227 style
|= wxFRAME_NO_TASKBAR
;
230 // We have to solve 2 different problems here:
232 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
233 // taskbar even if they don't have a parent
235 // 2. frames without this style should appear in the taskbar even
236 // if they're owned (Windows only puts non owned windows into
237 // the taskbar normally)
239 // The second one is solved here by using WS_EX_APPWINDOW flag, the
240 // first one is dealt with in our MSWGetParent() method
243 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
245 // need to force the frame to appear in the taskbar
246 *exflags
|= WS_EX_APPWINDOW
;
249 //else: nothing to do [here]
253 if ( style
& wxSTAY_ON_TOP
)
254 *exflags
|= WS_EX_TOPMOST
;
257 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
258 *exflags
|= WS_EX_CONTEXTHELP
;
265 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
267 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
268 // parent HWND or it would be always on top of its parent which is not what
269 // we usually want (in fact, we only want it for frames with the
270 // wxFRAME_FLOAT_ON_PARENT flag)
271 HWND hwndParent
= NULL
;
272 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
274 const wxWindow
*parent
= GetParent();
278 // this flag doesn't make sense then and will be ignored
279 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
283 hwndParent
= GetHwndOf(parent
);
286 //else: don't float on parent, must not be owned
288 // now deal with the 2nd taskbar-related problem (see comments above in
290 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
293 hwndParent
= wxTLWHiddenParentModule::GetHWND();
296 return (WXHWND
)hwndParent
;
299 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
300 const wxString
& title
,
304 #ifdef __WXMICROWIN__
305 // no dialogs support under MicroWin yet
306 return CreateFrame(title
, pos
, size
);
307 #else // !__WXMICROWIN__
308 wxWindow
*parent
= GetParent();
310 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
311 // app window as parent - this avoids creating modal dialogs without
313 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
315 parent
= wxTheApp
->GetTopWindow();
319 // don't use transient windows as parents, this is dangerous as it
320 // can lead to a crash if the parent is destroyed before the child
322 // also don't use the window which is currently hidden as then the
323 // dialog would be hidden as well
324 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
332 m_hWnd
= (WXHWND
)::CreateDialogIndirect
335 (DLGTEMPLATE
*)dlgTemplate
,
336 parent
? GetHwndOf(parent
) : NULL
,
342 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
344 wxLogSysError(wxT("Can't create dialog using memory template"));
350 (void)MSWGetCreateWindowFlags(&exflags
);
354 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
355 ::SetWindowPos(GetHwnd(),
356 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
360 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
364 #if defined(__WIN95__)
365 // For some reason, the system menu is activated when we use the
366 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
367 if ( exflags
& WS_EX_CONTEXTHELP
)
369 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
372 wxIcon icon
= winTop
->GetIcon();
375 ::SendMessage(GetHwnd(), WM_SETICON
,
377 (LPARAM
)GetHiconOf(icon
));
383 // move the dialog to its initial position without forcing repainting
385 if ( !MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
) )
388 w
= (int)CW_USEDEFAULT
;
391 // we can't use CW_USEDEFAULT here as we're not calling CreateWindow()
392 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
393 // window to (0, 0) size which breaks quite a lot of things, e.g. the
394 // sizer calculation in wxSizer::Fit()
395 if ( w
== (int)CW_USEDEFAULT
)
397 // the exact number doesn't matter, the dialog will be resized
398 // again soon anyhow but it should be big enough to allow
399 // calculation relying on "totalSize - clientSize > 0" work, i.e.
400 // at least greater than the title bar height
405 if ( x
== (int)CW_USEDEFAULT
)
407 // centre it on the screen - what else can we do?
408 wxSize sizeDpy
= wxGetDisplaySize();
410 x
= (sizeDpy
.x
- w
) / 2;
411 y
= (sizeDpy
.y
- h
) / 2;
414 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
416 wxLogLastError(wxT("MoveWindow"));
419 if ( !title
.empty() )
421 ::SetWindowText(GetHwnd(), title
);
427 #endif // __WXMICROWIN__/!__WXMICROWIN__
430 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
435 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
437 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
440 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
442 const wxString
& title
,
446 const wxString
& name
)
453 m_windowStyle
= style
;
457 m_windowId
= id
== -1 ? NewControlId() : id
;
459 wxTopLevelWindows
.Append(this);
462 parent
->AddChild(this);
464 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
466 // we have different dialog templates to allows creation of dialogs
467 // with & without captions under MSWindows, resizeable or not (but a
468 // resizeable dialog always has caption - otherwise it would look too
471 // we need 3 additional WORDs for dialog menu, class and title (as we
472 // don't use DS_SETFONT we don't need the fourth WORD for the font)
473 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
474 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
475 memset(dlgTemplate
, 0, dlgsize
);
477 // these values are arbitrary, they won't be used normally anyhow
480 dlgTemplate
->cx
= 144;
481 dlgTemplate
->cy
= 75;
483 // reuse the code in MSWGetStyle() but correct the results slightly for
485 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
487 // all dialogs are popups
488 dlgTemplate
->style
|= WS_POPUP
;
490 // force 3D-look if necessary, it looks impossibly ugly otherwise
491 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
492 dlgTemplate
->style
|= DS_MODALFRAME
;
494 ret
= CreateDialog(dlgTemplate
, title
, pos
, size
);
499 ret
= CreateFrame(title
, pos
, size
);
502 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
504 EnableCloseButton(false);
510 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
512 if ( wxModelessWindows
.Find(this) )
513 wxModelessWindows
.DeleteObject(this);
515 // after destroying an owned window, Windows activates the next top level
516 // window in Z order but it may be different from our owner (to reproduce
517 // this simply Alt-TAB to another application and back before closing the
518 // owned frame) whereas we always want to yield activation to our parent
519 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
521 wxWindow
*parent
= GetParent();
524 ::BringWindowToTop(GetHwndOf(parent
));
529 // ----------------------------------------------------------------------------
530 // wxTopLevelWindowMSW showing
531 // ----------------------------------------------------------------------------
533 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
535 ::ShowWindow(GetHwnd(), nShowCmd
);
537 m_iconized
= nShowCmd
== SW_MINIMIZE
;
540 bool wxTopLevelWindowMSW::Show(bool show
)
542 // don't use wxWindow version as we want to call DoShowWindow() ourselves
543 if ( !wxWindowBase::Show(show
) )
549 if ( m_maximizeOnShow
)
552 nShowCmd
= SW_MAXIMIZE
;
554 m_maximizeOnShow
= FALSE
;
558 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
559 nShowCmd
= SW_SHOWNA
;
569 DoShowWindow(nShowCmd
);
573 ::BringWindowToTop(GetHwnd());
575 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
576 event
.SetEventObject( this );
577 GetEventHandler()->ProcessEvent(event
);
581 // Try to highlight the correct window (the parent)
584 HWND hWndParent
= GetHwndOf(GetParent());
586 ::BringWindowToTop(hWndParent
);
593 // ----------------------------------------------------------------------------
594 // wxTopLevelWindowMSW maximize/minimize
595 // ----------------------------------------------------------------------------
597 void wxTopLevelWindowMSW::Maximize(bool maximize
)
601 // just maximize it directly
602 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
606 // we can't maximize the hidden frame because it shows it as well, so
607 // just remember that we should do it later in this case
608 m_maximizeOnShow
= maximize
;
612 bool wxTopLevelWindowMSW::IsMaximized() const
617 return ::IsZoomed(GetHwnd()) != 0;
621 void wxTopLevelWindowMSW::Iconize(bool iconize
)
623 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
626 bool wxTopLevelWindowMSW::IsIconized() const
631 // also update the current state
632 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
638 void wxTopLevelWindowMSW::Restore()
640 DoShowWindow(SW_RESTORE
);
643 // ----------------------------------------------------------------------------
644 // wxTopLevelWindowMSW fullscreen
645 // ----------------------------------------------------------------------------
647 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
649 if ( show
== IsFullScreen() )
655 m_fsIsShowing
= show
;
661 // zap the frame borders
663 // save the 'normal' window style
664 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
666 // save the old position, width & height, maximize state
667 m_fsOldSize
= GetRect();
668 m_fsIsMaximized
= IsMaximized();
670 // decide which window style flags to turn off
671 LONG newStyle
= m_fsOldWindowStyle
;
674 if (style
& wxFULLSCREEN_NOBORDER
)
676 offFlags
|= WS_BORDER
;
678 offFlags
|= WS_THICKFRAME
;
681 if (style
& wxFULLSCREEN_NOCAPTION
)
682 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
684 newStyle
&= ~offFlags
;
686 // change our window style to be compatible with full-screen mode
687 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
691 // resize to the size of the display containing us
692 int dpy
= wxDisplay::GetFromWindow(this);
693 if ( dpy
!= wxNOT_FOUND
)
695 rect
= wxDisplay(dpy
).GetGeometry();
697 else // fall back to the main desktop
698 #else // wxUSE_DISPLAY
700 // FIXME: implement for WinCE
702 // resize to the size of the desktop
703 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
706 #endif // wxUSE_DISPLAY
710 // now flush the window style cache and actually go full-screen
711 long flags
= SWP_FRAMECHANGED
;
713 // showing the frame full screen should also show it if it's still
717 // don't call wxWindow version to avoid flicker from calling
718 // ::ShowWindow() -- we're going to show the window at the correct
719 // location directly below -- but do call the wxWindowBase version
720 // to sync the internal m_isShown flag
721 wxWindowBase::Show();
723 flags
|= SWP_SHOWWINDOW
;
726 SetWindowPos(GetHwnd(), HWND_TOP
,
727 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
730 // finally send an event allowing the window to relayout itself &c
731 wxSizeEvent
event(rect
.GetSize(), GetId());
732 GetEventHandler()->ProcessEvent(event
);
734 else // stop showing full screen
736 Maximize(m_fsIsMaximized
);
737 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
738 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
739 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
745 // ----------------------------------------------------------------------------
746 // wxTopLevelWindowMSW misc
747 // ----------------------------------------------------------------------------
749 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
751 SetIcons( wxIconBundle( icon
) );
754 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
756 wxTopLevelWindowBase::SetIcons(icons
);
758 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
759 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
760 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
762 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
763 (LPARAM
)GetHiconOf(sml
) );
766 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
767 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
769 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
770 (LPARAM
)GetHiconOf(big
) );
775 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
777 #if !defined(__WXMICROWIN__)
778 // get system (a.k.a. window) menu
779 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
782 // no system menu at all -- ok if we want to remove the close button
783 // anyhow, but bad if we want to show it
787 // enabling/disabling the close item from it also automatically
788 // disables/enables the close title bar button
789 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
791 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
793 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
798 // update appearance immediately
799 if ( !::DrawMenuBar(GetHwnd()) )
801 wxLogLastError(_T("DrawMenuBar"));
803 #endif // !__WXMICROWIN__
808 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"));
856 // ----------------------------------------------------------------------------
857 // wxTopLevelWindow event handling
858 // ----------------------------------------------------------------------------
860 // Default activation behaviour - set the focus for the first child
862 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
864 if ( event
.GetActive() )
866 // restore focus to the child which was last focused unless we already
868 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
870 wxWindow
*winFocus
= FindFocus();
871 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
873 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
880 wxSetFocusToChild(parent
, &m_winLastFocused
);
885 // remember the last focused child if it is our child
886 m_winLastFocused
= FindFocus();
888 if ( m_winLastFocused
)
890 // let it know that it doesn't have focus any more
891 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
893 // and don't remember it if it's a child from some other frame
894 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
896 m_winLastFocused
= NULL
;
900 wxLogTrace(_T("focus"),
901 _T("wxTLW %08x deactivated, last focused: %08x."),
903 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
910 // the DialogProc for all wxWindows dialogs
911 LONG APIENTRY _EXPORT
912 wxDlgProc(HWND
WXUNUSED(hDlg
),
914 WPARAM
WXUNUSED(wParam
),
915 LPARAM
WXUNUSED(lParam
))
920 // for this message, returning TRUE tells system to set focus to
921 // the first control in the dialog box, but as we set the focus
922 // ourselves, we return FALSE from here as well, so fall through
925 // for all the other ones, FALSE means that we didn't process the
931 // ============================================================================
932 // wxTLWHiddenParentModule implementation
933 // ============================================================================
935 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
937 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
939 bool wxTLWHiddenParentModule::OnInit()
947 void wxTLWHiddenParentModule::OnExit()
951 if ( !::DestroyWindow(ms_hwnd
) )
953 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
961 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
963 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
971 HWND
wxTLWHiddenParentModule::GetHWND()
977 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
980 wxZeroMemory(wndclass
);
982 wndclass
.lpfnWndProc
= DefWindowProc
;
983 wndclass
.hInstance
= wxGetInstance();
984 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
986 if ( !::RegisterClass(&wndclass
) )
988 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
992 ms_className
= HIDDEN_PARENT_CLASS
;
996 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
997 (HMENU
)NULL
, wxGetInstance(), NULL
);
1000 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));