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/missing.h"
46 #if defined(__WXWINCE__)
52 #include "wx/msw/wince/missing.h"
55 #include "wx/msw/winundef.h"
57 // This can't be undefed in winundef.h or
58 // there are further errors
59 #if defined(__WXWINCE__) && defined(CreateDialog)
63 #include "wx/display.h"
73 // ----------------------------------------------------------------------------
74 // stubs for missing functions under MicroWindows
75 // ----------------------------------------------------------------------------
79 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
80 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
82 #endif // __WXMICROWIN__
84 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
85 // is not included by wxUniv build which does need wxDlgProc
87 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 // list of all frames and modeless dialogs
94 wxWindowList wxModelessWindows
;
96 // the name of the default wxWindows class
97 extern const wxChar
*wxCanvasClassName
;
99 // ----------------------------------------------------------------------------
100 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
101 // module to ensure that the window is always deleted)
102 // ----------------------------------------------------------------------------
104 class wxTLWHiddenParentModule
: public wxModule
107 // module init/finalize
108 virtual bool OnInit();
109 virtual void OnExit();
111 // get the hidden window (creates on demand)
112 static HWND
GetHWND();
115 // the HWND of the hidden parent
118 // the class used to create it
119 static const wxChar
*ms_className
;
121 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
124 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
126 // ============================================================================
127 // wxTopLevelWindowMSW implementation
128 // ============================================================================
130 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
131 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
134 // ----------------------------------------------------------------------------
135 // wxTopLevelWindowMSW creation
136 // ----------------------------------------------------------------------------
138 void wxTopLevelWindowMSW::Init()
141 m_maximizeOnShow
= FALSE
;
143 // unlike (almost?) all other windows, frames are created hidden
146 // Data to save/restore when calling ShowFullScreen
148 m_fsOldWindowStyle
= 0;
149 m_fsIsMaximized
= FALSE
;
150 m_fsIsShowing
= FALSE
;
152 m_winLastFocused
= (wxWindow
*)NULL
;
155 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
157 // let the base class deal with the common styles but fix the ones which
158 // don't make sense for us (we also deal with the borders ourselves)
159 WXDWORD msflags
= wxWindow::MSWGetStyle
161 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
162 ) & ~WS_CHILD
& ~WS_VISIBLE
;
164 // first select the kind of window being created
166 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
167 // creates a window with both caption and border, hence we also test it
168 // below in some other cases
169 if ( style
& wxFRAME_TOOL_WINDOW
)
174 if (msflags
& WS_BORDER
)
176 msflags
|= WS_OVERLAPPED
;
179 // border and caption styles
180 if ( style
& wxRESIZE_BORDER
)
183 msflags
|= WS_THICKFRAME
;
186 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
187 *exflags
|= WS_EX_DLGMODALFRAME
;
188 else if ( !(style
& wxBORDER_NONE
) )
189 msflags
|= WS_BORDER
;
195 if ( style
& wxCAPTION
)
196 msflags
|= WS_CAPTION
;
202 // next translate the individual flags
203 if ( style
& wxMINIMIZE_BOX
)
204 msflags
|= WS_MINIMIZEBOX
;
205 if ( style
& wxMAXIMIZE_BOX
)
206 msflags
|= WS_MAXIMIZEBOX
;
207 if ( style
& wxSYSTEM_MENU
)
208 msflags
|= WS_SYSMENU
;
210 if ( style
& wxMINIMIZE
)
211 msflags
|= WS_MINIMIZE
;
212 if ( style
& wxMAXIMIZE
)
213 msflags
|= WS_MAXIMIZE
;
216 // Keep this here because it saves recoding this function in wxTinyFrame
217 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
218 if ( style
& wxTINY_CAPTION_VERT
)
219 msflags
|= IBS_VERTCAPTION
;
220 if ( style
& wxTINY_CAPTION_HORIZ
)
221 msflags
|= IBS_HORZCAPTION
;
223 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
224 msflags
|= WS_CAPTION
;
229 #if !defined(__WIN16__)
230 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
232 if ( style
& wxFRAME_TOOL_WINDOW
)
234 // create the palette-like window
235 *exflags
|= WS_EX_TOOLWINDOW
;
237 // tool windows shouldn't appear on the taskbar (as documented)
238 style
|= wxFRAME_NO_TASKBAR
;
241 // We have to solve 2 different problems here:
243 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
244 // taskbar even if they don't have a parent
246 // 2. frames without this style should appear in the taskbar even
247 // if they're owned (Windows only puts non owned windows into
248 // the taskbar normally)
250 // The second one is solved here by using WS_EX_APPWINDOW flag, the
251 // first one is dealt with in our MSWGetParent() method
254 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
256 // need to force the frame to appear in the taskbar
257 *exflags
|= WS_EX_APPWINDOW
;
260 //else: nothing to do [here]
264 if ( style
& wxSTAY_ON_TOP
)
265 *exflags
|= WS_EX_TOPMOST
;
268 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
269 *exflags
|= WS_EX_CONTEXTHELP
;
276 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
278 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
279 // parent HWND or it would be always on top of its parent which is not what
280 // we usually want (in fact, we only want it for frames with the
281 // wxFRAME_FLOAT_ON_PARENT flag)
282 HWND hwndParent
= NULL
;
283 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
285 const wxWindow
*parent
= GetParent();
289 // this flag doesn't make sense then and will be ignored
290 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
294 hwndParent
= GetHwndOf(parent
);
297 //else: don't float on parent, must not be owned
299 // now deal with the 2nd taskbar-related problem (see comments above in
301 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
304 hwndParent
= wxTLWHiddenParentModule::GetHWND();
307 return (WXHWND
)hwndParent
;
310 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
311 const wxString
& title
,
315 #ifdef __WXMICROWIN__
316 // no dialogs support under MicroWin yet
317 return CreateFrame(title
, pos
, size
);
318 #else // !__WXMICROWIN__
319 wxWindow
*parent
= GetParent();
321 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
322 // app window as parent - this avoids creating modal dialogs without
324 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
326 parent
= wxTheApp
->GetTopWindow();
330 // don't use transient windows as parents, this is dangerous as it
331 // can lead to a crash if the parent is destroyed before the child
333 // also don't use the window which is currently hidden as then the
334 // dialog would be hidden as well
335 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
343 m_hWnd
= (WXHWND
)::CreateDialogIndirect
346 (DLGTEMPLATE
*)dlgTemplate
,
347 parent
? GetHwndOf(parent
) : NULL
,
353 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
355 wxLogSysError(wxT("Can't create dialog using memory template"));
361 (void)MSWGetCreateWindowFlags(&exflags
);
365 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
366 ::SetWindowPos(GetHwnd(),
367 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
371 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
375 #if defined(__WIN95__)
376 // For some reason, the system menu is activated when we use the
377 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
378 if ( exflags
& WS_EX_CONTEXTHELP
)
380 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
383 wxIcon icon
= winTop
->GetIcon();
386 ::SendMessage(GetHwnd(), WM_SETICON
,
388 (LPARAM
)GetHiconOf(icon
));
394 // move the dialog to its initial position without forcing repainting
396 if ( !MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
) )
399 w
= (int)CW_USEDEFAULT
;
402 // we can't use CW_USEDEFAULT here as we're not calling CreateWindow()
403 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
404 // window to (0, 0) size which breaks quite a lot of things, e.g. the
405 // sizer calculation in wxSizer::Fit()
406 if ( w
== (int)CW_USEDEFAULT
)
408 // the exact number doesn't matter, the dialog will be resized
409 // again soon anyhow but it should be big enough to allow
410 // calculation relying on "totalSize - clientSize > 0" work, i.e.
411 // at least greater than the title bar height
416 if ( x
== (int)CW_USEDEFAULT
)
418 // centre it on the screen - what else can we do?
419 wxSize sizeDpy
= wxGetDisplaySize();
421 x
= (sizeDpy
.x
- w
) / 2;
422 y
= (sizeDpy
.y
- h
) / 2;
425 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
427 wxLogLastError(wxT("MoveWindow"));
430 if ( !title
.empty() )
432 ::SetWindowText(GetHwnd(), title
);
438 #endif // __WXMICROWIN__/!__WXMICROWIN__
441 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
446 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
448 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
451 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
453 const wxString
& title
,
457 const wxString
& name
)
459 bool ret
wxDUMMY_INITIALIZE(false);
464 m_windowStyle
= style
;
468 m_windowId
= id
== -1 ? NewControlId() : id
;
470 wxTopLevelWindows
.Append(this);
473 parent
->AddChild(this);
475 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
477 // we have different dialog templates to allows creation of dialogs
478 // with & without captions under MSWindows, resizeable or not (but a
479 // resizeable dialog always has caption - otherwise it would look too
482 // we need 3 additional WORDs for dialog menu, class and title (as we
483 // don't use DS_SETFONT we don't need the fourth WORD for the font)
484 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
485 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
486 memset(dlgTemplate
, 0, dlgsize
);
488 // these values are arbitrary, they won't be used normally anyhow
491 dlgTemplate
->cx
= 144;
492 dlgTemplate
->cy
= 75;
494 // reuse the code in MSWGetStyle() but correct the results slightly for
496 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
498 // all dialogs are popups
499 dlgTemplate
->style
|= WS_POPUP
;
501 // force 3D-look if necessary, it looks impossibly ugly otherwise
502 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
503 dlgTemplate
->style
|= DS_MODALFRAME
;
505 ret
= CreateDialog(dlgTemplate
, title
, pos
, size
);
510 ret
= CreateFrame(title
, pos
, size
);
513 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
515 EnableCloseButton(false);
518 // for some reason we need to manually send ourselves this message as
519 // otherwise the mnemonics are always shown -- even if they're configured
520 // to be hidden until "Alt" is pressed in the control panel
522 // this could indicate a bug somewhere else but for now this is the only
530 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
538 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
540 if ( wxModelessWindows
.Find(this) )
541 wxModelessWindows
.DeleteObject(this);
543 // after destroying an owned window, Windows activates the next top level
544 // window in Z order but it may be different from our owner (to reproduce
545 // this simply Alt-TAB to another application and back before closing the
546 // owned frame) whereas we always want to yield activation to our parent
547 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
549 wxWindow
*parent
= GetParent();
552 ::BringWindowToTop(GetHwndOf(parent
));
557 // ----------------------------------------------------------------------------
558 // wxTopLevelWindowMSW showing
559 // ----------------------------------------------------------------------------
561 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
563 ::ShowWindow(GetHwnd(), nShowCmd
);
565 m_iconized
= nShowCmd
== SW_MINIMIZE
;
568 bool wxTopLevelWindowMSW::Show(bool show
)
570 // don't use wxWindow version as we want to call DoShowWindow() ourselves
571 if ( !wxWindowBase::Show(show
) )
577 if ( m_maximizeOnShow
)
580 nShowCmd
= SW_MAXIMIZE
;
582 m_maximizeOnShow
= FALSE
;
586 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
587 nShowCmd
= SW_SHOWNA
;
597 DoShowWindow(nShowCmd
);
601 ::BringWindowToTop(GetHwnd());
603 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
604 event
.SetEventObject( this );
605 GetEventHandler()->ProcessEvent(event
);
609 // Try to highlight the correct window (the parent)
612 HWND hWndParent
= GetHwndOf(GetParent());
614 ::BringWindowToTop(hWndParent
);
621 // ----------------------------------------------------------------------------
622 // wxTopLevelWindowMSW maximize/minimize
623 // ----------------------------------------------------------------------------
625 void wxTopLevelWindowMSW::Maximize(bool maximize
)
629 // just maximize it directly
630 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
634 // we can't maximize the hidden frame because it shows it as well, so
635 // just remember that we should do it later in this case
636 m_maximizeOnShow
= maximize
;
640 bool wxTopLevelWindowMSW::IsMaximized() const
645 return ::IsZoomed(GetHwnd()) != 0;
649 void wxTopLevelWindowMSW::Iconize(bool iconize
)
651 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
654 bool wxTopLevelWindowMSW::IsIconized() const
659 // also update the current state
660 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
666 void wxTopLevelWindowMSW::Restore()
668 DoShowWindow(SW_RESTORE
);
671 // ----------------------------------------------------------------------------
672 // wxTopLevelWindowMSW fullscreen
673 // ----------------------------------------------------------------------------
675 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
677 if ( show
== IsFullScreen() )
683 m_fsIsShowing
= show
;
689 // zap the frame borders
691 // save the 'normal' window style
692 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
694 // save the old position, width & height, maximize state
695 m_fsOldSize
= GetRect();
696 m_fsIsMaximized
= IsMaximized();
698 // decide which window style flags to turn off
699 LONG newStyle
= m_fsOldWindowStyle
;
702 if (style
& wxFULLSCREEN_NOBORDER
)
704 offFlags
|= WS_BORDER
;
706 offFlags
|= WS_THICKFRAME
;
709 if (style
& wxFULLSCREEN_NOCAPTION
)
710 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
712 newStyle
&= ~offFlags
;
714 // change our window style to be compatible with full-screen mode
715 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
719 // resize to the size of the display containing us
720 int dpy
= wxDisplay::GetFromWindow(this);
721 if ( dpy
!= wxNOT_FOUND
)
723 rect
= wxDisplay(dpy
).GetGeometry();
725 else // fall back to the main desktop
726 #else // wxUSE_DISPLAY
728 // resize to the size of the desktop
729 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
731 // FIXME: size of the bottom menu (toolbar)
732 // should be taken in account
733 rect
.height
+= rect
.y
;
737 #endif // wxUSE_DISPLAY
741 // now flush the window style cache and actually go full-screen
742 long flags
= SWP_FRAMECHANGED
;
744 // showing the frame full screen should also show it if it's still
748 // don't call wxWindow version to avoid flicker from calling
749 // ::ShowWindow() -- we're going to show the window at the correct
750 // location directly below -- but do call the wxWindowBase version
751 // to sync the internal m_isShown flag
752 wxWindowBase::Show();
754 flags
|= SWP_SHOWWINDOW
;
757 SetWindowPos(GetHwnd(), HWND_TOP
,
758 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
761 #if defined(__WXWINCE__) && _WIN32_WCE < 400
762 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
765 // finally send an event allowing the window to relayout itself &c
766 wxSizeEvent
event(rect
.GetSize(), GetId());
767 GetEventHandler()->ProcessEvent(event
);
769 else // stop showing full screen
771 #if defined(__WXWINCE__) && _WIN32_WCE < 400
772 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
774 Maximize(m_fsIsMaximized
);
775 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
776 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
777 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
783 // ----------------------------------------------------------------------------
784 // wxTopLevelWindowMSW misc
785 // ----------------------------------------------------------------------------
787 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
789 SetIcons( wxIconBundle( icon
) );
792 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
794 wxTopLevelWindowBase::SetIcons(icons
);
796 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
797 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
798 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
800 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
801 (LPARAM
)GetHiconOf(sml
) );
804 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
805 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
807 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
808 (LPARAM
)GetHiconOf(big
) );
813 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
815 #if !defined(__WXMICROWIN__)
816 // get system (a.k.a. window) menu
817 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
820 // no system menu at all -- ok if we want to remove the close button
821 // anyhow, but bad if we want to show it
825 // enabling/disabling the close item from it also automatically
826 // disables/enables the close title bar button
827 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
829 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
831 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
836 // update appearance immediately
837 if ( !::DrawMenuBar(GetHwnd()) )
839 wxLogLastError(_T("DrawMenuBar"));
841 #endif // !__WXMICROWIN__
846 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
851 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
852 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
854 // The empty region signifies that the shape should be removed from the
856 if ( region
.IsEmpty() )
858 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
860 wxLogLastError(_T("SetWindowRgn"));
866 // Windows takes ownership of the region, so
867 // we'll have to make a copy of the region to give to it.
868 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
869 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
870 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
871 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
872 delete[] (char*) rgnData
;
874 // SetWindowRgn expects the region to be in coordinants
875 // relative to the window, not the client area. Figure
876 // out the offset, if any.
878 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
879 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
880 ::GetClientRect(GetHwnd(), &rect
);
881 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
882 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
884 // Now call the shape API with the new region.
885 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
887 wxLogLastError(_T("SetWindowRgn"));
894 // ----------------------------------------------------------------------------
895 // wxTopLevelWindow event handling
896 // ----------------------------------------------------------------------------
898 // Default activation behaviour - set the focus for the first child
900 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
902 if ( event
.GetActive() )
904 // restore focus to the child which was last focused unless we already
906 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
908 wxWindow
*winFocus
= FindFocus();
909 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
911 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
918 wxSetFocusToChild(parent
, &m_winLastFocused
);
923 // remember the last focused child if it is our child
924 m_winLastFocused
= FindFocus();
926 if ( m_winLastFocused
)
928 // let it know that it doesn't have focus any more
929 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
931 // and don't remember it if it's a child from some other frame
932 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
934 m_winLastFocused
= NULL
;
938 wxLogTrace(_T("focus"),
939 _T("wxTLW %08x deactivated, last focused: %08x."),
941 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
948 // the DialogProc for all wxWindows dialogs
949 LONG APIENTRY _EXPORT
950 wxDlgProc(HWND
WXUNUSED(hDlg
),
952 WPARAM
WXUNUSED(wParam
),
953 LPARAM
WXUNUSED(lParam
))
958 // for this message, returning TRUE tells system to set focus to
959 // the first control in the dialog box, but as we set the focus
960 // ourselves, we return FALSE from here as well, so fall through
963 // for all the other ones, FALSE means that we didn't process the
969 // ============================================================================
970 // wxTLWHiddenParentModule implementation
971 // ============================================================================
973 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
975 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
977 bool wxTLWHiddenParentModule::OnInit()
985 void wxTLWHiddenParentModule::OnExit()
989 if ( !::DestroyWindow(ms_hwnd
) )
991 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
999 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1001 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1004 ms_className
= NULL
;
1009 HWND
wxTLWHiddenParentModule::GetHWND()
1013 if ( !ms_className
)
1015 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1018 wxZeroMemory(wndclass
);
1020 wndclass
.lpfnWndProc
= DefWindowProc
;
1021 wndclass
.hInstance
= wxGetInstance();
1022 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1024 if ( !::RegisterClass(&wndclass
) )
1026 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1030 ms_className
= HIDDEN_PARENT_CLASS
;
1034 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1035 (HMENU
)NULL
, wxGetInstance(), NULL
);
1038 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));