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"
43 #include "wx/dynlib.h"
45 #include "wx/msw/private.h"
46 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
49 // Standard SDK doesn't have aygshell.dll: see include/wx/msw/wince/libraries.h
50 #if _WIN32_WCE < 400 || !defined(__WINCE_STANDARDSDK__)
53 #include "wx/msw/wince/missing.h"
56 #include "wx/msw/missing.h"
57 #include "wx/msw/winundef.h"
59 #include "wx/display.h"
69 // ----------------------------------------------------------------------------
70 // stubs for missing functions under MicroWindows
71 // ----------------------------------------------------------------------------
75 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return false; }
76 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return false; }
78 #endif // __WXMICROWIN__
80 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
81 // is not included by wxUniv build which does need wxDlgProc
83 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // the name of the default wxWidgets class
91 extern wxChar
*wxCanvasClassName
;
93 extern const wxChar
*wxCanvasClassName
;
96 // ----------------------------------------------------------------------------
97 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
98 // module to ensure that the window is always deleted)
99 // ----------------------------------------------------------------------------
101 class wxTLWHiddenParentModule
: public wxModule
104 // module init/finalize
105 virtual bool OnInit();
106 virtual void OnExit();
108 // get the hidden window (creates on demand)
109 static HWND
GetHWND();
112 // the HWND of the hidden parent
115 // the class used to create it
116 static const wxChar
*ms_className
;
118 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
121 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
123 // ============================================================================
124 // wxTopLevelWindowMSW implementation
125 // ============================================================================
127 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
128 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
131 // ----------------------------------------------------------------------------
132 // wxTopLevelWindowMSW creation
133 // ----------------------------------------------------------------------------
135 void wxTopLevelWindowMSW::Init()
138 m_maximizeOnShow
= false;
140 // Data to save/restore when calling ShowFullScreen
142 m_fsOldWindowStyle
= 0;
143 m_fsIsMaximized
= false;
144 m_fsIsShowing
= false;
146 m_winLastFocused
= (wxWindow
*)NULL
;
148 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
153 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
155 // let the base class deal with the common styles but fix the ones which
156 // don't make sense for us (we also deal with the borders ourselves)
157 WXDWORD msflags
= wxWindow::MSWGetStyle
159 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
160 ) & ~WS_CHILD
& ~WS_VISIBLE
;
162 // For some reason, WS_VISIBLE needs to be defined on creation for
163 // SmartPhone 2003. The title can fail to be displayed otherwise.
164 #if defined(__SMARTPHONE__) || (defined(__WXWINCE__) && _WIN32_WCE < 400)
165 msflags
|= WS_VISIBLE
;
166 ((wxTopLevelWindowMSW
*)this)->wxWindowBase::Show(true);
169 // first select the kind of window being created
171 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
172 // creates a window with both caption and border, hence we need to use
173 // WS_POPUP in a few cases just to avoid having caption/border which we
176 #if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
177 // border and caption styles
178 if ( style
& wxRESIZE_BORDER
)
179 msflags
|= WS_THICKFRAME
;
180 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
181 *exflags
|= WS_EX_DLGMODALFRAME
;
182 else if ( !(style
& wxBORDER_NONE
) )
183 msflags
|= WS_BORDER
;
190 // normally we consider that all windows without a caption must be popups,
191 // but CE is an exception: there windows normally do not have the caption
192 // but shouldn't be made popups as popups can't have menus and don't look
193 // like normal windows anyhow
195 // TODO: Smartphone appears to like wxCAPTION, but we should check that
197 #if defined(__SMARTPHONE__) || !defined(__WXWINCE__)
198 if ( style
& wxCAPTION
)
199 msflags
|= WS_CAPTION
;
203 #endif // !__WXWINCE__
206 // next translate the individual flags
207 if ( style
& wxMINIMIZE_BOX
)
208 msflags
|= WS_MINIMIZEBOX
;
209 if ( style
& wxMAXIMIZE_BOX
)
210 msflags
|= WS_MAXIMIZEBOX
;
213 if ( style
& wxSYSTEM_MENU
)
214 msflags
|= WS_SYSMENU
;
217 // NB: under CE these 2 styles are not supported currently, we should
218 // call Minimize()/Maximize() "manually" if we want to support them
219 if ( style
& wxMINIMIZE
)
220 msflags
|= WS_MINIMIZE
;
222 #if !defined(__POCKETPC__)
223 if ( style
& wxMAXIMIZE
)
224 msflags
|= WS_MAXIMIZE
;
227 // Keep this here because it saves recoding this function in wxTinyFrame
228 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
229 msflags
|= WS_CAPTION
;
233 // there is no taskbar under CE, so omit all this
234 #if !defined(__WXWINCE__)
235 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
237 if ( style
& wxFRAME_TOOL_WINDOW
)
239 // create the palette-like window
240 *exflags
|= WS_EX_TOOLWINDOW
;
242 // tool windows shouldn't appear on the taskbar (as documented)
243 style
|= wxFRAME_NO_TASKBAR
;
246 // We have to solve 2 different problems here:
248 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
249 // taskbar even if they don't have a parent
251 // 2. frames without this style should appear in the taskbar even
252 // if they're owned (Windows only puts non owned windows into
253 // the taskbar normally)
255 // The second one is solved here by using WS_EX_APPWINDOW flag, the
256 // first one is dealt with in our MSWGetParent() method
258 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
260 // need to force the frame to appear in the taskbar
261 *exflags
|= WS_EX_APPWINDOW
;
263 //else: nothing to do [here]
266 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
267 *exflags
|= WS_EX_CONTEXTHELP
;
268 #endif // !__WXWINCE__
270 if ( style
& wxSTAY_ON_TOP
)
271 *exflags
|= WS_EX_TOPMOST
;
277 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
279 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
280 // parent HWND or it would be always on top of its parent which is not what
281 // we usually want (in fact, we only want it for frames with the
282 // wxFRAME_FLOAT_ON_PARENT flag)
283 HWND hwndParent
= NULL
;
284 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
286 const wxWindow
*parent
= GetParent();
290 // this flag doesn't make sense then and will be ignored
291 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
295 hwndParent
= GetHwndOf(parent
);
298 //else: don't float on parent, must not be owned
300 // now deal with the 2nd taskbar-related problem (see comments above in
302 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
305 hwndParent
= wxTLWHiddenParentModule::GetHWND();
308 return (WXHWND
)hwndParent
;
311 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
312 const wxString
& title
,
316 #ifdef __WXMICROWIN__
317 // no dialogs support under MicroWin yet
318 return CreateFrame(title
, pos
, size
);
319 #else // !__WXMICROWIN__
320 wxWindow
*parent
= GetParent();
322 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
323 // app window as parent - this avoids creating modal dialogs without
325 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
327 parent
= wxTheApp
->GetTopWindow();
331 // don't use transient windows as parents, this is dangerous as it
332 // can lead to a crash if the parent is destroyed before the child
334 // also don't use the window which is currently hidden as then the
335 // dialog would be hidden as well
336 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
344 m_hWnd
= (WXHWND
)::CreateDialogIndirect
347 (DLGTEMPLATE
*)dlgTemplate
,
348 parent
? GetHwndOf(parent
) : NULL
,
354 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
356 wxLogSysError(wxT("Can't create dialog using memory template"));
362 (void)MSWGetCreateWindowFlags(&exflags
);
366 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
367 ::SetWindowPos(GetHwnd(),
368 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
372 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
376 #if !defined(__WXWINCE__)
377 // For some reason, the system menu is activated when we use the
378 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
379 if ( exflags
& WS_EX_CONTEXTHELP
)
381 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
384 wxIcon icon
= winTop
->GetIcon();
387 ::SendMessage(GetHwnd(), WM_SETICON
,
389 (LPARAM
)GetHiconOf(icon
));
395 // move the dialog to its initial position without forcing repainting
397 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
399 if ( x
== (int)CW_USEDEFAULT
)
401 // centre it on the screen - what else can we do?
402 wxSize sizeDpy
= wxGetDisplaySize();
404 x
= (sizeDpy
.x
- w
) / 2;
405 y
= (sizeDpy
.y
- h
) / 2;
408 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
409 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
411 wxLogLastError(wxT("MoveWindow"));
415 if ( !title
.empty() )
417 ::SetWindowText(GetHwnd(), title
);
422 #ifdef __SMARTPHONE__
423 // Work around title non-display glitch
428 #endif // __WXMICROWIN__/!__WXMICROWIN__
431 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
436 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
438 #if !defined(__HANDHELDPC__) && ((defined(_WIN32_WCE) && _WIN32_WCE < 400) || \
439 defined(__POCKETPC__) || \
440 defined(__SMARTPHONE__))
441 // Always expand to fit the screen in PocketPC or SmartPhone
442 wxSize
sz(wxDefaultSize
);
444 #else // other (including normal desktop) Windows
448 bool result
= MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
453 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
455 const wxString
& title
,
459 const wxString
& name
)
461 bool ret
wxDUMMY_INITIALIZE(false);
466 wxSize sizeReal
= size
;
467 if ( !sizeReal
.IsFullySpecified() )
469 sizeReal
.SetDefaults(GetDefaultSize());
472 m_windowStyle
= style
;
476 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
478 wxTopLevelWindows
.Append(this);
481 parent
->AddChild(this);
483 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
485 // we have different dialog templates to allows creation of dialogs
486 // with & without captions under MSWindows, resizeable or not (but a
487 // resizeable dialog always has caption - otherwise it would look too
490 // we need 3 additional WORDs for dialog menu, class and title (as we
491 // don't use DS_SETFONT we don't need the fourth WORD for the font)
492 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
493 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
494 memset(dlgTemplate
, 0, dlgsize
);
496 // these values are arbitrary, they won't be used normally anyhow
499 dlgTemplate
->cx
= 144;
500 dlgTemplate
->cy
= 75;
502 // reuse the code in MSWGetStyle() but correct the results slightly for
504 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
506 // all dialogs are popups
507 dlgTemplate
->style
|= WS_POPUP
;
510 // force 3D-look if necessary, it looks impossibly ugly otherwise
511 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
512 dlgTemplate
->style
|= DS_MODALFRAME
;
515 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
520 ret
= CreateFrame(title
, pos
, sizeReal
);
524 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
526 EnableCloseButton(false);
530 // for some reason we need to manually send ourselves this message as
531 // otherwise the mnemonics are always shown -- even if they're configured
532 // to be hidden until "Alt" is pressed in the control panel
534 // this could indicate a bug somewhere else but for now this is the only
542 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
547 // Note: if we include PocketPC in this test, dialogs can fail to show up,
548 // for example the text entry dialog in the dialogs sample. Problem with Maximise()?
549 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__))
550 if ( style
& wxMAXIMIZE
)
556 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
557 SetRightMenu(); // to nothing for initialization
563 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
565 // after destroying an owned window, Windows activates the next top level
566 // window in Z order but it may be different from our owner (to reproduce
567 // this simply Alt-TAB to another application and back before closing the
568 // owned frame) whereas we always want to yield activation to our parent
569 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
571 wxWindow
*parent
= GetParent();
574 ::BringWindowToTop(GetHwndOf(parent
));
579 // ----------------------------------------------------------------------------
580 // wxTopLevelWindowMSW showing
581 // ----------------------------------------------------------------------------
583 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
585 ::ShowWindow(GetHwnd(), nShowCmd
);
587 m_iconized
= nShowCmd
== SW_MINIMIZE
;
590 bool wxTopLevelWindowMSW::Show(bool show
)
592 // don't use wxWindow version as we want to call DoShowWindow() ourselves
593 if ( !wxWindowBase::Show(show
) )
599 if ( m_maximizeOnShow
)
602 nShowCmd
= SW_MAXIMIZE
;
604 // This is necessary, or no window appears
605 #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__)
606 DoShowWindow(SW_SHOW
);
609 m_maximizeOnShow
= false;
613 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
614 nShowCmd
= SW_SHOWNA
;
624 DoShowWindow(nShowCmd
);
626 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
627 // Addornments have to be added when the frame is the correct size
628 wxFrame
* frame
= wxDynamicCast(this, wxFrame
);
629 if (frame
&& frame
->GetMenuBar())
630 frame
->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
635 ::BringWindowToTop(GetHwnd());
637 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_windowId
);
638 event
.SetEventObject( this );
639 GetEventHandler()->ProcessEvent(event
);
643 // Try to highlight the correct window (the parent)
646 HWND hWndParent
= GetHwndOf(GetParent());
648 ::BringWindowToTop(hWndParent
);
655 // ----------------------------------------------------------------------------
656 // wxTopLevelWindowMSW maximize/minimize
657 // ----------------------------------------------------------------------------
659 void wxTopLevelWindowMSW::Maximize(bool maximize
)
663 // just maximize it directly
664 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
668 // we can't maximize the hidden frame because it shows it as well, so
669 // just remember that we should do it later in this case
670 m_maximizeOnShow
= maximize
;
672 // after calling Maximize() the client code expects to get the frame
673 // "real" size and doesn't want to know that, because of implementation
674 // details, the frame isn't really maximized yet but will be only once
675 // it's shown, so return our size as it will be then in this case
677 // we don't know which display we're on yet so use the default one
678 SetSize(wxGetClientDisplayRect().GetSize());
682 bool wxTopLevelWindowMSW::IsMaximized() const
687 return m_maximizeOnShow
|| ::IsZoomed(GetHwnd()) != 0;
691 void wxTopLevelWindowMSW::Iconize(bool iconize
)
693 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
696 bool wxTopLevelWindowMSW::IsIconized() const
701 // also update the current state
702 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
708 void wxTopLevelWindowMSW::Restore()
710 DoShowWindow(SW_RESTORE
);
713 // ----------------------------------------------------------------------------
714 // wxTopLevelWindowMSW fullscreen
715 // ----------------------------------------------------------------------------
717 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
719 if ( show
== IsFullScreen() )
725 m_fsIsShowing
= show
;
731 // zap the frame borders
733 // save the 'normal' window style
734 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
736 // save the old position, width & height, maximize state
737 m_fsOldSize
= GetRect();
738 m_fsIsMaximized
= IsMaximized();
740 // decide which window style flags to turn off
741 LONG newStyle
= m_fsOldWindowStyle
;
744 if (style
& wxFULLSCREEN_NOBORDER
)
746 offFlags
|= WS_BORDER
;
748 offFlags
|= WS_THICKFRAME
;
751 if (style
& wxFULLSCREEN_NOCAPTION
)
752 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
754 newStyle
&= ~offFlags
;
756 // change our window style to be compatible with full-screen mode
757 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
761 // resize to the size of the display containing us
762 int dpy
= wxDisplay::GetFromWindow(this);
763 if ( dpy
!= wxNOT_FOUND
)
765 rect
= wxDisplay(dpy
).GetGeometry();
767 else // fall back to the main desktop
768 #endif // wxUSE_DISPLAY
770 // resize to the size of the desktop
771 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
773 // FIXME: size of the bottom menu (toolbar)
774 // should be taken in account
775 rect
.height
+= rect
.y
;
782 // now flush the window style cache and actually go full-screen
783 long flags
= SWP_FRAMECHANGED
;
785 // showing the frame full screen should also show it if it's still
789 // don't call wxWindow version to avoid flicker from calling
790 // ::ShowWindow() -- we're going to show the window at the correct
791 // location directly below -- but do call the wxWindowBase version
792 // to sync the internal m_isShown flag
793 wxWindowBase::Show();
795 flags
|= SWP_SHOWWINDOW
;
798 SetWindowPos(GetHwnd(), HWND_TOP
,
799 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
802 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
803 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
806 // finally send an event allowing the window to relayout itself &c
807 wxSizeEvent
event(rect
.GetSize(), GetId());
808 GetEventHandler()->ProcessEvent(event
);
810 else // stop showing full screen
812 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
813 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
815 Maximize(m_fsIsMaximized
);
816 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
817 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
818 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
824 // ----------------------------------------------------------------------------
825 // wxTopLevelWindowMSW misc
826 // ----------------------------------------------------------------------------
828 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
830 SetIcons( wxIconBundle( icon
) );
833 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
835 wxTopLevelWindowBase::SetIcons(icons
);
837 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
838 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
839 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
841 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
842 (LPARAM
)GetHiconOf(sml
) );
845 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
846 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
848 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
849 (LPARAM
)GetHiconOf(big
) );
854 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
856 #if !defined(__WXMICROWIN__)
857 // get system (a.k.a. window) menu
858 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
861 // no system menu at all -- ok if we want to remove the close button
862 // anyhow, but bad if we want to show it
866 // enabling/disabling the close item from it also automatically
867 // disables/enables the close title bar button
868 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
870 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
872 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
877 // update appearance immediately
878 if ( !::DrawMenuBar(GetHwnd()) )
880 wxLogLastError(_T("DrawMenuBar"));
883 #endif // !__WXMICROWIN__
890 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
892 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
893 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
895 // The empty region signifies that the shape should be removed from the
897 if ( region
.IsEmpty() )
899 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
901 wxLogLastError(_T("SetWindowRgn"));
907 // Windows takes ownership of the region, so
908 // we'll have to make a copy of the region to give to it.
909 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
910 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
911 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
912 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
913 delete[] (char*) rgnData
;
915 // SetWindowRgn expects the region to be in coordinants
916 // relative to the window, not the client area. Figure
917 // out the offset, if any.
919 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
920 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
921 ::GetClientRect(GetHwnd(), &rect
);
922 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
923 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
925 // Now call the shape API with the new region.
926 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
928 wxLogLastError(_T("SetWindowRgn"));
934 #endif // !__WXWINCE__
936 void wxTopLevelWindowMSW::RequestUserAttention(int flags
)
938 // check if we can use FlashWindowEx(): unfortunately a simple test for
939 // FLASHW_STOP doesn't work because MSVC6 headers do #define it but don't
940 // provide FlashWindowEx() declaration, so try to detect whether we have
941 // real headers for WINVER 0x0500 by checking for existence of a symbol not
942 // declated in MSVC6 header
943 #if defined(FLASHW_STOP) && defined(VK_XBUTTON1)
944 // available in the headers, check if it is supported by the system
945 typedef BOOL (WINAPI
*FlashWindowEx_t
)(FLASHWINFO
*pfwi
);
946 FlashWindowEx_t s_pfnFlashWindowEx
= NULL
;
947 if ( !s_pfnFlashWindowEx
)
949 wxDynamicLibrary
dllUser32(_T("user32.dll"));
950 s_pfnFlashWindowEx
= (FlashWindowEx_t
)
951 dllUser32
.GetSymbol(_T("FlashWindowEx"));
953 // we can safely unload user32.dll here, it's going to remain loaded as
954 // long as the program is running anyhow
957 if ( s_pfnFlashWindowEx
)
959 WinStruct
<FLASHWINFO
> fwi
;
960 fwi
.hwnd
= GetHwnd();
961 fwi
.dwFlags
= FLASHW_ALL
;
962 if ( flags
& wxUSER_ATTENTION_INFO
)
964 // just flash a few times
967 else // wxUSER_ATTENTION_ERROR
969 // flash until the user notices it
970 fwi
.dwFlags
|= FLASHW_TIMERNOFG
;
973 s_pfnFlashWindowEx(&fwi
);
975 else // FlashWindowEx() not available
976 #endif // FlashWindowEx() defined
980 ::FlashWindow(GetHwnd(), TRUE
);
981 #endif // __WXWINCE__
985 // ----------------------------------------------------------------------------
986 // wxTopLevelWindow event handling
987 // ----------------------------------------------------------------------------
989 // Default activation behaviour - set the focus for the first child
991 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
993 if ( event
.GetActive() )
995 // restore focus to the child which was last focused unless we already
997 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
999 wxWindow
*winFocus
= FindFocus();
1000 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
1002 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
1009 wxSetFocusToChild(parent
, &m_winLastFocused
);
1012 else // deactivating
1014 // remember the last focused child if it is our child
1015 m_winLastFocused
= FindFocus();
1017 if ( m_winLastFocused
)
1019 // let it know that it doesn't have focus any more
1020 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
1022 // and don't remember it if it's a child from some other frame
1023 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
1025 m_winLastFocused
= NULL
;
1029 wxLogTrace(_T("focus"),
1030 _T("wxTLW %08x deactivated, last focused: %08x."),
1032 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
1039 // the DialogProc for all wxWidgets dialogs
1040 LONG APIENTRY _EXPORT
1041 wxDlgProc(HWND hDlg
,
1043 WPARAM
WXUNUSED(wParam
),
1044 LPARAM
WXUNUSED(lParam
))
1046 if ( message
== WM_INITDIALOG
)
1048 // under CE, add a "Ok" button in the dialog title bar and make it full
1051 // TODO: find the window for this HWND, and take into account
1052 // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present.
1054 // Standard SDK doesn't have aygshell.dll: see
1055 // include/wx/msw/wince/libraries.h
1056 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1057 SHINITDLGINFO shidi
;
1058 shidi
.dwMask
= SHIDIM_FLAGS
;
1059 shidi
.dwFlags
= SHIDIF_SIZEDLG
// take account of the SIP or menubar
1060 #ifndef __SMARTPHONE__
1065 SHInitDialog( &shidi
);
1066 #else // no SHInitDialog()
1071 // for almost all messages, returning FALSE means that we didn't process
1074 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1075 // the first control in the dialog box, but as we set the focus
1076 // ourselves, we return FALSE for it as well
1080 // ============================================================================
1081 // wxTLWHiddenParentModule implementation
1082 // ============================================================================
1084 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
1086 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
1088 bool wxTLWHiddenParentModule::OnInit()
1091 ms_className
= NULL
;
1096 void wxTLWHiddenParentModule::OnExit()
1100 if ( !::DestroyWindow(ms_hwnd
) )
1102 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1110 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1112 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1115 ms_className
= NULL
;
1120 HWND
wxTLWHiddenParentModule::GetHWND()
1124 if ( !ms_className
)
1126 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1129 wxZeroMemory(wndclass
);
1131 wndclass
.lpfnWndProc
= DefWindowProc
;
1132 wndclass
.hInstance
= wxGetInstance();
1133 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1135 if ( !::RegisterClass(&wndclass
) )
1137 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1141 ms_className
= HIDDEN_PARENT_CLASS
;
1145 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1146 (HMENU
)NULL
, wxGetInstance(), NULL
);
1149 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));