1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
31 #include "wx/dialog.h"
32 #include "wx/string.h"
36 #include "wx/containr.h" // wxSetFocusToChild()
37 #include "wx/module.h"
40 #include "wx/dynlib.h"
42 #include "wx/msw/private.h"
43 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
46 // Standard SDK doesn't have aygshell.dll: see include/wx/msw/wince/libraries.h
47 #if _WIN32_WCE < 400 || !defined(__WINCE_STANDARDSDK__)
52 #include "wx/msw/winundef.h"
53 #include "wx/msw/missing.h"
55 #include "wx/display.h"
65 // ----------------------------------------------------------------------------
66 // stubs for missing functions under MicroWindows
67 // ----------------------------------------------------------------------------
71 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return false; }
72 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return false; }
74 #endif // __WXMICROWIN__
76 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
77 // is not included by wxUniv build which does need wxDlgProc
79 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // the name of the default wxWidgets class
87 extern wxChar
*wxCanvasClassName
;
89 extern const wxChar
*wxCanvasClassName
;
92 // ----------------------------------------------------------------------------
93 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
94 // module to ensure that the window is always deleted)
95 // ----------------------------------------------------------------------------
97 class wxTLWHiddenParentModule
: public wxModule
100 // module init/finalize
101 virtual bool OnInit();
102 virtual void OnExit();
104 // get the hidden window (creates on demand)
105 static HWND
GetHWND();
108 // the HWND of the hidden parent
111 // the class used to create it
112 static const wxChar
*ms_className
;
114 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
117 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
119 // ============================================================================
120 // wxTopLevelWindowMSW implementation
121 // ============================================================================
123 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
124 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
127 // ----------------------------------------------------------------------------
128 // wxTopLevelWindowMSW creation
129 // ----------------------------------------------------------------------------
131 void wxTopLevelWindowMSW::Init()
134 m_maximizeOnShow
= false;
136 // Data to save/restore when calling ShowFullScreen
138 m_fsOldWindowStyle
= 0;
139 m_fsIsMaximized
= false;
140 m_fsIsShowing
= false;
142 m_winLastFocused
= (wxWindow
*)NULL
;
144 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
148 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
149 SHACTIVATEINFO
* info
= new SHACTIVATEINFO
;
151 info
->cbSize
= sizeof(SHACTIVATEINFO
);
153 m_activateInfo
= (void*) info
;
157 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
159 // let the base class deal with the common styles but fix the ones which
160 // don't make sense for us (we also deal with the borders ourselves)
161 WXDWORD msflags
= wxWindow::MSWGetStyle
163 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
164 ) & ~WS_CHILD
& ~WS_VISIBLE
;
166 // For some reason, WS_VISIBLE needs to be defined on creation for
167 // SmartPhone 2003. The title can fail to be displayed otherwise.
168 #if defined(__SMARTPHONE__) || (defined(__WXWINCE__) && _WIN32_WCE < 400)
169 msflags
|= WS_VISIBLE
;
170 ((wxTopLevelWindowMSW
*)this)->wxWindowBase::Show(true);
173 // first select the kind of window being created
175 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
176 // creates a window with both caption and border, hence we need to use
177 // WS_POPUP in a few cases just to avoid having caption/border which we
180 // border and caption styles
181 if ( ( style
& wxRESIZE_BORDER
) && !IsAlwaysMaximized())
182 msflags
|= WS_THICKFRAME
;
183 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
184 *exflags
|= WS_EX_DLGMODALFRAME
;
185 else if ( !(style
& wxBORDER_NONE
) )
186 msflags
|= WS_BORDER
;
192 // normally we consider that all windows without a caption must be popups,
193 // but CE is an exception: there windows normally do not have the caption
194 // but shouldn't be made popups as popups can't have menus and don't look
195 // like normal windows anyhow
197 // TODO: Smartphone appears to like wxCAPTION, but we should check that
199 #if defined(__SMARTPHONE__) || !defined(__WXWINCE__)
200 if ( style
& wxCAPTION
)
201 msflags
|= WS_CAPTION
;
205 #endif // !__WXWINCE__
208 // next translate the individual flags
210 // WS_EX_CONTEXTHELP is incompatible with WS_MINIMIZEBOX and WS_MAXIMIZEBOX
211 // and is ignored if we specify both of them, but chances are that if we
212 // use wxWS_EX_CONTEXTHELP, we really do want to have the context help
213 // button while wxMINIMIZE/wxMAXIMIZE are included by default, so the help
215 if ( !(GetExtraStyle() & wxWS_EX_CONTEXTHELP
) )
217 if ( style
& wxMINIMIZE_BOX
)
218 msflags
|= WS_MINIMIZEBOX
;
219 if ( style
& wxMAXIMIZE_BOX
)
220 msflags
|= WS_MAXIMIZEBOX
;
224 // notice that if wxCLOSE_BOX is specified we need to use WS_SYSMENU too as
225 // otherwise the close box doesn't appear
226 if ( style
& (wxSYSTEM_MENU
| wxCLOSE_BOX
) )
227 msflags
|= WS_SYSMENU
;
228 #endif // !__WXWINCE__
230 // NB: under CE these 2 styles are not supported currently, we should
231 // call Minimize()/Maximize() "manually" if we want to support them
232 if ( style
& wxMINIMIZE
)
233 msflags
|= WS_MINIMIZE
;
235 if ( style
& wxMAXIMIZE
)
236 msflags
|= WS_MAXIMIZE
;
238 // Keep this here because it saves recoding this function in wxTinyFrame
239 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
240 msflags
|= WS_CAPTION
;
244 // there is no taskbar under CE, so omit all this
245 #if !defined(__WXWINCE__)
246 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
248 if ( style
& wxFRAME_TOOL_WINDOW
)
250 // create the palette-like window
251 *exflags
|= WS_EX_TOOLWINDOW
;
253 // tool windows shouldn't appear on the taskbar (as documented)
254 style
|= wxFRAME_NO_TASKBAR
;
257 // We have to solve 2 different problems here:
259 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
260 // taskbar even if they don't have a parent
262 // 2. frames without this style should appear in the taskbar even
263 // if they're owned (Windows only puts non owned windows into
264 // the taskbar normally)
266 // The second one is solved here by using WS_EX_APPWINDOW flag, the
267 // first one is dealt with in our MSWGetParent() method
269 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
271 // need to force the frame to appear in the taskbar
272 *exflags
|= WS_EX_APPWINDOW
;
274 //else: nothing to do [here]
277 if ( GetExtraStyle() & wxWS_EX_CONTEXTHELP
)
278 *exflags
|= WS_EX_CONTEXTHELP
;
279 #endif // !__WXWINCE__
281 if ( style
& wxSTAY_ON_TOP
)
282 *exflags
|= WS_EX_TOPMOST
;
288 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
290 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
291 // parent HWND or it would be always on top of its parent which is not what
292 // we usually want (in fact, we only want it for frames with the
293 // wxFRAME_FLOAT_ON_PARENT flag)
294 HWND hwndParent
= NULL
;
295 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
297 const wxWindow
*parent
= GetParent();
301 // this flag doesn't make sense then and will be ignored
302 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
306 hwndParent
= GetHwndOf(parent
);
309 //else: don't float on parent, must not be owned
311 // now deal with the 2nd taskbar-related problem (see comments above in
313 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
316 hwndParent
= wxTLWHiddenParentModule::GetHWND();
319 return (WXHWND
)hwndParent
;
322 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
323 bool wxTopLevelWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
325 SHACTIVATEINFO
*info
= (SHACTIVATEINFO
*) m_activateInfo
;
328 SHHandleWMSettingChange(GetHwnd(), wParam
, lParam
, info
);
331 return wxWindowMSW::HandleSettingChange(wParam
, lParam
);
335 WXLRESULT
wxTopLevelWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
338 bool processed
= false;
340 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
345 SHACTIVATEINFO
* info
= (SHACTIVATEINFO
*) m_activateInfo
;
349 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) flags
= SHA_INPUTDIALOG
;
350 SHHandleWMActivate(GetHwnd(), wParam
, lParam
, info
, flags
);
353 // This implicitly sends a wxEVT_ACTIVATE_APP event
355 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
363 wxActivateEvent
event(wxEVT_HIBERNATE
, true, wxID_ANY
);
364 event
.SetEventObject(wxTheApp
);
365 processed
= wxTheApp
->ProcessEvent(event
);
373 rc
= wxTopLevelWindowBase::MSWWindowProc(message
, wParam
, lParam
);
378 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
379 const wxString
& title
,
383 #ifdef __WXMICROWIN__
384 // no dialogs support under MicroWin yet
385 return CreateFrame(title
, pos
, size
);
386 #else // !__WXMICROWIN__
387 wxWindow
*parent
= GetParent();
389 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
390 // app window as parent - this avoids creating modal dialogs without
392 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
394 parent
= wxTheApp
->GetTopWindow();
398 // don't use transient windows as parents, this is dangerous as it
399 // can lead to a crash if the parent is destroyed before the child
401 // also don't use the window which is currently hidden as then the
402 // dialog would be hidden as well
403 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
411 m_hWnd
= (WXHWND
)::CreateDialogIndirect
414 (DLGTEMPLATE
*)dlgTemplate
,
415 parent
? GetHwndOf(parent
) : NULL
,
421 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
423 wxLogSysError(wxT("Can't create dialog using memory template"));
428 #if !defined(__WXWINCE__)
429 // For some reason, the system menu is activated when we use the
430 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
431 if ( HasExtraStyle(wxWS_EX_CONTEXTHELP
) )
433 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
436 wxIcon icon
= winTop
->GetIcon();
439 ::SendMessage(GetHwnd(), WM_SETICON
,
441 (LPARAM
)GetHiconOf(icon
));
445 #endif // !__WXWINCE__
447 // move the dialog to its initial position without forcing repainting
449 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
451 if ( x
== (int)CW_USEDEFAULT
)
453 // centre it on the screen - what else can we do?
454 wxSize sizeDpy
= wxGetDisplaySize();
456 x
= (sizeDpy
.x
- w
) / 2;
457 y
= (sizeDpy
.y
- h
) / 2;
460 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
461 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
463 wxLogLastError(wxT("MoveWindow"));
467 if ( !title
.empty() )
469 ::SetWindowText(GetHwnd(), title
.wx_str());
474 #ifdef __SMARTPHONE__
475 // Work around title non-display glitch
480 #endif // __WXMICROWIN__/!__WXMICROWIN__
483 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
488 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
490 const wxSize sz
= IsAlwaysMaximized() ? wxDefaultSize
: size
;
493 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
494 exflags
|= WS_EX_LAYOUTRTL
;
497 return MSWCreate(wxCanvasClassName
, title
.wx_str(), pos
, sz
, flags
, exflags
);
500 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
502 const wxString
& title
,
506 const wxString
& name
)
508 bool ret
wxDUMMY_INITIALIZE(false);
510 wxSize sizeReal
= size
;
511 if ( !sizeReal
.IsFullySpecified() )
513 sizeReal
.SetDefaults(GetDefaultSize());
516 m_windowStyle
= style
;
520 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
522 wxTopLevelWindows
.Append(this);
525 parent
->AddChild(this);
527 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
529 // we have different dialog templates to allows creation of dialogs
530 // with & without captions under MSWindows, resizeable or not (but a
531 // resizeable dialog always has caption - otherwise it would look too
534 // we need 3 additional WORDs for dialog menu, class and title (as we
535 // don't use DS_SETFONT we don't need the fourth WORD for the font)
536 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
537 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
538 memset(dlgTemplate
, 0, dlgsize
);
540 // these values are arbitrary, they won't be used normally anyhow
543 dlgTemplate
->cx
= 144;
544 dlgTemplate
->cy
= 75;
546 // reuse the code in MSWGetStyle() but correct the results slightly for
548 dlgTemplate
->style
= MSWGetStyle(style
, &dlgTemplate
->dwExtendedStyle
);
550 // all dialogs are popups
551 dlgTemplate
->style
|= WS_POPUP
;
554 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
556 dlgTemplate
->dwExtendedStyle
|= WS_EX_LAYOUTRTL
;
559 // force 3D-look if necessary, it looks impossibly ugly otherwise
560 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
561 dlgTemplate
->style
|= DS_MODALFRAME
;
564 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
569 ret
= CreateFrame(title
, pos
, sizeReal
);
573 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
575 EnableCloseButton(false);
579 // for standard dialogs the dialog manager generates WM_CHANGEUISTATE
580 // itself but for custom windows we have to do it ourselves in order to
581 // make the keyboard indicators (such as underlines for accelerators and
582 // focus rectangles) work under Win2k+
585 MSWUpdateUIState(UIS_INITIALIZE
);
588 // Note: if we include PocketPC in this test, dialogs can fail to show up,
589 // for example the text entry dialog in the dialogs sample. Problem with Maximise()?
590 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__))
591 if ( ( style
& wxMAXIMIZE
) || IsAlwaysMaximized() )
597 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
598 SetRightMenu(); // to nothing for initialization
604 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
606 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
607 SHACTIVATEINFO
* info
= (SHACTIVATEINFO
*) m_activateInfo
;
609 m_activateInfo
= NULL
;
612 // after destroying an owned window, Windows activates the next top level
613 // window in Z order but it may be different from our owner (to reproduce
614 // this simply Alt-TAB to another application and back before closing the
615 // owned frame) whereas we always want to yield activation to our parent
616 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
618 wxWindow
*parent
= GetParent();
621 ::BringWindowToTop(GetHwndOf(parent
));
626 // ----------------------------------------------------------------------------
627 // wxTopLevelWindowMSW showing
628 // ----------------------------------------------------------------------------
630 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
632 ::ShowWindow(GetHwnd(), nShowCmd
);
634 m_iconized
= nShowCmd
== SW_MINIMIZE
;
637 bool wxTopLevelWindowMSW::Show(bool show
)
639 // don't use wxWindow version as we want to call DoShowWindow() ourselves
640 if ( !wxWindowBase::Show(show
) )
646 if ( m_maximizeOnShow
)
649 nShowCmd
= SW_MAXIMIZE
;
651 // This is necessary, or no window appears
652 #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__)
653 DoShowWindow(SW_SHOW
);
656 m_maximizeOnShow
= false;
660 // we shouldn't use SW_SHOW which also activates the window for
661 // tool frames (as they shouldn't steal focus from the main window)
662 // nor for the currently disabled windows as they would be enabled
664 if ( HasFlag(wxFRAME_TOOL_WINDOW
) || !IsEnabled() )
665 nShowCmd
= SW_SHOWNA
;
675 DoShowWindow(nShowCmd
);
677 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
678 // Addornments have to be added when the frame is the correct size
679 wxFrame
* frame
= wxDynamicCast(this, wxFrame
);
680 if (frame
&& frame
->GetMenuBar())
681 frame
->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
684 // we only set pending size if we're maximized before being shown, now that
685 // we're shown we don't need it any more (it is reset in size event handler
686 // for child windows but we have to do it ourselves for this parent window)
687 m_pendingSize
= wxDefaultSize
;
692 // ----------------------------------------------------------------------------
693 // wxTopLevelWindowMSW maximize/minimize
694 // ----------------------------------------------------------------------------
696 void wxTopLevelWindowMSW::Maximize(bool maximize
)
700 // just maximize it directly
701 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
705 // we can't maximize the hidden frame because it shows it as well,
706 // so just remember that we should do it later in this case
707 m_maximizeOnShow
= maximize
;
709 // after calling Maximize() the client code expects to get the frame
710 // "real" size and doesn't want to know that, because of implementation
711 // details, the frame isn't really maximized yet but will be only once
712 // it's shown, so return our size as it will be then in this case
715 // we must only change pending size here, and not call SetSize()
716 // because otherwise Windows would think that this (full screen)
717 // size is the natural size for the frame and so would use it when
718 // the user clicks on "restore" title bar button instead of the
719 // correct initial frame size
721 // NB: unfortunately we don't know which display we're on yet so we
722 // have to use the default one
723 m_pendingSize
= wxGetClientDisplayRect().GetSize();
725 //else: can't do anything in this case, we don't have the old size
729 bool wxTopLevelWindowMSW::IsMaximized() const
731 return IsAlwaysMaximized() ||
732 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) && !defined(__WINCE_STANDARDSDK__)
734 (::IsZoomed(GetHwnd()) != 0) ||
739 void wxTopLevelWindowMSW::Iconize(bool iconize
)
741 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
744 bool wxTopLevelWindowMSW::IsIconized() const
749 // don't use m_iconized, it may be briefly out of sync with the real state
750 // as it's only modified when we receive a WM_SIZE and we could be called
751 // from an event handler from one of the messages we receive before it,
753 return ::IsIconic(GetHwnd()) != 0;
757 void wxTopLevelWindowMSW::Restore()
759 DoShowWindow(SW_RESTORE
);
762 void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
764 if ( dir
== wxLayout_Default
)
765 dir
= wxTheApp
->GetLayoutDirection();
767 if ( dir
!= wxLayout_Default
)
768 wxTopLevelWindowBase::SetLayoutDirection(dir
);
771 // ----------------------------------------------------------------------------
772 // wxTopLevelWindowMSW geometry
773 // ----------------------------------------------------------------------------
777 void wxTopLevelWindowMSW::DoGetPosition(int *x
, int *y
) const
782 wp
.length
= sizeof(WINDOWPLACEMENT
);
783 if ( ::GetWindowPlacement(GetHwnd(), &wp
) )
785 RECT
& rc
= wp
.rcNormalPosition
;
787 // the position returned by GetWindowPlacement() is in workspace
788 // coordinates except for windows with WS_EX_TOOLWINDOW style
789 if ( !HasFlag(wxFRAME_TOOL_WINDOW
) )
791 // we must use the correct display for the translation as the
792 // task bar might be shown on one display but not the other one
793 int n
= wxDisplay::GetFromWindow(this);
794 wxDisplay
dpy(n
== wxNOT_FOUND
? 0 : n
);
795 const wxPoint ptOfs
= dpy
.GetClientArea().GetPosition() -
796 dpy
.GetGeometry().GetPosition();
810 wxLogLastError(_T("GetWindowPlacement"));
814 wxTopLevelWindowBase::DoGetPosition(x
, y
);
817 void wxTopLevelWindowMSW::DoGetSize(int *width
, int *height
) const
822 wp
.length
= sizeof(WINDOWPLACEMENT
);
823 if ( ::GetWindowPlacement(GetHwnd(), &wp
) )
825 const RECT
& rc
= wp
.rcNormalPosition
;
828 *width
= rc
.right
- rc
.left
;
830 *height
= rc
.bottom
- rc
.top
;
835 wxLogLastError(_T("GetWindowPlacement"));
839 wxTopLevelWindowBase::DoGetSize(width
, height
);
842 #endif // __WXWINCE__
844 // ----------------------------------------------------------------------------
845 // wxTopLevelWindowMSW fullscreen
846 // ----------------------------------------------------------------------------
848 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
850 if ( show
== IsFullScreen() )
856 m_fsIsShowing
= show
;
862 // zap the frame borders
864 // save the 'normal' window style
865 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
867 // save the old position, width & height, maximize state
868 m_fsOldSize
= GetRect();
869 m_fsIsMaximized
= IsMaximized();
871 // decide which window style flags to turn off
872 LONG newStyle
= m_fsOldWindowStyle
;
875 if (style
& wxFULLSCREEN_NOBORDER
)
877 offFlags
|= WS_BORDER
;
879 offFlags
|= WS_THICKFRAME
;
882 if (style
& wxFULLSCREEN_NOCAPTION
)
883 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
885 newStyle
&= ~offFlags
;
887 // change our window style to be compatible with full-screen mode
888 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
892 // resize to the size of the display containing us
893 int dpy
= wxDisplay::GetFromWindow(this);
894 if ( dpy
!= wxNOT_FOUND
)
896 rect
= wxDisplay(dpy
).GetGeometry();
898 else // fall back to the main desktop
899 #endif // wxUSE_DISPLAY
901 // resize to the size of the desktop
902 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
904 // FIXME: size of the bottom menu (toolbar)
905 // should be taken in account
906 rect
.height
+= rect
.y
;
913 // now flush the window style cache and actually go full-screen
914 long flags
= SWP_FRAMECHANGED
;
916 // showing the frame full screen should also show it if it's still
920 // don't call wxWindow version to avoid flicker from calling
921 // ::ShowWindow() -- we're going to show the window at the correct
922 // location directly below -- but do call the wxWindowBase version
923 // to sync the internal m_isShown flag
924 wxWindowBase::Show();
926 flags
|= SWP_SHOWWINDOW
;
929 SetWindowPos(GetHwnd(), HWND_TOP
,
930 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
933 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
934 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
937 // finally send an event allowing the window to relayout itself &c
938 wxSizeEvent
event(rect
.GetSize(), GetId());
939 HandleWindowEvent(event
);
941 else // stop showing full screen
943 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
944 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
946 Maximize(m_fsIsMaximized
);
947 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
948 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
949 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
955 // ----------------------------------------------------------------------------
956 // wxTopLevelWindowMSW misc
957 // ----------------------------------------------------------------------------
959 void wxTopLevelWindowMSW::SetTitle( const wxString
& title
)
964 wxString
wxTopLevelWindowMSW::GetTitle() const
969 void wxTopLevelWindowMSW::DoSelectAndSetIcon(const wxIconBundle
& icons
,
974 const wxSize
size(::GetSystemMetrics(smX
), ::GetSystemMetrics(smY
));
976 const wxIcon icon
= icons
.GetIconOfExactSize(size
);
979 ::SendMessage(GetHwnd(), WM_SETICON
, i
, (LPARAM
)GetHiconOf(icon
));
983 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
985 wxTopLevelWindowBase::SetIcons(icons
);
987 DoSelectAndSetIcon(icons
, SM_CXSMICON
, SM_CYSMICON
, ICON_SMALL
);
988 DoSelectAndSetIcon(icons
, SM_CXICON
, SM_CYICON
, ICON_BIG
);
991 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
993 #if !defined(__WXMICROWIN__)
994 // get system (a.k.a. window) menu
995 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
998 // no system menu at all -- ok if we want to remove the close button
999 // anyhow, but bad if we want to show it
1003 // enabling/disabling the close item from it also automatically
1004 // disables/enables the close title bar button
1005 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
1007 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
1009 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
1014 // update appearance immediately
1015 if ( !::DrawMenuBar(GetHwnd()) )
1017 wxLogLastError(_T("DrawMenuBar"));
1020 #endif // !__WXMICROWIN__
1027 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
1029 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1030 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1032 // The empty region signifies that the shape should be removed from the
1034 if ( region
.IsEmpty() )
1036 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
1038 wxLogLastError(_T("SetWindowRgn"));
1044 // Windows takes ownership of the region, so
1045 // we'll have to make a copy of the region to give to it.
1046 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
1047 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
1048 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
1049 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
1050 delete[] (char*) rgnData
;
1052 // SetWindowRgn expects the region to be in coordinants
1053 // relative to the window, not the client area. Figure
1054 // out the offset, if any.
1056 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1057 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1058 ::GetClientRect(GetHwnd(), &rect
);
1059 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
1060 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
1062 // Now call the shape API with the new region.
1063 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
1065 wxLogLastError(_T("SetWindowRgn"));
1071 #endif // !__WXWINCE__
1073 void wxTopLevelWindowMSW::RequestUserAttention(int flags
)
1075 // check if we can use FlashWindowEx(): unfortunately a simple test for
1076 // FLASHW_STOP doesn't work because MSVC6 headers do #define it but don't
1077 // provide FlashWindowEx() declaration, so try to detect whether we have
1078 // real headers for WINVER 0x0500 by checking for existence of a symbol not
1079 // declated in MSVC6 header
1080 #if defined(FLASHW_STOP) && defined(VK_XBUTTON1) && wxUSE_DYNLIB_CLASS
1081 // available in the headers, check if it is supported by the system
1082 typedef BOOL (WINAPI
*FlashWindowEx_t
)(FLASHWINFO
*pfwi
);
1083 FlashWindowEx_t s_pfnFlashWindowEx
= NULL
;
1084 if ( !s_pfnFlashWindowEx
)
1086 wxDynamicLibrary
dllUser32(_T("user32.dll"));
1087 s_pfnFlashWindowEx
= (FlashWindowEx_t
)
1088 dllUser32
.GetSymbol(_T("FlashWindowEx"));
1090 // we can safely unload user32.dll here, it's going to remain loaded as
1091 // long as the program is running anyhow
1094 if ( s_pfnFlashWindowEx
)
1096 WinStruct
<FLASHWINFO
> fwi
;
1097 fwi
.hwnd
= GetHwnd();
1098 fwi
.dwFlags
= FLASHW_ALL
;
1099 if ( flags
& wxUSER_ATTENTION_INFO
)
1101 // just flash a few times
1104 else // wxUSER_ATTENTION_ERROR
1106 // flash until the user notices it
1107 fwi
.dwFlags
|= FLASHW_TIMERNOFG
;
1110 s_pfnFlashWindowEx(&fwi
);
1112 else // FlashWindowEx() not available
1113 #endif // FlashWindowEx() defined
1117 ::FlashWindow(GetHwnd(), TRUE
);
1118 #endif // __WXWINCE__
1122 // ---------------------------------------------------------------------------
1124 bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha
)
1126 #if wxUSE_DYNLIB_CLASS
1127 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
1128 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
1130 if ( pSetLayeredWindowAttributes
== NULL
)
1132 wxDynamicLibrary
dllUser32(_T("user32.dll"));
1133 pSetLayeredWindowAttributes
= (PSETLAYEREDWINDOWATTR
)
1134 dllUser32
.GetSymbol(wxT("SetLayeredWindowAttributes"));
1136 if ( pSetLayeredWindowAttributes
== NULL
)
1138 #endif // wxUSE_DYNLIB_CLASS
1140 LONG exstyle
= GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1142 // if setting alpha to fully opaque then turn off the layered style
1145 SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyle
& ~WS_EX_LAYERED
);
1150 #if wxUSE_DYNLIB_CLASS
1151 // Otherwise, set the layered style if needed and set the alpha value
1152 if ((exstyle
& WS_EX_LAYERED
) == 0 )
1153 SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyle
| WS_EX_LAYERED
);
1155 if ( pSetLayeredWindowAttributes(GetHwnd(), 0, (BYTE
)alpha
, LWA_ALPHA
) )
1157 #endif // wxUSE_DYNLIB_CLASS
1162 bool wxTopLevelWindowMSW::CanSetTransparent()
1164 // The API is available on win2k and above
1166 static int os_type
= -1;
1167 static int ver_major
= -1;
1170 os_type
= ::wxGetOsVersion(&ver_major
);
1172 return (os_type
== wxOS_WINDOWS_NT
&& ver_major
>= 5);
1176 void wxTopLevelWindowMSW::DoFreeze()
1178 // do nothing: freezing toplevel window causes paint and mouse events
1179 // to go through it any TLWs under it, so the best we can do is to freeze
1180 // all children -- and wxWindowBase::Freeze() does that
1183 void wxTopLevelWindowMSW::DoThaw()
1185 // intentionally empty -- see DoFreeze()
1189 // ----------------------------------------------------------------------------
1190 // wxTopLevelWindow event handling
1191 // ----------------------------------------------------------------------------
1193 // Default activation behaviour - set the focus for the first child
1195 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
1197 if ( event
.GetActive() )
1199 // restore focus to the child which was last focused unless we already
1201 wxLogTrace(_T("focus"), _T("wxTLW %p activated."), m_hWnd
);
1203 wxWindow
*winFocus
= FindFocus();
1204 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
1206 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
1213 wxSetFocusToChild(parent
, &m_winLastFocused
);
1216 else // deactivating
1218 // remember the last focused child if it is our child
1219 m_winLastFocused
= FindFocus();
1221 if ( m_winLastFocused
)
1223 // let it know that it doesn't have focus any more
1224 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
1226 // and don't remember it if it's a child from some other frame
1227 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
1229 m_winLastFocused
= NULL
;
1233 wxLogTrace(_T("focus"),
1234 _T("wxTLW %p deactivated, last focused: %p."),
1236 m_winLastFocused
? GetHwndOf(m_winLastFocused
) : NULL
);
1242 // the DialogProc for all wxWidgets dialogs
1243 LONG APIENTRY _EXPORT
1244 wxDlgProc(HWND hDlg
,
1246 WPARAM
WXUNUSED(wParam
),
1247 LPARAM
WXUNUSED(lParam
))
1253 // under CE, add a "Ok" button in the dialog title bar and make it full
1256 // TODO: find the window for this HWND, and take into account
1257 // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present.
1259 // Standard SDK doesn't have aygshell.dll: see
1260 // include/wx/msw/wince/libraries.h
1261 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1262 SHINITDLGINFO shidi
;
1263 shidi
.dwMask
= SHIDIM_FLAGS
;
1264 shidi
.dwFlags
= SHIDIF_SIZEDLG
// take account of the SIP or menubar
1265 #ifndef __SMARTPHONE__
1270 SHInitDialog( &shidi
);
1271 #else // no SHInitDialog()
1274 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1275 // the first control in the dialog box, but as we set the focus
1276 // ourselves, we return FALSE for it as well
1281 // for almost all messages, returning FALSE means that we didn't process
1286 // ============================================================================
1287 // wxTLWHiddenParentModule implementation
1288 // ============================================================================
1290 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
1292 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
1294 bool wxTLWHiddenParentModule::OnInit()
1297 ms_className
= NULL
;
1302 void wxTLWHiddenParentModule::OnExit()
1306 if ( !::DestroyWindow(ms_hwnd
) )
1308 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1316 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1318 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1321 ms_className
= NULL
;
1326 HWND
wxTLWHiddenParentModule::GetHWND()
1330 if ( !ms_className
)
1332 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1335 wxZeroMemory(wndclass
);
1337 wndclass
.lpfnWndProc
= DefWindowProc
;
1338 wndclass
.hInstance
= wxGetInstance();
1339 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1341 if ( !::RegisterClass(&wndclass
) )
1343 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1347 ms_className
= HIDDEN_PARENT_CLASS
;
1351 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1352 (HMENU
)NULL
, wxGetInstance(), NULL
);
1355 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));