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/dialog.h"
35 #include "wx/string.h"
39 #include "wx/containr.h" // wxSetFocusToChild()
42 #include "wx/module.h"
44 #include "wx/msw/private.h"
45 #if defined(__WXWINCE__)
48 // Standard SDK doesn't have aygshell.dll: see include/wx/msw/wince/libraries.h
49 #if _WIN32_WCE < 400 || !defined(WCE_PLATFORM_STANDARDSDK)
52 #include "wx/msw/wince/missing.h"
55 #include "wx/msw/missing.h"
56 #include "wx/msw/winundef.h"
58 #include "wx/display.h"
68 // ----------------------------------------------------------------------------
69 // stubs for missing functions under MicroWindows
70 // ----------------------------------------------------------------------------
74 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
75 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
77 #endif // __WXMICROWIN__
79 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
80 // is not included by wxUniv build which does need wxDlgProc
82 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 // list of all frames and modeless dialogs
89 wxWindowList wxModelessWindows
;
91 // the name of the default wxWindows class
93 extern wxChar
*wxCanvasClassName
;
95 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 // Data to save/restore when calling ShowFullScreen
144 m_fsOldWindowStyle
= 0;
145 m_fsIsMaximized
= FALSE
;
146 m_fsIsShowing
= FALSE
;
148 m_winLastFocused
= (wxWindow
*)NULL
;
151 WXDWORD wxTopLevelWindowMSW
::MSWGetStyle(long style
, WXDWORD
*exflags
) const
153 // let the base class deal with the common styles but fix the ones which
154 // don't make sense for us (we also deal with the borders ourselves)
155 WXDWORD msflags
= wxWindow
::MSWGetStyle
157 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
158 ) & ~WS_CHILD
& ~WS_VISIBLE
;
160 #if defined(__WXWINCE__) && _WIN32_WCE < 400
161 msflags
|= 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
)
173 //else: WS_OVERLAPPED is 0 anyhow, so it is on by default
175 // border and caption styles
176 if ( style
& wxRESIZE_BORDER
)
177 msflags
|= WS_THICKFRAME
;
178 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
179 *exflags
|= WS_EX_DLGMODALFRAME
;
180 else if ( !(style
& wxBORDER_NONE
) )
181 msflags
|= WS_BORDER
;
185 // normally we consider that all windows without caption must be popups,
186 // but CE is an exception: there windows normally do not have the caption
187 // but shouldn't be made popups as popups can't have menus and don't look
188 // like normal windows anyhow
189 if ( style
& wxCAPTION
)
190 msflags
|= WS_CAPTION
;
194 #endif // !__WXWINCE__
196 // next translate the individual flags
197 if ( style
& wxMINIMIZE_BOX
)
198 msflags
|= WS_MINIMIZEBOX
;
199 if ( style
& wxMAXIMIZE_BOX
)
200 msflags
|= WS_MAXIMIZEBOX
;
201 if ( style
& wxSYSTEM_MENU
)
202 msflags
|= WS_SYSMENU
;
204 // NB: under CE these 2 styles are not supported currently, we should
205 // call Minimize()/Maximize() "manually" if we want to support them
206 if ( style
& wxMINIMIZE
)
207 msflags
|= WS_MINIMIZE
;
208 if ( style
& wxMAXIMIZE
)
209 msflags
|= WS_MAXIMIZE
;
211 // Keep this here because it saves recoding this function in wxTinyFrame
212 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
213 msflags
|= WS_CAPTION
;
217 // there is no taskbar under CE, so omit all this
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
242 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
244 // need to force the frame to appear in the taskbar
245 *exflags
|= WS_EX_APPWINDOW
;
247 //else: nothing to do [here]
249 #endif // !__WXWINCE__
251 if ( style
& wxSTAY_ON_TOP
)
252 *exflags
|= WS_EX_TOPMOST
;
254 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
255 *exflags
|= WS_EX_CONTEXTHELP
;
261 WXHWND wxTopLevelWindowMSW
::MSWGetParent() const
263 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
264 // parent HWND or it would be always on top of its parent which is not what
265 // we usually want (in fact, we only want it for frames with the
266 // wxFRAME_FLOAT_ON_PARENT flag)
267 HWND hwndParent
= NULL
;
268 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
270 const wxWindow
*parent
= GetParent();
274 // this flag doesn't make sense then and will be ignored
275 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
279 hwndParent
= GetHwndOf(parent
);
282 //else: don't float on parent, must not be owned
284 // now deal with the 2nd taskbar-related problem (see comments above in
286 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
289 hwndParent
= wxTLWHiddenParentModule
::GetHWND();
292 return (WXHWND
)hwndParent
;
295 bool wxTopLevelWindowMSW
::CreateDialog(const void *dlgTemplate
,
296 const wxString
& title
,
300 #ifdef __WXMICROWIN__
301 // no dialogs support under MicroWin yet
302 return CreateFrame(title
, pos
, size
);
303 #else // !__WXMICROWIN__
304 wxWindow
*parent
= GetParent();
306 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
307 // app window as parent - this avoids creating modal dialogs without
309 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
311 parent
= wxTheApp
->GetTopWindow();
315 // don't use transient windows as parents, this is dangerous as it
316 // can lead to a crash if the parent is destroyed before the child
318 // also don't use the window which is currently hidden as then the
319 // dialog would be hidden as well
320 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
328 m_hWnd
= (WXHWND
)::CreateDialogIndirect
331 (DLGTEMPLATE
*)dlgTemplate
,
332 parent ?
GetHwndOf(parent
) : NULL
,
338 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
340 wxLogSysError(wxT("Can't create dialog using memory template"));
346 (void)MSWGetCreateWindowFlags(&exflags
);
350 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
351 ::SetWindowPos(GetHwnd(),
352 exflags
& WS_EX_TOPMOST ? HWND_TOPMOST
: 0,
356 (exflags
& WS_EX_TOPMOST ?
0 : SWP_NOZORDER
) |
360 #if defined(__WIN95__)
361 // For some reason, the system menu is activated when we use the
362 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
363 if ( exflags
& WS_EX_CONTEXTHELP
)
365 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
368 wxIcon icon
= winTop
->GetIcon();
371 ::SendMessage(GetHwnd(), WM_SETICON
,
373 (LPARAM
)GetHiconOf(icon
));
379 // move the dialog to its initial position without forcing repainting
381 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
383 if ( x
== (int)CW_USEDEFAULT
)
385 // centre it on the screen - what else can we do?
386 wxSize sizeDpy
= wxGetDisplaySize();
388 x
= (sizeDpy
.x
- w
) / 2;
389 y
= (sizeDpy
.y
- h
) / 2;
393 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
395 wxLogLastError(wxT("MoveWindow"));
399 if ( !title
.empty() )
401 ::SetWindowText(GetHwnd(), title
);
407 #endif // __WXMICROWIN__/!__WXMICROWIN__
410 bool wxTopLevelWindowMSW
::CreateFrame(const wxString
& title
,
415 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
417 #if _WIN32_WCE < 400 || defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
418 // Always expand to fit the screen in PocketPC or SmartPhone
419 wxSize
sz(wxDefaultSize
);
420 #else // other (including normal desktop) Windows
424 return MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
427 bool wxTopLevelWindowMSW
::Create(wxWindow
*parent
,
429 const wxString
& title
,
433 const wxString
& name
)
435 bool ret
wxDUMMY_INITIALIZE(false);
440 wxSize sizeReal
= size
;
441 if ( !sizeReal
.IsFullySpecified() )
443 sizeReal
.SetDefaults(GetDefaultSize());
446 m_windowStyle
= style
;
450 m_windowId
= id
== -1 ?
NewControlId() : id
;
452 wxTopLevelWindows
.Append(this);
455 parent
->AddChild(this);
457 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
459 // we have different dialog templates to allows creation of dialogs
460 // with & without captions under MSWindows, resizeable or not (but a
461 // resizeable dialog always has caption - otherwise it would look too
464 // we need 3 additional WORDs for dialog menu, class and title (as we
465 // don't use DS_SETFONT we don't need the fourth WORD for the font)
466 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
467 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
468 memset(dlgTemplate
, 0, dlgsize
);
470 // these values are arbitrary, they won't be used normally anyhow
473 dlgTemplate
->cx
= 144;
474 dlgTemplate
->cy
= 75;
476 // reuse the code in MSWGetStyle() but correct the results slightly for
478 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
480 // all dialogs are popups
481 dlgTemplate
->style
|= WS_POPUP
;
483 // force 3D-look if necessary, it looks impossibly ugly otherwise
484 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
485 dlgTemplate
->style
|= DS_MODALFRAME
;
487 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
492 ret
= CreateFrame(title
, pos
, sizeReal
);
495 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
497 EnableCloseButton(false);
500 // for some reason we need to manually send ourselves this message as
501 // otherwise the mnemonics are always shown -- even if they're configured
502 // to be hidden until "Alt" is pressed in the control panel
504 // this could indicate a bug somewhere else but for now this is the only
512 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
520 wxTopLevelWindowMSW
::~wxTopLevelWindowMSW()
522 if ( wxModelessWindows
.Find(this) )
523 wxModelessWindows
.DeleteObject(this);
525 // after destroying an owned window, Windows activates the next top level
526 // window in Z order but it may be different from our owner (to reproduce
527 // this simply Alt-TAB to another application and back before closing the
528 // owned frame) whereas we always want to yield activation to our parent
529 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
531 wxWindow
*parent
= GetParent();
534 ::BringWindowToTop(GetHwndOf(parent
));
539 // ----------------------------------------------------------------------------
540 // wxTopLevelWindowMSW showing
541 // ----------------------------------------------------------------------------
543 void wxTopLevelWindowMSW
::DoShowWindow(int nShowCmd
)
545 ::ShowWindow(GetHwnd(), nShowCmd
);
547 m_iconized
= nShowCmd
== SW_MINIMIZE
;
550 bool wxTopLevelWindowMSW
::Show(bool show
)
552 // don't use wxWindow version as we want to call DoShowWindow() ourselves
553 if ( !wxWindowBase
::Show(show
) )
559 if ( m_maximizeOnShow
)
562 nShowCmd
= SW_MAXIMIZE
;
564 m_maximizeOnShow
= FALSE
;
568 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
569 nShowCmd
= SW_SHOWNA
;
579 DoShowWindow(nShowCmd
);
583 ::BringWindowToTop(GetHwnd());
585 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
586 event
.SetEventObject( this );
587 GetEventHandler()->ProcessEvent(event
);
591 // Try to highlight the correct window (the parent)
594 HWND hWndParent
= GetHwndOf(GetParent());
596 ::BringWindowToTop(hWndParent
);
603 // ----------------------------------------------------------------------------
604 // wxTopLevelWindowMSW maximize/minimize
605 // ----------------------------------------------------------------------------
607 void wxTopLevelWindowMSW
::Maximize(bool maximize
)
611 // just maximize it directly
612 DoShowWindow(maximize ? SW_MAXIMIZE
: SW_RESTORE
);
616 // we can't maximize the hidden frame because it shows it as well, so
617 // just remember that we should do it later in this case
618 m_maximizeOnShow
= maximize
;
622 bool wxTopLevelWindowMSW
::IsMaximized() const
627 return ::IsZoomed(GetHwnd()) != 0;
631 void wxTopLevelWindowMSW
::Iconize(bool iconize
)
633 DoShowWindow(iconize ? SW_MINIMIZE
: SW_RESTORE
);
636 bool wxTopLevelWindowMSW
::IsIconized() const
641 // also update the current state
642 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
648 void wxTopLevelWindowMSW
::Restore()
650 DoShowWindow(SW_RESTORE
);
653 // ----------------------------------------------------------------------------
654 // wxTopLevelWindowMSW fullscreen
655 // ----------------------------------------------------------------------------
657 bool wxTopLevelWindowMSW
::ShowFullScreen(bool show
, long style
)
659 if ( show
== IsFullScreen() )
665 m_fsIsShowing
= show
;
671 // zap the frame borders
673 // save the 'normal' window style
674 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
676 // save the old position, width & height, maximize state
677 m_fsOldSize
= GetRect();
678 m_fsIsMaximized
= IsMaximized();
680 // decide which window style flags to turn off
681 LONG newStyle
= m_fsOldWindowStyle
;
684 if (style
& wxFULLSCREEN_NOBORDER
)
686 offFlags
|= WS_BORDER
;
688 offFlags
|= WS_THICKFRAME
;
691 if (style
& wxFULLSCREEN_NOCAPTION
)
692 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
694 newStyle
&= ~offFlags
;
696 // change our window style to be compatible with full-screen mode
697 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
701 // resize to the size of the display containing us
702 int dpy
= wxDisplay
::GetFromWindow(this);
703 if ( dpy
!= wxNOT_FOUND
)
705 rect
= wxDisplay(dpy
).GetGeometry();
707 else // fall back to the main desktop
708 #else // wxUSE_DISPLAY
710 // resize to the size of the desktop
711 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
713 // FIXME: size of the bottom menu (toolbar)
714 // should be taken in account
715 rect
.height
+= rect
.y
;
719 #endif // wxUSE_DISPLAY
723 // now flush the window style cache and actually go full-screen
724 long flags
= SWP_FRAMECHANGED
;
726 // showing the frame full screen should also show it if it's still
730 // don't call wxWindow version to avoid flicker from calling
731 // ::ShowWindow() -- we're going to show the window at the correct
732 // location directly below -- but do call the wxWindowBase version
733 // to sync the internal m_isShown flag
734 wxWindowBase
::Show();
736 flags
|= SWP_SHOWWINDOW
;
739 SetWindowPos(GetHwnd(), HWND_TOP
,
740 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
743 #if defined(__WXWINCE__) && _WIN32_WCE < 400
744 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
747 // finally send an event allowing the window to relayout itself &c
748 wxSizeEvent
event(rect
.GetSize(), GetId());
749 GetEventHandler()->ProcessEvent(event
);
751 else // stop showing full screen
753 #if defined(__WXWINCE__) && _WIN32_WCE < 400
754 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
756 Maximize(m_fsIsMaximized
);
757 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
758 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
759 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
765 // ----------------------------------------------------------------------------
766 // wxTopLevelWindowMSW misc
767 // ----------------------------------------------------------------------------
769 void wxTopLevelWindowMSW
::SetIcon(const wxIcon
& icon
)
771 SetIcons( wxIconBundle( icon
) );
774 void wxTopLevelWindowMSW
::SetIcons(const wxIconBundle
& icons
)
776 wxTopLevelWindowBase
::SetIcons(icons
);
778 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
779 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
780 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
782 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
783 (LPARAM
)GetHiconOf(sml
) );
786 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
787 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
789 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
790 (LPARAM
)GetHiconOf(big
) );
795 bool wxTopLevelWindowMSW
::EnableCloseButton(bool enable
)
797 #if !defined(__WXMICROWIN__)
798 // get system (a.k.a. window) menu
799 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
802 // no system menu at all -- ok if we want to remove the close button
803 // anyhow, but bad if we want to show it
807 // enabling/disabling the close item from it also automatically
808 // disables/enables the close title bar button
809 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
811 (enable ? MF_ENABLED
: MF_GRAYED
)) == -1 )
813 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
818 // update appearance immediately
819 if ( !::DrawMenuBar(GetHwnd()) )
821 wxLogLastError(_T("DrawMenuBar"));
824 #endif // !__WXMICROWIN__
831 bool wxTopLevelWindowMSW
::SetShape(const wxRegion
& region
)
833 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
834 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
836 // The empty region signifies that the shape should be removed from the
838 if ( region
.IsEmpty() )
840 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
842 wxLogLastError(_T("SetWindowRgn"));
848 // Windows takes ownership of the region, so
849 // we'll have to make a copy of the region to give to it.
850 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
851 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
852 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
853 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
854 delete[] (char*) rgnData
;
856 // SetWindowRgn expects the region to be in coordinants
857 // relative to the window, not the client area. Figure
858 // out the offset, if any.
860 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
861 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
862 ::GetClientRect(GetHwnd(), &rect
);
863 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
864 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
866 // Now call the shape API with the new region.
867 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
869 wxLogLastError(_T("SetWindowRgn"));
875 #endif // !__WXWINCE__
877 // ----------------------------------------------------------------------------
878 // wxTopLevelWindow event handling
879 // ----------------------------------------------------------------------------
881 // Default activation behaviour - set the focus for the first child
883 void wxTopLevelWindowMSW
::OnActivate(wxActivateEvent
& event
)
885 if ( event
.GetActive() )
887 // restore focus to the child which was last focused unless we already
889 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
891 wxWindow
*winFocus
= FindFocus();
892 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
894 wxWindow
*parent
= m_winLastFocused ? m_winLastFocused
->GetParent()
901 wxSetFocusToChild(parent
, &m_winLastFocused
);
906 // remember the last focused child if it is our child
907 m_winLastFocused
= FindFocus();
909 if ( m_winLastFocused
)
911 // let it know that it doesn't have focus any more
912 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
914 // and don't remember it if it's a child from some other frame
915 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
917 m_winLastFocused
= NULL
;
921 wxLogTrace(_T("focus"),
922 _T("wxTLW %08x deactivated, last focused: %08x."),
924 (int) (m_winLastFocused ?
GetHwndOf(m_winLastFocused
)
931 // the DialogProc for all wxWindows dialogs
932 LONG APIENTRY _EXPORT
935 WPARAM
WXUNUSED(wParam
),
936 LPARAM
WXUNUSED(lParam
))
938 if ( message
== WM_INITDIALOG
)
940 // under CE, add a "Ok" button in the dialog title bar and make it full
943 // VZ: we should probably allow for overriding this, e.g. by including
944 // MAXIMIZED flag in the dialog style by default and doing this
945 // only if it is present...
947 // Standard SDK doesn't have aygshell.dll: see
948 // include/wx/msw/wince/libraries.h
949 #if defined(__WXWINCE__) && !defined(WCE_PLATFORM_STANDARDSDK)
951 shidi
.dwMask
= SHIDIM_FLAGS
;
952 shidi
.dwFlags
= SHIDIF_DONEBUTTON
|
953 SHIDIF_SIZEDLGFULLSCREEN
;
955 SHInitDialog( &shidi
);
956 #else // no SHInitDialog()
961 // for almost all messages, returning FALSE means that we didn't process
964 // for WM_INITDIALOG, returning TRUE tells system to set focus to
965 // the first control in the dialog box, but as we set the focus
966 // ourselves, we return FALSE for it as well
970 // ============================================================================
971 // wxTLWHiddenParentModule implementation
972 // ============================================================================
974 HWND wxTLWHiddenParentModule
::ms_hwnd
= NULL
;
976 const wxChar
*wxTLWHiddenParentModule
::ms_className
= NULL
;
978 bool wxTLWHiddenParentModule
::OnInit()
986 void wxTLWHiddenParentModule
::OnExit()
990 if ( !::DestroyWindow(ms_hwnd
) )
992 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1000 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1002 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1005 ms_className
= NULL
;
1010 HWND wxTLWHiddenParentModule
::GetHWND()
1014 if ( !ms_className
)
1016 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1019 wxZeroMemory(wndclass
);
1021 wndclass
.lpfnWndProc
= DefWindowProc
;
1022 wndclass
.hInstance
= wxGetInstance();
1023 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1025 if ( !::RegisterClass(&wndclass
) )
1027 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1031 ms_className
= HIDDEN_PARENT_CLASS
;
1035 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1036 (HMENU
)NULL
, wxGetInstance(), NULL
);
1039 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));