]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/toplevel.cpp
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 // the name of the default wxWindows class
90 extern wxChar
*wxCanvasClassName
;
92 extern const wxChar
*wxCanvasClassName
;
95 // ----------------------------------------------------------------------------
96 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
97 // module to ensure that the window is always deleted)
98 // ----------------------------------------------------------------------------
100 class wxTLWHiddenParentModule
: public wxModule
103 // module init/finalize
104 virtual bool OnInit();
105 virtual void OnExit();
107 // get the hidden window (creates on demand)
108 static HWND
GetHWND();
111 // the HWND of the hidden parent
114 // the class used to create it
115 static const wxChar
*ms_className
;
117 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
120 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
122 // ============================================================================
123 // wxTopLevelWindowMSW implementation
124 // ============================================================================
126 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
127 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
130 // ----------------------------------------------------------------------------
131 // wxTopLevelWindowMSW creation
132 // ----------------------------------------------------------------------------
134 void wxTopLevelWindowMSW::Init()
137 m_maximizeOnShow
= FALSE
;
139 // Data to save/restore when calling ShowFullScreen
141 m_fsOldWindowStyle
= 0;
142 m_fsIsMaximized
= FALSE
;
143 m_fsIsShowing
= FALSE
;
145 m_winLastFocused
= (wxWindow
*)NULL
;
148 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
150 // let the base class deal with the common styles but fix the ones which
151 // don't make sense for us (we also deal with the borders ourselves)
152 WXDWORD msflags
= wxWindow::MSWGetStyle
154 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
155 ) & ~WS_CHILD
& ~WS_VISIBLE
;
157 #if defined(__WXWINCE__) && _WIN32_WCE < 400
158 msflags
|= WS_VISIBLE
;
161 // first select the kind of window being created
163 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
164 // creates a window with both caption and border, hence we also test it
165 // below in some other cases
166 if ( style
& wxFRAME_TOOL_WINDOW
)
170 //else: WS_OVERLAPPED is 0 anyhow, so it is on by default
172 // border and caption styles
173 if ( style
& wxRESIZE_BORDER
)
174 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
;
182 // normally we consider that all windows without caption must be popups,
183 // but CE is an exception: there windows normally do not have the caption
184 // but shouldn't be made popups as popups can't have menus and don't look
185 // like normal windows anyhow
186 if ( style
& wxCAPTION
)
187 msflags
|= WS_CAPTION
;
191 #endif // !__WXWINCE__
193 // next translate the individual flags
194 if ( style
& wxMINIMIZE_BOX
)
195 msflags
|= WS_MINIMIZEBOX
;
196 if ( style
& wxMAXIMIZE_BOX
)
197 msflags
|= WS_MAXIMIZEBOX
;
198 if ( style
& wxSYSTEM_MENU
)
199 msflags
|= WS_SYSMENU
;
201 // NB: under CE these 2 styles are not supported currently, we should
202 // call Minimize()/Maximize() "manually" if we want to support them
203 if ( style
& wxMINIMIZE
)
204 msflags
|= WS_MINIMIZE
;
205 if ( style
& wxMAXIMIZE
)
206 msflags
|= WS_MAXIMIZE
;
208 // Keep this here because it saves recoding this function in wxTinyFrame
209 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
210 msflags
|= WS_CAPTION
;
214 // there is no taskbar under CE, so omit all this
216 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
218 if ( style
& wxFRAME_TOOL_WINDOW
)
220 // create the palette-like window
221 *exflags
|= WS_EX_TOOLWINDOW
;
223 // tool windows shouldn't appear on the taskbar (as documented)
224 style
|= wxFRAME_NO_TASKBAR
;
227 // We have to solve 2 different problems here:
229 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
230 // taskbar even if they don't have a parent
232 // 2. frames without this style should appear in the taskbar even
233 // if they're owned (Windows only puts non owned windows into
234 // the taskbar normally)
236 // The second one is solved here by using WS_EX_APPWINDOW flag, the
237 // first one is dealt with in our MSWGetParent() method
239 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
241 // need to force the frame to appear in the taskbar
242 *exflags
|= WS_EX_APPWINDOW
;
244 //else: nothing to do [here]
246 #endif // !__WXWINCE__
248 if ( style
& wxSTAY_ON_TOP
)
249 *exflags
|= WS_EX_TOPMOST
;
251 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
252 *exflags
|= WS_EX_CONTEXTHELP
;
258 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
260 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
261 // parent HWND or it would be always on top of its parent which is not what
262 // we usually want (in fact, we only want it for frames with the
263 // wxFRAME_FLOAT_ON_PARENT flag)
264 HWND hwndParent
= NULL
;
265 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
267 const wxWindow
*parent
= GetParent();
271 // this flag doesn't make sense then and will be ignored
272 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
276 hwndParent
= GetHwndOf(parent
);
279 //else: don't float on parent, must not be owned
281 // now deal with the 2nd taskbar-related problem (see comments above in
283 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
286 hwndParent
= wxTLWHiddenParentModule::GetHWND();
289 return (WXHWND
)hwndParent
;
292 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
293 const wxString
& title
,
297 #ifdef __WXMICROWIN__
298 // no dialogs support under MicroWin yet
299 return CreateFrame(title
, pos
, size
);
300 #else // !__WXMICROWIN__
301 wxWindow
*parent
= GetParent();
303 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
304 // app window as parent - this avoids creating modal dialogs without
306 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
308 parent
= wxTheApp
->GetTopWindow();
312 // don't use transient windows as parents, this is dangerous as it
313 // can lead to a crash if the parent is destroyed before the child
315 // also don't use the window which is currently hidden as then the
316 // dialog would be hidden as well
317 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
325 m_hWnd
= (WXHWND
)::CreateDialogIndirect
328 (DLGTEMPLATE
*)dlgTemplate
,
329 parent
? GetHwndOf(parent
) : NULL
,
335 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
337 wxLogSysError(wxT("Can't create dialog using memory template"));
343 (void)MSWGetCreateWindowFlags(&exflags
);
347 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
348 ::SetWindowPos(GetHwnd(),
349 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
353 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
357 #if defined(__WIN95__)
358 // For some reason, the system menu is activated when we use the
359 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
360 if ( exflags
& WS_EX_CONTEXTHELP
)
362 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
365 wxIcon icon
= winTop
->GetIcon();
368 ::SendMessage(GetHwnd(), WM_SETICON
,
370 (LPARAM
)GetHiconOf(icon
));
376 // move the dialog to its initial position without forcing repainting
378 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
380 if ( x
== (int)CW_USEDEFAULT
)
382 // centre it on the screen - what else can we do?
383 wxSize sizeDpy
= wxGetDisplaySize();
385 x
= (sizeDpy
.x
- w
) / 2;
386 y
= (sizeDpy
.y
- h
) / 2;
390 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
392 wxLogLastError(wxT("MoveWindow"));
396 if ( !title
.empty() )
398 ::SetWindowText(GetHwnd(), title
);
404 #endif // __WXMICROWIN__/!__WXMICROWIN__
407 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
412 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
414 #if (defined(_WIN32_WCE) && _WIN32_WCE < 400) || \
415 defined(WIN32_PLATFORM_PSPC) || \
416 defined(WIN32_PLATFORM_WFSP)
417 // Always expand to fit the screen in PocketPC or SmartPhone
418 wxSize
sz(wxDefaultSize
);
419 #else // other (including normal desktop) Windows
423 return MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
426 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
428 const wxString
& title
,
432 const wxString
& name
)
434 bool ret
wxDUMMY_INITIALIZE(false);
439 wxSize sizeReal
= size
;
440 if ( !sizeReal
.IsFullySpecified() )
442 sizeReal
.SetDefaults(GetDefaultSize());
445 m_windowStyle
= style
;
449 m_windowId
= id
== -1 ? NewControlId() : id
;
451 wxTopLevelWindows
.Append(this);
454 parent
->AddChild(this);
456 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
458 // we have different dialog templates to allows creation of dialogs
459 // with & without captions under MSWindows, resizeable or not (but a
460 // resizeable dialog always has caption - otherwise it would look too
463 // we need 3 additional WORDs for dialog menu, class and title (as we
464 // don't use DS_SETFONT we don't need the fourth WORD for the font)
465 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
466 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
467 memset(dlgTemplate
, 0, dlgsize
);
469 // these values are arbitrary, they won't be used normally anyhow
472 dlgTemplate
->cx
= 144;
473 dlgTemplate
->cy
= 75;
475 // reuse the code in MSWGetStyle() but correct the results slightly for
477 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
479 // all dialogs are popups
480 dlgTemplate
->style
|= WS_POPUP
;
482 // force 3D-look if necessary, it looks impossibly ugly otherwise
483 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
484 dlgTemplate
->style
|= DS_MODALFRAME
;
486 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
491 ret
= CreateFrame(title
, pos
, sizeReal
);
494 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
496 EnableCloseButton(false);
499 // for some reason we need to manually send ourselves this message as
500 // otherwise the mnemonics are always shown -- even if they're configured
501 // to be hidden until "Alt" is pressed in the control panel
503 // this could indicate a bug somewhere else but for now this is the only
511 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
519 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
521 // after destroying an owned window, Windows activates the next top level
522 // window in Z order but it may be different from our owner (to reproduce
523 // this simply Alt-TAB to another application and back before closing the
524 // owned frame) whereas we always want to yield activation to our parent
525 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
527 wxWindow
*parent
= GetParent();
530 ::BringWindowToTop(GetHwndOf(parent
));
535 // ----------------------------------------------------------------------------
536 // wxTopLevelWindowMSW showing
537 // ----------------------------------------------------------------------------
539 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
541 ::ShowWindow(GetHwnd(), nShowCmd
);
543 m_iconized
= nShowCmd
== SW_MINIMIZE
;
546 bool wxTopLevelWindowMSW::Show(bool show
)
548 // don't use wxWindow version as we want to call DoShowWindow() ourselves
549 if ( !wxWindowBase::Show(show
) )
555 if ( m_maximizeOnShow
)
558 nShowCmd
= SW_MAXIMIZE
;
560 m_maximizeOnShow
= FALSE
;
564 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
565 nShowCmd
= SW_SHOWNA
;
575 DoShowWindow(nShowCmd
);
579 ::BringWindowToTop(GetHwnd());
581 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
582 event
.SetEventObject( this );
583 GetEventHandler()->ProcessEvent(event
);
587 // Try to highlight the correct window (the parent)
590 HWND hWndParent
= GetHwndOf(GetParent());
592 ::BringWindowToTop(hWndParent
);
599 // ----------------------------------------------------------------------------
600 // wxTopLevelWindowMSW maximize/minimize
601 // ----------------------------------------------------------------------------
603 void wxTopLevelWindowMSW::Maximize(bool maximize
)
607 // just maximize it directly
608 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
612 // we can't maximize the hidden frame because it shows it as well, so
613 // just remember that we should do it later in this case
614 m_maximizeOnShow
= maximize
;
618 bool wxTopLevelWindowMSW::IsMaximized() const
623 return ::IsZoomed(GetHwnd()) != 0;
627 void wxTopLevelWindowMSW::Iconize(bool iconize
)
629 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
632 bool wxTopLevelWindowMSW::IsIconized() const
637 // also update the current state
638 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
644 void wxTopLevelWindowMSW::Restore()
646 DoShowWindow(SW_RESTORE
);
649 // ----------------------------------------------------------------------------
650 // wxTopLevelWindowMSW fullscreen
651 // ----------------------------------------------------------------------------
653 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
655 if ( show
== IsFullScreen() )
661 m_fsIsShowing
= show
;
667 // zap the frame borders
669 // save the 'normal' window style
670 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
672 // save the old position, width & height, maximize state
673 m_fsOldSize
= GetRect();
674 m_fsIsMaximized
= IsMaximized();
676 // decide which window style flags to turn off
677 LONG newStyle
= m_fsOldWindowStyle
;
680 if (style
& wxFULLSCREEN_NOBORDER
)
682 offFlags
|= WS_BORDER
;
684 offFlags
|= WS_THICKFRAME
;
687 if (style
& wxFULLSCREEN_NOCAPTION
)
688 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
690 newStyle
&= ~offFlags
;
692 // change our window style to be compatible with full-screen mode
693 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
697 // resize to the size of the display containing us
698 int dpy
= wxDisplay::GetFromWindow(this);
699 if ( dpy
!= wxNOT_FOUND
)
701 rect
= wxDisplay(dpy
).GetGeometry();
703 else // fall back to the main desktop
704 #else // wxUSE_DISPLAY
706 // resize to the size of the desktop
707 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
709 // FIXME: size of the bottom menu (toolbar)
710 // should be taken in account
711 rect
.height
+= rect
.y
;
715 #endif // wxUSE_DISPLAY
719 // now flush the window style cache and actually go full-screen
720 long flags
= SWP_FRAMECHANGED
;
722 // showing the frame full screen should also show it if it's still
726 // don't call wxWindow version to avoid flicker from calling
727 // ::ShowWindow() -- we're going to show the window at the correct
728 // location directly below -- but do call the wxWindowBase version
729 // to sync the internal m_isShown flag
730 wxWindowBase::Show();
732 flags
|= SWP_SHOWWINDOW
;
735 SetWindowPos(GetHwnd(), HWND_TOP
,
736 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
739 #if defined(__WXWINCE__) && _WIN32_WCE < 400
740 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
743 // finally send an event allowing the window to relayout itself &c
744 wxSizeEvent
event(rect
.GetSize(), GetId());
745 GetEventHandler()->ProcessEvent(event
);
747 else // stop showing full screen
749 #if defined(__WXWINCE__) && _WIN32_WCE < 400
750 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
752 Maximize(m_fsIsMaximized
);
753 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
754 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
755 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
761 // ----------------------------------------------------------------------------
762 // wxTopLevelWindowMSW misc
763 // ----------------------------------------------------------------------------
765 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
767 SetIcons( wxIconBundle( icon
) );
770 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
772 wxTopLevelWindowBase::SetIcons(icons
);
774 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
775 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
776 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
778 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
779 (LPARAM
)GetHiconOf(sml
) );
782 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
783 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
785 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
786 (LPARAM
)GetHiconOf(big
) );
791 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
793 #if !defined(__WXMICROWIN__)
794 // get system (a.k.a. window) menu
795 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
798 // no system menu at all -- ok if we want to remove the close button
799 // anyhow, but bad if we want to show it
803 // enabling/disabling the close item from it also automatically
804 // disables/enables the close title bar button
805 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
807 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
809 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
814 // update appearance immediately
815 if ( !::DrawMenuBar(GetHwnd()) )
817 wxLogLastError(_T("DrawMenuBar"));
820 #endif // !__WXMICROWIN__
827 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
829 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
830 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
832 // The empty region signifies that the shape should be removed from the
834 if ( region
.IsEmpty() )
836 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
838 wxLogLastError(_T("SetWindowRgn"));
844 // Windows takes ownership of the region, so
845 // we'll have to make a copy of the region to give to it.
846 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
847 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
848 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
849 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
850 delete[] (char*) rgnData
;
852 // SetWindowRgn expects the region to be in coordinants
853 // relative to the window, not the client area. Figure
854 // out the offset, if any.
856 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
857 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
858 ::GetClientRect(GetHwnd(), &rect
);
859 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
860 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
862 // Now call the shape API with the new region.
863 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
865 wxLogLastError(_T("SetWindowRgn"));
871 #endif // !__WXWINCE__
873 // ----------------------------------------------------------------------------
874 // wxTopLevelWindow event handling
875 // ----------------------------------------------------------------------------
877 // Default activation behaviour - set the focus for the first child
879 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
881 if ( event
.GetActive() )
883 // restore focus to the child which was last focused unless we already
885 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
887 wxWindow
*winFocus
= FindFocus();
888 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
890 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
897 wxSetFocusToChild(parent
, &m_winLastFocused
);
902 // remember the last focused child if it is our child
903 m_winLastFocused
= FindFocus();
905 if ( m_winLastFocused
)
907 // let it know that it doesn't have focus any more
908 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
910 // and don't remember it if it's a child from some other frame
911 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
913 m_winLastFocused
= NULL
;
917 wxLogTrace(_T("focus"),
918 _T("wxTLW %08x deactivated, last focused: %08x."),
920 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
927 // the DialogProc for all wxWindows dialogs
928 LONG APIENTRY _EXPORT
931 WPARAM
WXUNUSED(wParam
),
932 LPARAM
WXUNUSED(lParam
))
934 if ( message
== WM_INITDIALOG
)
936 // under CE, add a "Ok" button in the dialog title bar and make it full
939 // VZ: we should probably allow for overriding this, e.g. by including
940 // MAXIMIZED flag in the dialog style by default and doing this
941 // only if it is present...
943 // Standard SDK doesn't have aygshell.dll: see
944 // include/wx/msw/wince/libraries.h
945 #if defined(__WXWINCE__) && !defined(WCE_PLATFORM_STANDARDSDK)
947 shidi
.dwMask
= SHIDIM_FLAGS
;
948 shidi
.dwFlags
= SHIDIF_DONEBUTTON
|
949 SHIDIF_SIZEDLGFULLSCREEN
;
951 SHInitDialog( &shidi
);
952 #else // no SHInitDialog()
957 // for almost all messages, returning FALSE means that we didn't process
960 // for WM_INITDIALOG, returning TRUE tells system to set focus to
961 // the first control in the dialog box, but as we set the focus
962 // ourselves, we return FALSE for it as well
966 // ============================================================================
967 // wxTLWHiddenParentModule implementation
968 // ============================================================================
970 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
972 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
974 bool wxTLWHiddenParentModule::OnInit()
982 void wxTLWHiddenParentModule::OnExit()
986 if ( !::DestroyWindow(ms_hwnd
) )
988 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
996 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
998 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1001 ms_className
= NULL
;
1006 HWND
wxTLWHiddenParentModule::GetHWND()
1010 if ( !ms_className
)
1012 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1015 wxZeroMemory(wndclass
);
1017 wndclass
.lpfnWndProc
= DefWindowProc
;
1018 wndclass
.hInstance
= wxGetInstance();
1019 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1021 if ( !::RegisterClass(&wndclass
) )
1023 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1027 ms_className
= HIDDEN_PARENT_CLASS
;
1031 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1032 (HMENU
)NULL
, wxGetInstance(), NULL
);
1035 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));