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
;
188 // normally we consider that all windows without a caption must be popups,
189 // but CE is an exception: there windows normally do not have the caption
190 // but shouldn't be made popups as popups can't have menus and don't look
191 // like normal windows anyhow
193 // TODO: Smartphone appears to like wxCAPTION, but we should check that
195 #if defined(__SMARTPHONE__) || !defined(__WXWINCE__)
196 if ( style
& wxCAPTION
)
197 msflags
|= WS_CAPTION
;
201 #endif // !__WXWINCE__
204 // next translate the individual flags
205 if ( style
& wxMINIMIZE_BOX
)
206 msflags
|= WS_MINIMIZEBOX
;
207 if ( style
& wxMAXIMIZE_BOX
)
208 msflags
|= WS_MAXIMIZEBOX
;
211 if ( style
& wxSYSTEM_MENU
)
212 msflags
|= WS_SYSMENU
;
215 // NB: under CE these 2 styles are not supported currently, we should
216 // call Minimize()/Maximize() "manually" if we want to support them
217 if ( style
& wxMINIMIZE
)
218 msflags
|= WS_MINIMIZE
;
220 #if !defined(__POCKETPC__)
221 if ( style
& wxMAXIMIZE
)
222 msflags
|= WS_MAXIMIZE
;
225 // Keep this here because it saves recoding this function in wxTinyFrame
226 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
227 msflags
|= WS_CAPTION
;
231 // there is no taskbar under CE, so omit all this
232 #if !defined(__WXWINCE__)
233 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
235 if ( style
& wxFRAME_TOOL_WINDOW
)
237 // create the palette-like window
238 *exflags
|= WS_EX_TOOLWINDOW
;
240 // tool windows shouldn't appear on the taskbar (as documented)
241 style
|= wxFRAME_NO_TASKBAR
;
244 // We have to solve 2 different problems here:
246 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
247 // taskbar even if they don't have a parent
249 // 2. frames without this style should appear in the taskbar even
250 // if they're owned (Windows only puts non owned windows into
251 // the taskbar normally)
253 // The second one is solved here by using WS_EX_APPWINDOW flag, the
254 // first one is dealt with in our MSWGetParent() method
256 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
258 // need to force the frame to appear in the taskbar
259 *exflags
|= WS_EX_APPWINDOW
;
261 //else: nothing to do [here]
264 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
265 *exflags
|= WS_EX_CONTEXTHELP
;
266 #endif // !__WXWINCE__
268 if ( style
& wxSTAY_ON_TOP
)
269 *exflags
|= WS_EX_TOPMOST
;
275 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
277 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
278 // parent HWND or it would be always on top of its parent which is not what
279 // we usually want (in fact, we only want it for frames with the
280 // wxFRAME_FLOAT_ON_PARENT flag)
281 HWND hwndParent
= NULL
;
282 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
284 const wxWindow
*parent
= GetParent();
288 // this flag doesn't make sense then and will be ignored
289 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
293 hwndParent
= GetHwndOf(parent
);
296 //else: don't float on parent, must not be owned
298 // now deal with the 2nd taskbar-related problem (see comments above in
300 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
303 hwndParent
= wxTLWHiddenParentModule::GetHWND();
306 return (WXHWND
)hwndParent
;
309 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
310 const wxString
& title
,
314 #ifdef __WXMICROWIN__
315 // no dialogs support under MicroWin yet
316 return CreateFrame(title
, pos
, size
);
317 #else // !__WXMICROWIN__
318 wxWindow
*parent
= GetParent();
320 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
321 // app window as parent - this avoids creating modal dialogs without
323 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
325 parent
= wxTheApp
->GetTopWindow();
329 // don't use transient windows as parents, this is dangerous as it
330 // can lead to a crash if the parent is destroyed before the child
332 // also don't use the window which is currently hidden as then the
333 // dialog would be hidden as well
334 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
342 m_hWnd
= (WXHWND
)::CreateDialogIndirect
345 (DLGTEMPLATE
*)dlgTemplate
,
346 parent
? GetHwndOf(parent
) : NULL
,
352 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
354 wxLogSysError(wxT("Can't create dialog using memory template"));
360 (void)MSWGetCreateWindowFlags(&exflags
);
364 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
365 ::SetWindowPos(GetHwnd(),
366 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
370 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
374 #if !defined(__WXWINCE__)
375 // For some reason, the system menu is activated when we use the
376 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
377 if ( exflags
& WS_EX_CONTEXTHELP
)
379 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
382 wxIcon icon
= winTop
->GetIcon();
385 ::SendMessage(GetHwnd(), WM_SETICON
,
387 (LPARAM
)GetHiconOf(icon
));
393 // move the dialog to its initial position without forcing repainting
395 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
397 if ( x
== (int)CW_USEDEFAULT
)
399 // centre it on the screen - what else can we do?
400 wxSize sizeDpy
= wxGetDisplaySize();
402 x
= (sizeDpy
.x
- w
) / 2;
403 y
= (sizeDpy
.y
- h
) / 2;
406 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
407 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
409 wxLogLastError(wxT("MoveWindow"));
413 if ( !title
.empty() )
415 ::SetWindowText(GetHwnd(), title
);
420 #ifdef __SMARTPHONE__
421 // Work around title non-display glitch
426 #endif // __WXMICROWIN__/!__WXMICROWIN__
429 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
434 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
436 #if !defined(__HANDHELDPC__) && ((defined(_WIN32_WCE) && _WIN32_WCE < 400) || \
437 defined(__POCKETPC__) || \
438 defined(__SMARTPHONE__))
439 // Always expand to fit the screen in PocketPC or SmartPhone
440 wxSize
sz(wxDefaultSize
);
442 #else // other (including normal desktop) Windows
446 bool result
= MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
448 #ifdef __SMARTPHONE__
449 // Work around title non-display glitch
455 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
457 const wxString
& title
,
461 const wxString
& name
)
463 bool ret
wxDUMMY_INITIALIZE(false);
468 wxSize sizeReal
= size
;
469 if ( !sizeReal
.IsFullySpecified() )
471 sizeReal
.SetDefaults(GetDefaultSize());
474 m_windowStyle
= style
;
478 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
480 wxTopLevelWindows
.Append(this);
483 parent
->AddChild(this);
485 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
487 // we have different dialog templates to allows creation of dialogs
488 // with & without captions under MSWindows, resizeable or not (but a
489 // resizeable dialog always has caption - otherwise it would look too
492 // we need 3 additional WORDs for dialog menu, class and title (as we
493 // don't use DS_SETFONT we don't need the fourth WORD for the font)
494 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
495 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
496 memset(dlgTemplate
, 0, dlgsize
);
498 // these values are arbitrary, they won't be used normally anyhow
501 dlgTemplate
->cx
= 144;
502 dlgTemplate
->cy
= 75;
504 // reuse the code in MSWGetStyle() but correct the results slightly for
506 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
508 // all dialogs are popups
509 dlgTemplate
->style
|= WS_POPUP
;
511 // force 3D-look if necessary, it looks impossibly ugly otherwise
512 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
513 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 // Native look is full screen window on Smartphones and Standard SDK.
548 // TODO: check that we need this (if we're passing default values to ctor).
549 // Also check that there really is a difference between PocketPC and Smartphone in this regard.
550 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__))
551 if ( style
& wxMAXIMIZE
)
557 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
558 SetRightMenu(); // to nothing for initialization
564 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
566 // after destroying an owned window, Windows activates the next top level
567 // window in Z order but it may be different from our owner (to reproduce
568 // this simply Alt-TAB to another application and back before closing the
569 // owned frame) whereas we always want to yield activation to our parent
570 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
572 wxWindow
*parent
= GetParent();
575 ::BringWindowToTop(GetHwndOf(parent
));
580 // ----------------------------------------------------------------------------
581 // wxTopLevelWindowMSW showing
582 // ----------------------------------------------------------------------------
584 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
586 ::ShowWindow(GetHwnd(), nShowCmd
);
588 m_iconized
= nShowCmd
== SW_MINIMIZE
;
591 bool wxTopLevelWindowMSW::Show(bool show
)
593 // don't use wxWindow version as we want to call DoShowWindow() ourselves
594 if ( !wxWindowBase::Show(show
) )
600 if ( m_maximizeOnShow
)
603 nShowCmd
= SW_MAXIMIZE
;
605 // This is necessary, or no window appears
606 #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__)
607 DoShowWindow(SW_SHOW
);
610 m_maximizeOnShow
= false;
614 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
615 nShowCmd
= SW_SHOWNA
;
625 DoShowWindow(nShowCmd
);
627 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
628 // Addornments have to be added when the frame is the correct size
629 wxFrame
* frame
= wxDynamicCast(this, wxFrame
);
630 if (frame
&& frame
->GetMenuBar())
631 frame
->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
636 ::BringWindowToTop(GetHwnd());
638 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_windowId
);
639 event
.SetEventObject( this );
640 GetEventHandler()->ProcessEvent(event
);
644 // Try to highlight the correct window (the parent)
647 HWND hWndParent
= GetHwndOf(GetParent());
649 ::BringWindowToTop(hWndParent
);
656 // ----------------------------------------------------------------------------
657 // wxTopLevelWindowMSW maximize/minimize
658 // ----------------------------------------------------------------------------
660 void wxTopLevelWindowMSW::Maximize(bool maximize
)
664 // just maximize it directly
665 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
669 // we can't maximize the hidden frame because it shows it as well, so
670 // just remember that we should do it later in this case
671 m_maximizeOnShow
= maximize
;
675 bool wxTopLevelWindowMSW::IsMaximized() const
680 return ::IsZoomed(GetHwnd()) != 0;
684 void wxTopLevelWindowMSW::Iconize(bool iconize
)
686 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
689 bool wxTopLevelWindowMSW::IsIconized() const
694 // also update the current state
695 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
701 void wxTopLevelWindowMSW::Restore()
703 DoShowWindow(SW_RESTORE
);
706 // ----------------------------------------------------------------------------
707 // wxTopLevelWindowMSW fullscreen
708 // ----------------------------------------------------------------------------
710 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
712 if ( show
== IsFullScreen() )
718 m_fsIsShowing
= show
;
724 // zap the frame borders
726 // save the 'normal' window style
727 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
729 // save the old position, width & height, maximize state
730 m_fsOldSize
= GetRect();
731 m_fsIsMaximized
= IsMaximized();
733 // decide which window style flags to turn off
734 LONG newStyle
= m_fsOldWindowStyle
;
737 if (style
& wxFULLSCREEN_NOBORDER
)
739 offFlags
|= WS_BORDER
;
741 offFlags
|= WS_THICKFRAME
;
744 if (style
& wxFULLSCREEN_NOCAPTION
)
745 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
747 newStyle
&= ~offFlags
;
749 // change our window style to be compatible with full-screen mode
750 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
754 // resize to the size of the display containing us
755 int dpy
= wxDisplay::GetFromWindow(this);
756 if ( dpy
!= wxNOT_FOUND
)
758 rect
= wxDisplay(dpy
).GetGeometry();
760 else // fall back to the main desktop
761 #else // wxUSE_DISPLAY
763 // resize to the size of the desktop
764 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
766 // FIXME: size of the bottom menu (toolbar)
767 // should be taken in account
768 rect
.height
+= rect
.y
;
772 #endif // wxUSE_DISPLAY
776 // now flush the window style cache and actually go full-screen
777 long flags
= SWP_FRAMECHANGED
;
779 // showing the frame full screen should also show it if it's still
783 // don't call wxWindow version to avoid flicker from calling
784 // ::ShowWindow() -- we're going to show the window at the correct
785 // location directly below -- but do call the wxWindowBase version
786 // to sync the internal m_isShown flag
787 wxWindowBase::Show();
789 flags
|= SWP_SHOWWINDOW
;
792 SetWindowPos(GetHwnd(), HWND_TOP
,
793 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
796 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
797 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
800 // finally send an event allowing the window to relayout itself &c
801 wxSizeEvent
event(rect
.GetSize(), GetId());
802 GetEventHandler()->ProcessEvent(event
);
804 else // stop showing full screen
806 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
807 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
809 Maximize(m_fsIsMaximized
);
810 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
811 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
812 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
818 // ----------------------------------------------------------------------------
819 // wxTopLevelWindowMSW misc
820 // ----------------------------------------------------------------------------
822 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
824 SetIcons( wxIconBundle( icon
) );
827 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
829 wxTopLevelWindowBase::SetIcons(icons
);
831 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
832 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
833 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
835 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
836 (LPARAM
)GetHiconOf(sml
) );
839 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
840 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
842 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
843 (LPARAM
)GetHiconOf(big
) );
848 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
850 #if !defined(__WXMICROWIN__)
851 // get system (a.k.a. window) menu
852 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
855 // no system menu at all -- ok if we want to remove the close button
856 // anyhow, but bad if we want to show it
860 // enabling/disabling the close item from it also automatically
861 // disables/enables the close title bar button
862 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
864 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
866 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
871 // update appearance immediately
872 if ( !::DrawMenuBar(GetHwnd()) )
874 wxLogLastError(_T("DrawMenuBar"));
877 #endif // !__WXMICROWIN__
884 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
886 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
887 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
889 // The empty region signifies that the shape should be removed from the
891 if ( region
.IsEmpty() )
893 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
895 wxLogLastError(_T("SetWindowRgn"));
901 // Windows takes ownership of the region, so
902 // we'll have to make a copy of the region to give to it.
903 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
904 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
905 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
906 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
907 delete[] (char*) rgnData
;
909 // SetWindowRgn expects the region to be in coordinants
910 // relative to the window, not the client area. Figure
911 // out the offset, if any.
913 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
914 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
915 ::GetClientRect(GetHwnd(), &rect
);
916 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
917 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
919 // Now call the shape API with the new region.
920 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
922 wxLogLastError(_T("SetWindowRgn"));
928 #endif // !__WXWINCE__
930 void wxTopLevelWindowMSW::RequestUserAttention(int flags
)
932 // check if we can use FlashWindowEx(): unfortunately an explicit test for
933 // FLASHW_STOP, for example, doesn't work because MSVC6 headers do #define
934 // it but don't provide FlashWindowEx() declaration
935 #if (WINVER >= 0x0500 && (defined FLASHW_STOP))
936 // available in the headers, check if it is supported by the system
937 typedef BOOL (WINAPI
*FlashWindowEx_t
)(FLASHWINFO
*pfwi
);
938 FlashWindowEx_t s_pfnFlashWindowEx
= NULL
;
939 if ( !s_pfnFlashWindowEx
)
941 wxDynamicLibrary
dllUser32(_T("user32.dll"));
942 s_pfnFlashWindowEx
= (FlashWindowEx_t
)
943 dllUser32
.GetSymbol(_T("FlashWindowEx"));
945 // we can safely unload user32.dll here, it's goign to remain loaded as
946 // long as the program is running anyhow
949 if ( s_pfnFlashWindowEx
)
951 WinStruct
<FLASHWINFO
> fwi
;
952 fwi
.hwnd
= GetHwnd();
953 fwi
.dwFlags
= FLASHW_ALL
;
954 if ( flags
& wxUSER_ATTENTION_INFO
)
956 // just flash a few times
959 else // wxUSER_ATTENTION_ERROR
961 // flash until the user notices it
962 fwi
.dwFlags
|= FLASHW_TIMERNOFG
;
965 s_pfnFlashWindowEx(&fwi
);
967 else // FlashWindowEx() not available
968 #endif // FlashWindowEx() defined
972 ::FlashWindow(GetHwnd(), TRUE
);
973 #endif // __WXWINCE__
977 // ----------------------------------------------------------------------------
978 // wxTopLevelWindow event handling
979 // ----------------------------------------------------------------------------
981 // Default activation behaviour - set the focus for the first child
983 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
985 if ( event
.GetActive() )
987 // restore focus to the child which was last focused unless we already
989 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
991 wxWindow
*winFocus
= FindFocus();
992 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
994 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
1001 wxSetFocusToChild(parent
, &m_winLastFocused
);
1004 else // deactivating
1006 // remember the last focused child if it is our child
1007 m_winLastFocused
= FindFocus();
1009 if ( m_winLastFocused
)
1011 // let it know that it doesn't have focus any more
1012 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
1014 // and don't remember it if it's a child from some other frame
1015 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
1017 m_winLastFocused
= NULL
;
1021 wxLogTrace(_T("focus"),
1022 _T("wxTLW %08x deactivated, last focused: %08x."),
1024 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
1031 // the DialogProc for all wxWidgets dialogs
1032 LONG APIENTRY _EXPORT
1033 wxDlgProc(HWND hDlg
,
1035 WPARAM
WXUNUSED(wParam
),
1036 LPARAM
WXUNUSED(lParam
))
1038 if ( message
== WM_INITDIALOG
)
1040 // under CE, add a "Ok" button in the dialog title bar and make it full
1043 // TODO: find the window for this HWND, and take into account
1044 // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present.
1046 // Standard SDK doesn't have aygshell.dll: see
1047 // include/wx/msw/wince/libraries.h
1048 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1049 SHINITDLGINFO shidi
;
1050 shidi
.dwMask
= SHIDIM_FLAGS
;
1051 shidi
.dwFlags
= SHIDIF_SIZEDLG
// take account of the SIP or menubar
1052 #ifndef __SMARTPHONE__
1057 SHInitDialog( &shidi
);
1058 #else // no SHInitDialog()
1063 // for almost all messages, returning FALSE means that we didn't process
1066 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1067 // the first control in the dialog box, but as we set the focus
1068 // ourselves, we return FALSE for it as well
1072 // ============================================================================
1073 // wxTLWHiddenParentModule implementation
1074 // ============================================================================
1076 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
1078 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
1080 bool wxTLWHiddenParentModule::OnInit()
1083 ms_className
= NULL
;
1088 void wxTLWHiddenParentModule::OnExit()
1092 if ( !::DestroyWindow(ms_hwnd
) )
1094 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1102 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1104 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1107 ms_className
= NULL
;
1112 HWND
wxTLWHiddenParentModule::GetHWND()
1116 if ( !ms_className
)
1118 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1121 wxZeroMemory(wndclass
);
1123 wndclass
.lpfnWndProc
= DefWindowProc
;
1124 wndclass
.hInstance
= wxGetInstance();
1125 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1127 if ( !::RegisterClass(&wndclass
) )
1129 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1133 ms_className
= HIDDEN_PARENT_CLASS
;
1137 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1138 (HMENU
)NULL
, wxGetInstance(), NULL
);
1141 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));