]>
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 wxWidgets 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 #ifndef __SMARTPHONE__
173 // border and caption styles
174 if ( style
& wxRESIZE_BORDER
)
175 msflags
|= WS_THICKFRAME
;
176 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
177 *exflags
|= WS_EX_DLGMODALFRAME
;
178 else if ( !(style
& wxBORDER_NONE
) )
179 msflags
|= WS_BORDER
;
184 // normally we consider that all windows without caption must be popups,
185 // but CE is an exception: there windows normally do not have the caption
186 // but shouldn't be made popups as popups can't have menus and don't look
187 // like normal windows anyhow
188 if ( style
& wxCAPTION
)
189 msflags
|= WS_CAPTION
;
193 #endif // !__WXWINCE__
195 // next translate the individual flags
196 if ( style
& wxMINIMIZE_BOX
)
197 msflags
|= WS_MINIMIZEBOX
;
198 if ( style
& wxMAXIMIZE_BOX
)
199 msflags
|= WS_MAXIMIZEBOX
;
200 if ( style
& wxSYSTEM_MENU
)
201 msflags
|= WS_SYSMENU
;
203 // NB: under CE these 2 styles are not supported currently, we should
204 // call Minimize()/Maximize() "manually" if we want to support them
205 if ( style
& wxMINIMIZE
)
206 msflags
|= WS_MINIMIZE
;
207 if ( style
& wxMAXIMIZE
)
208 msflags
|= WS_MAXIMIZE
;
210 // Keep this here because it saves recoding this function in wxTinyFrame
211 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
212 msflags
|= WS_CAPTION
;
216 // there is no taskbar under CE, so omit all this
218 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
220 if ( style
& wxFRAME_TOOL_WINDOW
)
222 // create the palette-like window
223 *exflags
|= WS_EX_TOOLWINDOW
;
225 // tool windows shouldn't appear on the taskbar (as documented)
226 style
|= wxFRAME_NO_TASKBAR
;
229 // We have to solve 2 different problems here:
231 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
232 // taskbar even if they don't have a parent
234 // 2. frames without this style should appear in the taskbar even
235 // if they're owned (Windows only puts non owned windows into
236 // the taskbar normally)
238 // The second one is solved here by using WS_EX_APPWINDOW flag, the
239 // first one is dealt with in our MSWGetParent() method
241 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
243 // need to force the frame to appear in the taskbar
244 *exflags
|= WS_EX_APPWINDOW
;
246 //else: nothing to do [here]
248 #endif // !__WXWINCE__
250 if ( style
& wxSTAY_ON_TOP
)
251 *exflags
|= WS_EX_TOPMOST
;
253 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
254 *exflags
|= WS_EX_CONTEXTHELP
;
260 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
262 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
263 // parent HWND or it would be always on top of its parent which is not what
264 // we usually want (in fact, we only want it for frames with the
265 // wxFRAME_FLOAT_ON_PARENT flag)
266 HWND hwndParent
= NULL
;
267 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
269 const wxWindow
*parent
= GetParent();
273 // this flag doesn't make sense then and will be ignored
274 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
278 hwndParent
= GetHwndOf(parent
);
281 //else: don't float on parent, must not be owned
283 // now deal with the 2nd taskbar-related problem (see comments above in
285 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
288 hwndParent
= wxTLWHiddenParentModule::GetHWND();
291 return (WXHWND
)hwndParent
;
294 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
295 const wxString
& title
,
299 #ifdef __WXMICROWIN__
300 // no dialogs support under MicroWin yet
301 return CreateFrame(title
, pos
, size
);
302 #else // !__WXMICROWIN__
303 wxWindow
*parent
= GetParent();
305 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
306 // app window as parent - this avoids creating modal dialogs without
308 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
310 parent
= wxTheApp
->GetTopWindow();
314 // don't use transient windows as parents, this is dangerous as it
315 // can lead to a crash if the parent is destroyed before the child
317 // also don't use the window which is currently hidden as then the
318 // dialog would be hidden as well
319 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
327 m_hWnd
= (WXHWND
)::CreateDialogIndirect
330 (DLGTEMPLATE
*)dlgTemplate
,
331 parent
? GetHwndOf(parent
) : NULL
,
337 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
339 wxLogSysError(wxT("Can't create dialog using memory template"));
345 (void)MSWGetCreateWindowFlags(&exflags
);
349 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
350 ::SetWindowPos(GetHwnd(),
351 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
355 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
359 #if defined(__WIN95__)
360 // For some reason, the system menu is activated when we use the
361 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
362 if ( exflags
& WS_EX_CONTEXTHELP
)
364 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
367 wxIcon icon
= winTop
->GetIcon();
370 ::SendMessage(GetHwnd(), WM_SETICON
,
372 (LPARAM
)GetHiconOf(icon
));
378 // move the dialog to its initial position without forcing repainting
380 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
382 if ( x
== (int)CW_USEDEFAULT
)
384 // centre it on the screen - what else can we do?
385 wxSize sizeDpy
= wxGetDisplaySize();
387 x
= (sizeDpy
.x
- w
) / 2;
388 y
= (sizeDpy
.y
- h
) / 2;
392 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
394 wxLogLastError(wxT("MoveWindow"));
398 if ( !title
.empty() )
400 ::SetWindowText(GetHwnd(), title
);
406 #endif // __WXMICROWIN__/!__WXMICROWIN__
409 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
414 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
416 #if (defined(_WIN32_WCE) && _WIN32_WCE < 400) || \
417 defined(WIN32_PLATFORM_PSPC) || \
418 defined(__SMARTPHONE__)
419 // Always expand to fit the screen in PocketPC or SmartPhone
420 wxSize
sz(wxDefaultSize
);
421 #else // other (including normal desktop) Windows
425 return MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
428 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
430 const wxString
& title
,
434 const wxString
& name
)
436 bool ret
wxDUMMY_INITIALIZE(false);
441 wxSize sizeReal
= size
;
442 if ( !sizeReal
.IsFullySpecified() )
444 sizeReal
.SetDefaults(GetDefaultSize());
447 m_windowStyle
= style
;
451 m_windowId
= id
== -1 ? NewControlId() : id
;
453 wxTopLevelWindows
.Append(this);
456 parent
->AddChild(this);
458 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
460 // we have different dialog templates to allows creation of dialogs
461 // with & without captions under MSWindows, resizeable or not (but a
462 // resizeable dialog always has caption - otherwise it would look too
465 // we need 3 additional WORDs for dialog menu, class and title (as we
466 // don't use DS_SETFONT we don't need the fourth WORD for the font)
467 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
468 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
469 memset(dlgTemplate
, 0, dlgsize
);
471 // these values are arbitrary, they won't be used normally anyhow
474 dlgTemplate
->cx
= 144;
475 dlgTemplate
->cy
= 75;
477 // reuse the code in MSWGetStyle() but correct the results slightly for
479 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
481 // all dialogs are popups
482 dlgTemplate
->style
|= WS_POPUP
;
484 // force 3D-look if necessary, it looks impossibly ugly otherwise
485 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
486 dlgTemplate
->style
|= DS_MODALFRAME
;
488 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
493 ret
= CreateFrame(title
, pos
, sizeReal
);
496 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
498 EnableCloseButton(false);
501 // for some reason we need to manually send ourselves this message as
502 // otherwise the mnemonics are always shown -- even if they're configured
503 // to be hidden until "Alt" is pressed in the control panel
505 // this could indicate a bug somewhere else but for now this is the only
513 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
518 // Native look is full screen window on Smartphones
519 #ifdef __SMARTPHONE__
520 if ( style
& wxMAXIMIZE
)
527 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
529 // after destroying an owned window, Windows activates the next top level
530 // window in Z order but it may be different from our owner (to reproduce
531 // this simply Alt-TAB to another application and back before closing the
532 // owned frame) whereas we always want to yield activation to our parent
533 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
535 wxWindow
*parent
= GetParent();
538 ::BringWindowToTop(GetHwndOf(parent
));
543 // ----------------------------------------------------------------------------
544 // wxTopLevelWindowMSW showing
545 // ----------------------------------------------------------------------------
547 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
549 ::ShowWindow(GetHwnd(), nShowCmd
);
551 m_iconized
= nShowCmd
== SW_MINIMIZE
;
554 bool wxTopLevelWindowMSW::Show(bool show
)
556 // don't use wxWindow version as we want to call DoShowWindow() ourselves
557 if ( !wxWindowBase::Show(show
) )
563 if ( m_maximizeOnShow
)
566 nShowCmd
= SW_MAXIMIZE
;
568 m_maximizeOnShow
= FALSE
;
572 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
573 nShowCmd
= SW_SHOWNA
;
583 DoShowWindow(nShowCmd
);
587 ::BringWindowToTop(GetHwnd());
589 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
590 event
.SetEventObject( this );
591 GetEventHandler()->ProcessEvent(event
);
595 // Try to highlight the correct window (the parent)
598 HWND hWndParent
= GetHwndOf(GetParent());
600 ::BringWindowToTop(hWndParent
);
607 // ----------------------------------------------------------------------------
608 // wxTopLevelWindowMSW maximize/minimize
609 // ----------------------------------------------------------------------------
611 void wxTopLevelWindowMSW::Maximize(bool maximize
)
615 // just maximize it directly
616 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
620 // we can't maximize the hidden frame because it shows it as well, so
621 // just remember that we should do it later in this case
622 m_maximizeOnShow
= maximize
;
626 bool wxTopLevelWindowMSW::IsMaximized() const
631 return ::IsZoomed(GetHwnd()) != 0;
635 void wxTopLevelWindowMSW::Iconize(bool iconize
)
637 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
640 bool wxTopLevelWindowMSW::IsIconized() const
645 // also update the current state
646 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
652 void wxTopLevelWindowMSW::Restore()
654 DoShowWindow(SW_RESTORE
);
657 // ----------------------------------------------------------------------------
658 // wxTopLevelWindowMSW fullscreen
659 // ----------------------------------------------------------------------------
661 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
663 if ( show
== IsFullScreen() )
669 m_fsIsShowing
= show
;
675 // zap the frame borders
677 // save the 'normal' window style
678 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
680 // save the old position, width & height, maximize state
681 m_fsOldSize
= GetRect();
682 m_fsIsMaximized
= IsMaximized();
684 // decide which window style flags to turn off
685 LONG newStyle
= m_fsOldWindowStyle
;
688 if (style
& wxFULLSCREEN_NOBORDER
)
690 offFlags
|= WS_BORDER
;
692 offFlags
|= WS_THICKFRAME
;
695 if (style
& wxFULLSCREEN_NOCAPTION
)
696 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
698 newStyle
&= ~offFlags
;
700 // change our window style to be compatible with full-screen mode
701 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
705 // resize to the size of the display containing us
706 int dpy
= wxDisplay::GetFromWindow(this);
707 if ( dpy
!= wxNOT_FOUND
)
709 rect
= wxDisplay(dpy
).GetGeometry();
711 else // fall back to the main desktop
712 #else // wxUSE_DISPLAY
714 // resize to the size of the desktop
715 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
717 // FIXME: size of the bottom menu (toolbar)
718 // should be taken in account
719 rect
.height
+= rect
.y
;
723 #endif // wxUSE_DISPLAY
727 // now flush the window style cache and actually go full-screen
728 long flags
= SWP_FRAMECHANGED
;
730 // showing the frame full screen should also show it if it's still
734 // don't call wxWindow version to avoid flicker from calling
735 // ::ShowWindow() -- we're going to show the window at the correct
736 // location directly below -- but do call the wxWindowBase version
737 // to sync the internal m_isShown flag
738 wxWindowBase::Show();
740 flags
|= SWP_SHOWWINDOW
;
743 SetWindowPos(GetHwnd(), HWND_TOP
,
744 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
747 #if defined(__WXWINCE__) && _WIN32_WCE < 400
748 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
751 // finally send an event allowing the window to relayout itself &c
752 wxSizeEvent
event(rect
.GetSize(), GetId());
753 GetEventHandler()->ProcessEvent(event
);
755 else // stop showing full screen
757 #if defined(__WXWINCE__) && _WIN32_WCE < 400
758 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
760 Maximize(m_fsIsMaximized
);
761 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
762 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
763 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
769 // ----------------------------------------------------------------------------
770 // wxTopLevelWindowMSW misc
771 // ----------------------------------------------------------------------------
773 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
775 SetIcons( wxIconBundle( icon
) );
778 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
780 wxTopLevelWindowBase::SetIcons(icons
);
782 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
783 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
784 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
786 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
787 (LPARAM
)GetHiconOf(sml
) );
790 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
791 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
793 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
794 (LPARAM
)GetHiconOf(big
) );
799 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
801 #if !defined(__WXMICROWIN__)
802 // get system (a.k.a. window) menu
803 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
806 // no system menu at all -- ok if we want to remove the close button
807 // anyhow, but bad if we want to show it
811 // enabling/disabling the close item from it also automatically
812 // disables/enables the close title bar button
813 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
815 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
817 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
822 // update appearance immediately
823 if ( !::DrawMenuBar(GetHwnd()) )
825 wxLogLastError(_T("DrawMenuBar"));
828 #endif // !__WXMICROWIN__
835 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
837 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
838 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
840 // The empty region signifies that the shape should be removed from the
842 if ( region
.IsEmpty() )
844 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
846 wxLogLastError(_T("SetWindowRgn"));
852 // Windows takes ownership of the region, so
853 // we'll have to make a copy of the region to give to it.
854 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
855 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
856 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
857 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
858 delete[] (char*) rgnData
;
860 // SetWindowRgn expects the region to be in coordinants
861 // relative to the window, not the client area. Figure
862 // out the offset, if any.
864 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
865 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
866 ::GetClientRect(GetHwnd(), &rect
);
867 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
868 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
870 // Now call the shape API with the new region.
871 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
873 wxLogLastError(_T("SetWindowRgn"));
879 #endif // !__WXWINCE__
881 // ----------------------------------------------------------------------------
882 // wxTopLevelWindow event handling
883 // ----------------------------------------------------------------------------
885 // Default activation behaviour - set the focus for the first child
887 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
889 if ( event
.GetActive() )
891 // restore focus to the child which was last focused unless we already
893 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
895 wxWindow
*winFocus
= FindFocus();
896 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
898 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
905 wxSetFocusToChild(parent
, &m_winLastFocused
);
910 // remember the last focused child if it is our child
911 m_winLastFocused
= FindFocus();
913 if ( m_winLastFocused
)
915 // let it know that it doesn't have focus any more
916 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
918 // and don't remember it if it's a child from some other frame
919 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
921 m_winLastFocused
= NULL
;
925 wxLogTrace(_T("focus"),
926 _T("wxTLW %08x deactivated, last focused: %08x."),
928 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
935 // the DialogProc for all wxWidgets dialogs
936 LONG APIENTRY _EXPORT
939 WPARAM
WXUNUSED(wParam
),
940 LPARAM
WXUNUSED(lParam
))
942 if ( message
== WM_INITDIALOG
)
944 // under CE, add a "Ok" button in the dialog title bar and make it full
947 // VZ: we should probably allow for overriding this, e.g. by including
948 // MAXIMIZED flag in the dialog style by default and doing this
949 // only if it is present...
951 // Standard SDK doesn't have aygshell.dll: see
952 // include/wx/msw/wince/libraries.h
953 #if defined(__WXWINCE__) && !defined(WCE_PLATFORM_STANDARDSDK)
955 shidi
.dwMask
= SHIDIM_FLAGS
;
956 shidi
.dwFlags
= SHIDIF_DONEBUTTON
|
957 SHIDIF_SIZEDLGFULLSCREEN
;
959 SHInitDialog( &shidi
);
960 #else // no SHInitDialog()
965 // for almost all messages, returning FALSE means that we didn't process
968 // for WM_INITDIALOG, returning TRUE tells system to set focus to
969 // the first control in the dialog box, but as we set the focus
970 // ourselves, we return FALSE for it as well
974 // ============================================================================
975 // wxTLWHiddenParentModule implementation
976 // ============================================================================
978 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
980 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
982 bool wxTLWHiddenParentModule::OnInit()
990 void wxTLWHiddenParentModule::OnExit()
994 if ( !::DestroyWindow(ms_hwnd
) )
996 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1004 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1006 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1009 ms_className
= NULL
;
1014 HWND
wxTLWHiddenParentModule::GetHWND()
1018 if ( !ms_className
)
1020 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1023 wxZeroMemory(wndclass
);
1025 wndclass
.lpfnWndProc
= DefWindowProc
;
1026 wndclass
.hInstance
= wxGetInstance();
1027 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1029 if ( !::RegisterClass(&wndclass
) )
1031 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1035 ms_className
= HIDDEN_PARENT_CLASS
;
1039 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1040 (HMENU
)NULL
, wxGetInstance(), NULL
);
1043 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));