1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for MSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
34 #include "wx/string.h"
38 #include "wx/containr.h" // wxSetFocusToChild()
41 #include "wx/module.h"
43 #include "wx/msw/private.h"
44 #if defined(__WXWINCE__)
50 #include "wx/msw/wince/missing.h"
53 #include "wx/msw/missing.h"
54 #include "wx/msw/winundef.h"
56 // This can't be undefed in winundef.h or
57 // there are further errors
58 #if defined(__WXWINCE__) && defined(CreateDialog)
62 #include "wx/display.h"
72 // ----------------------------------------------------------------------------
73 // stubs for missing functions under MicroWindows
74 // ----------------------------------------------------------------------------
78 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
79 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
81 #endif // __WXMICROWIN__
83 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
84 // is not included by wxUniv build which does need wxDlgProc
86 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // list of all frames and modeless dialogs
93 wxWindowList wxModelessWindows
;
95 // the name of the default wxWindows class
96 extern const wxChar
*wxCanvasClassName
;
98 // ----------------------------------------------------------------------------
99 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
100 // module to ensure that the window is always deleted)
101 // ----------------------------------------------------------------------------
103 class wxTLWHiddenParentModule
: public wxModule
106 // module init/finalize
107 virtual bool OnInit();
108 virtual void OnExit();
110 // get the hidden window (creates on demand)
111 static HWND
GetHWND();
114 // the HWND of the hidden parent
117 // the class used to create it
118 static const wxChar
*ms_className
;
120 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
123 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
125 // ============================================================================
126 // wxTopLevelWindowMSW implementation
127 // ============================================================================
129 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
130 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
133 // ----------------------------------------------------------------------------
134 // wxTopLevelWindowMSW creation
135 // ----------------------------------------------------------------------------
137 void wxTopLevelWindowMSW::Init()
140 m_maximizeOnShow
= FALSE
;
142 // unlike (almost?) all other windows, frames are created hidden
145 // Data to save/restore when calling ShowFullScreen
147 m_fsOldWindowStyle
= 0;
148 m_fsIsMaximized
= FALSE
;
149 m_fsIsShowing
= FALSE
;
151 m_winLastFocused
= (wxWindow
*)NULL
;
154 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
156 // let the base class deal with the common styles but fix the ones which
157 // don't make sense for us (we also deal with the borders ourselves)
158 WXDWORD msflags
= wxWindow::MSWGetStyle
160 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
161 ) & ~WS_CHILD
& ~WS_VISIBLE
;
163 // first select the kind of window being created
165 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
166 // creates a window with both caption and border, hence we also test it
167 // below in some other cases
168 if ( style
& wxFRAME_TOOL_WINDOW
)
173 if (msflags
& WS_BORDER
)
175 msflags
|= WS_OVERLAPPED
;
178 // border and caption styles
179 if ( style
& wxRESIZE_BORDER
)
182 msflags
|= WS_THICKFRAME
;
185 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
186 *exflags
|= WS_EX_DLGMODALFRAME
;
187 else if ( !(style
& wxBORDER_NONE
) )
188 msflags
|= WS_BORDER
;
194 if ( style
& wxCAPTION
)
195 msflags
|= WS_CAPTION
;
201 // next translate the individual flags
202 if ( style
& wxMINIMIZE_BOX
)
203 msflags
|= WS_MINIMIZEBOX
;
204 if ( style
& wxMAXIMIZE_BOX
)
205 msflags
|= WS_MAXIMIZEBOX
;
206 if ( style
& wxSYSTEM_MENU
)
207 msflags
|= WS_SYSMENU
;
209 if ( style
& wxMINIMIZE
)
210 msflags
|= WS_MINIMIZE
;
211 if ( style
& wxMAXIMIZE
)
212 msflags
|= WS_MAXIMIZE
;
215 // Keep this here because it saves recoding this function in wxTinyFrame
216 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
217 if ( style
& wxTINY_CAPTION_VERT
)
218 msflags
|= IBS_VERTCAPTION
;
219 if ( style
& wxTINY_CAPTION_HORIZ
)
220 msflags
|= IBS_HORZCAPTION
;
222 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
223 msflags
|= WS_CAPTION
;
228 #if !defined(__WIN16__)
229 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
231 if ( style
& wxFRAME_TOOL_WINDOW
)
233 // create the palette-like window
234 *exflags
|= WS_EX_TOOLWINDOW
;
236 // tool windows shouldn't appear on the taskbar (as documented)
237 style
|= wxFRAME_NO_TASKBAR
;
240 // We have to solve 2 different problems here:
242 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
243 // taskbar even if they don't have a parent
245 // 2. frames without this style should appear in the taskbar even
246 // if they're owned (Windows only puts non owned windows into
247 // the taskbar normally)
249 // The second one is solved here by using WS_EX_APPWINDOW flag, the
250 // first one is dealt with in our MSWGetParent() method
253 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
255 // need to force the frame to appear in the taskbar
256 *exflags
|= WS_EX_APPWINDOW
;
259 //else: nothing to do [here]
263 if ( style
& wxSTAY_ON_TOP
)
264 *exflags
|= WS_EX_TOPMOST
;
267 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
268 *exflags
|= WS_EX_CONTEXTHELP
;
275 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
277 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
278 // parent HWND or it would be always on top of its parent which is not what
279 // we usually want (in fact, we only want it for frames with the
280 // wxFRAME_FLOAT_ON_PARENT flag)
281 HWND hwndParent
= NULL
;
282 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
284 const wxWindow
*parent
= GetParent();
288 // this flag doesn't make sense then and will be ignored
289 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
293 hwndParent
= GetHwndOf(parent
);
296 //else: don't float on parent, must not be owned
298 // now deal with the 2nd taskbar-related problem (see comments above in
300 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
303 hwndParent
= wxTLWHiddenParentModule::GetHWND();
306 return (WXHWND
)hwndParent
;
309 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
310 const wxString
& title
,
314 #ifdef __WXMICROWIN__
315 // no dialogs support under MicroWin yet
316 return CreateFrame(title
, pos
, size
);
317 #else // !__WXMICROWIN__
318 wxWindow
*parent
= GetParent();
320 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
321 // app window as parent - this avoids creating modal dialogs without
323 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
325 parent
= wxTheApp
->GetTopWindow();
329 // don't use transient windows as parents, this is dangerous as it
330 // can lead to a crash if the parent is destroyed before the child
332 // also don't use the window which is currently hidden as then the
333 // dialog would be hidden as well
334 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
342 m_hWnd
= (WXHWND
)::CreateDialogIndirect
345 (DLGTEMPLATE
*)dlgTemplate
,
346 parent
? GetHwndOf(parent
) : NULL
,
352 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
354 wxLogSysError(wxT("Can't create dialog using memory template"));
360 (void)MSWGetCreateWindowFlags(&exflags
);
364 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
365 ::SetWindowPos(GetHwnd(),
366 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
370 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
374 #if defined(__WIN95__)
375 // For some reason, the system menu is activated when we use the
376 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
377 if ( exflags
& WS_EX_CONTEXTHELP
)
379 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
382 wxIcon icon
= winTop
->GetIcon();
385 ::SendMessage(GetHwnd(), WM_SETICON
,
387 (LPARAM
)GetHiconOf(icon
));
393 // move the dialog to its initial position without forcing repainting
395 if ( !MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
) )
398 w
= (int)CW_USEDEFAULT
;
401 // we can't use CW_USEDEFAULT here as we're not calling CreateWindow()
402 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
403 // window to (0, 0) size which breaks quite a lot of things, e.g. the
404 // sizer calculation in wxSizer::Fit()
405 if ( w
== (int)CW_USEDEFAULT
)
407 // the exact number doesn't matter, the dialog will be resized
408 // again soon anyhow but it should be big enough to allow
409 // calculation relying on "totalSize - clientSize > 0" work, i.e.
410 // at least greater than the title bar height
415 if ( x
== (int)CW_USEDEFAULT
)
417 // centre it on the screen - what else can we do?
418 wxSize sizeDpy
= wxGetDisplaySize();
420 x
= (sizeDpy
.x
- w
) / 2;
421 y
= (sizeDpy
.y
- h
) / 2;
424 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
426 wxLogLastError(wxT("MoveWindow"));
429 if ( !title
.empty() )
431 ::SetWindowText(GetHwnd(), title
);
437 #endif // __WXMICROWIN__/!__WXMICROWIN__
440 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
445 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
447 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
450 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
452 const wxString
& title
,
456 const wxString
& name
)
458 bool ret
wxDUMMY_INITIALIZE(false);
463 m_windowStyle
= style
;
467 m_windowId
= id
== -1 ? NewControlId() : id
;
469 wxTopLevelWindows
.Append(this);
472 parent
->AddChild(this);
474 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
476 // we have different dialog templates to allows creation of dialogs
477 // with & without captions under MSWindows, resizeable or not (but a
478 // resizeable dialog always has caption - otherwise it would look too
481 // we need 3 additional WORDs for dialog menu, class and title (as we
482 // don't use DS_SETFONT we don't need the fourth WORD for the font)
483 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
484 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
485 memset(dlgTemplate
, 0, dlgsize
);
487 // these values are arbitrary, they won't be used normally anyhow
490 dlgTemplate
->cx
= 144;
491 dlgTemplate
->cy
= 75;
493 // reuse the code in MSWGetStyle() but correct the results slightly for
495 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
497 // all dialogs are popups
498 dlgTemplate
->style
|= WS_POPUP
;
500 // force 3D-look if necessary, it looks impossibly ugly otherwise
501 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
502 dlgTemplate
->style
|= DS_MODALFRAME
;
504 ret
= CreateDialog(dlgTemplate
, title
, pos
, size
);
509 ret
= CreateFrame(title
, pos
, size
);
512 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
514 EnableCloseButton(false);
517 // for some reason we need to manually send ourselves this message as
518 // otherwise the mnemonics are always shown -- even if they're configured
519 // to be hidden until "Alt" is pressed in the control panel
521 // this could indicate a bug somewhere else but for now this is the only
529 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
537 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
539 if ( wxModelessWindows
.Find(this) )
540 wxModelessWindows
.DeleteObject(this);
542 // after destroying an owned window, Windows activates the next top level
543 // window in Z order but it may be different from our owner (to reproduce
544 // this simply Alt-TAB to another application and back before closing the
545 // owned frame) whereas we always want to yield activation to our parent
546 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
548 wxWindow
*parent
= GetParent();
551 ::BringWindowToTop(GetHwndOf(parent
));
556 // ----------------------------------------------------------------------------
557 // wxTopLevelWindowMSW showing
558 // ----------------------------------------------------------------------------
560 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
562 ::ShowWindow(GetHwnd(), nShowCmd
);
564 m_iconized
= nShowCmd
== SW_MINIMIZE
;
567 bool wxTopLevelWindowMSW::Show(bool show
)
569 // don't use wxWindow version as we want to call DoShowWindow() ourselves
570 if ( !wxWindowBase::Show(show
) )
576 if ( m_maximizeOnShow
)
579 nShowCmd
= SW_MAXIMIZE
;
581 m_maximizeOnShow
= FALSE
;
585 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
586 nShowCmd
= SW_SHOWNA
;
596 DoShowWindow(nShowCmd
);
600 ::BringWindowToTop(GetHwnd());
602 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
603 event
.SetEventObject( this );
604 GetEventHandler()->ProcessEvent(event
);
608 // Try to highlight the correct window (the parent)
611 HWND hWndParent
= GetHwndOf(GetParent());
613 ::BringWindowToTop(hWndParent
);
620 // ----------------------------------------------------------------------------
621 // wxTopLevelWindowMSW maximize/minimize
622 // ----------------------------------------------------------------------------
624 void wxTopLevelWindowMSW::Maximize(bool maximize
)
628 // just maximize it directly
629 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
633 // we can't maximize the hidden frame because it shows it as well, so
634 // just remember that we should do it later in this case
635 m_maximizeOnShow
= maximize
;
639 bool wxTopLevelWindowMSW::IsMaximized() const
644 return ::IsZoomed(GetHwnd()) != 0;
648 void wxTopLevelWindowMSW::Iconize(bool iconize
)
650 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
653 bool wxTopLevelWindowMSW::IsIconized() const
658 // also update the current state
659 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
665 void wxTopLevelWindowMSW::Restore()
667 DoShowWindow(SW_RESTORE
);
670 // ----------------------------------------------------------------------------
671 // wxTopLevelWindowMSW fullscreen
672 // ----------------------------------------------------------------------------
674 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
676 if ( show
== IsFullScreen() )
682 m_fsIsShowing
= show
;
688 // zap the frame borders
690 // save the 'normal' window style
691 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
693 // save the old position, width & height, maximize state
694 m_fsOldSize
= GetRect();
695 m_fsIsMaximized
= IsMaximized();
697 // decide which window style flags to turn off
698 LONG newStyle
= m_fsOldWindowStyle
;
701 if (style
& wxFULLSCREEN_NOBORDER
)
703 offFlags
|= WS_BORDER
;
705 offFlags
|= WS_THICKFRAME
;
708 if (style
& wxFULLSCREEN_NOCAPTION
)
709 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
711 newStyle
&= ~offFlags
;
713 // change our window style to be compatible with full-screen mode
714 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
718 // resize to the size of the display containing us
719 int dpy
= wxDisplay::GetFromWindow(this);
720 if ( dpy
!= wxNOT_FOUND
)
722 rect
= wxDisplay(dpy
).GetGeometry();
724 else // fall back to the main desktop
725 #else // wxUSE_DISPLAY
727 // resize to the size of the desktop
728 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
730 // FIXME: size of the bottom menu (toolbar)
731 // should be taken in account
732 rect
.height
+= rect
.y
;
736 #endif // wxUSE_DISPLAY
740 // now flush the window style cache and actually go full-screen
741 long flags
= SWP_FRAMECHANGED
;
743 // showing the frame full screen should also show it if it's still
747 // don't call wxWindow version to avoid flicker from calling
748 // ::ShowWindow() -- we're going to show the window at the correct
749 // location directly below -- but do call the wxWindowBase version
750 // to sync the internal m_isShown flag
751 wxWindowBase::Show();
753 flags
|= SWP_SHOWWINDOW
;
756 SetWindowPos(GetHwnd(), HWND_TOP
,
757 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
760 #if defined(__WXWINCE__) && _WIN32_WCE < 400
761 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
764 // finally send an event allowing the window to relayout itself &c
765 wxSizeEvent
event(rect
.GetSize(), GetId());
766 GetEventHandler()->ProcessEvent(event
);
768 else // stop showing full screen
770 #if defined(__WXWINCE__) && _WIN32_WCE < 400
771 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
773 Maximize(m_fsIsMaximized
);
774 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
775 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
776 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
782 // ----------------------------------------------------------------------------
783 // wxTopLevelWindowMSW misc
784 // ----------------------------------------------------------------------------
786 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
788 SetIcons( wxIconBundle( icon
) );
791 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
793 wxTopLevelWindowBase::SetIcons(icons
);
795 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
796 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
797 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
799 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
800 (LPARAM
)GetHiconOf(sml
) );
803 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
804 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
806 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
807 (LPARAM
)GetHiconOf(big
) );
812 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
814 #if !defined(__WXMICROWIN__)
815 // get system (a.k.a. window) menu
816 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
819 // no system menu at all -- ok if we want to remove the close button
820 // anyhow, but bad if we want to show it
824 // enabling/disabling the close item from it also automatically
825 // disables/enables the close title bar button
826 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
828 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
830 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
835 // update appearance immediately
836 if ( !::DrawMenuBar(GetHwnd()) )
838 wxLogLastError(_T("DrawMenuBar"));
840 #endif // !__WXMICROWIN__
845 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
850 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
851 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
853 // The empty region signifies that the shape should be removed from the
855 if ( region
.IsEmpty() )
857 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
859 wxLogLastError(_T("SetWindowRgn"));
865 // Windows takes ownership of the region, so
866 // we'll have to make a copy of the region to give to it.
867 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
868 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
869 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
870 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
871 delete[] (char*) rgnData
;
873 // SetWindowRgn expects the region to be in coordinants
874 // relative to the window, not the client area. Figure
875 // out the offset, if any.
877 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
878 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
879 ::GetClientRect(GetHwnd(), &rect
);
880 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
881 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
883 // Now call the shape API with the new region.
884 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
886 wxLogLastError(_T("SetWindowRgn"));
893 // ----------------------------------------------------------------------------
894 // wxTopLevelWindow event handling
895 // ----------------------------------------------------------------------------
897 // Default activation behaviour - set the focus for the first child
899 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
901 if ( event
.GetActive() )
903 // restore focus to the child which was last focused unless we already
905 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
907 wxWindow
*winFocus
= FindFocus();
908 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
910 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
917 wxSetFocusToChild(parent
, &m_winLastFocused
);
922 // remember the last focused child if it is our child
923 m_winLastFocused
= FindFocus();
925 if ( m_winLastFocused
)
927 // let it know that it doesn't have focus any more
928 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
930 // and don't remember it if it's a child from some other frame
931 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
933 m_winLastFocused
= NULL
;
937 wxLogTrace(_T("focus"),
938 _T("wxTLW %08x deactivated, last focused: %08x."),
940 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
947 // the DialogProc for all wxWindows dialogs
948 LONG APIENTRY _EXPORT
949 wxDlgProc(HWND
WXUNUSED(hDlg
),
951 WPARAM
WXUNUSED(wParam
),
952 LPARAM
WXUNUSED(lParam
))
957 // for this message, returning TRUE tells system to set focus to
958 // the first control in the dialog box, but as we set the focus
959 // ourselves, we return FALSE from here as well, so fall through
962 // for all the other ones, FALSE means that we didn't process the
968 // ============================================================================
969 // wxTLWHiddenParentModule implementation
970 // ============================================================================
972 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
974 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
976 bool wxTLWHiddenParentModule::OnInit()
984 void wxTLWHiddenParentModule::OnExit()
988 if ( !::DestroyWindow(ms_hwnd
) )
990 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
998 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1000 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1003 ms_className
= NULL
;
1008 HWND
wxTLWHiddenParentModule::GetHWND()
1012 if ( !ms_className
)
1014 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1017 wxZeroMemory(wndclass
);
1019 wndclass
.lpfnWndProc
= DefWindowProc
;
1020 wndclass
.hInstance
= wxGetInstance();
1021 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1023 if ( !::RegisterClass(&wndclass
) )
1025 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1029 ms_className
= HIDDEN_PARENT_CLASS
;
1033 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1034 (HMENU
)NULL
, wxGetInstance(), NULL
);
1037 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));