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 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
192 if ( style
& wxCAPTION
)
193 msflags
|= WS_CAPTION
;
197 #endif // !__WXWINCE__
199 // next translate the individual flags
200 if ( style
& wxMINIMIZE_BOX
)
201 msflags
|= WS_MINIMIZEBOX
;
202 if ( style
& wxMAXIMIZE_BOX
)
203 msflags
|= WS_MAXIMIZEBOX
;
204 if ( style
& wxSYSTEM_MENU
)
205 msflags
|= WS_SYSMENU
;
207 // NB: under CE these 2 styles are not supported currently, we should
208 // call Minimize()/Maximize() "manually" if we want to support them
209 if ( style
& wxMINIMIZE
)
210 msflags
|= WS_MINIMIZE
;
211 if ( style
& wxMAXIMIZE
)
212 msflags
|= WS_MAXIMIZE
;
214 // Keep this here because it saves recoding this function in wxTinyFrame
215 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
216 msflags
|= WS_CAPTION
;
220 // there is no taskbar under CE, so omit all this
221 #if !defined(__WXWINCE__)
222 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
224 if ( style
& wxFRAME_TOOL_WINDOW
)
226 // create the palette-like window
227 *exflags
|= WS_EX_TOOLWINDOW
;
229 // tool windows shouldn't appear on the taskbar (as documented)
230 style
|= wxFRAME_NO_TASKBAR
;
233 // We have to solve 2 different problems here:
235 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
236 // taskbar even if they don't have a parent
238 // 2. frames without this style should appear in the taskbar even
239 // if they're owned (Windows only puts non owned windows into
240 // the taskbar normally)
242 // The second one is solved here by using WS_EX_APPWINDOW flag, the
243 // first one is dealt with in our MSWGetParent() method
245 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
247 // need to force the frame to appear in the taskbar
248 *exflags
|= WS_EX_APPWINDOW
;
250 //else: nothing to do [here]
252 #endif // !__WXWINCE__
254 if ( style
& wxSTAY_ON_TOP
)
255 *exflags
|= WS_EX_TOPMOST
;
257 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
258 *exflags
|= WS_EX_CONTEXTHELP
;
264 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
266 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
267 // parent HWND or it would be always on top of its parent which is not what
268 // we usually want (in fact, we only want it for frames with the
269 // wxFRAME_FLOAT_ON_PARENT flag)
270 HWND hwndParent
= NULL
;
271 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
273 const wxWindow
*parent
= GetParent();
277 // this flag doesn't make sense then and will be ignored
278 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
282 hwndParent
= GetHwndOf(parent
);
285 //else: don't float on parent, must not be owned
287 // now deal with the 2nd taskbar-related problem (see comments above in
289 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
292 hwndParent
= wxTLWHiddenParentModule::GetHWND();
295 return (WXHWND
)hwndParent
;
298 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
299 const wxString
& title
,
303 #ifdef __WXMICROWIN__
304 // no dialogs support under MicroWin yet
305 return CreateFrame(title
, pos
, size
);
306 #else // !__WXMICROWIN__
307 wxWindow
*parent
= GetParent();
309 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
310 // app window as parent - this avoids creating modal dialogs without
312 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
314 parent
= wxTheApp
->GetTopWindow();
318 // don't use transient windows as parents, this is dangerous as it
319 // can lead to a crash if the parent is destroyed before the child
321 // also don't use the window which is currently hidden as then the
322 // dialog would be hidden as well
323 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
331 m_hWnd
= (WXHWND
)::CreateDialogIndirect
334 (DLGTEMPLATE
*)dlgTemplate
,
335 parent
? GetHwndOf(parent
) : NULL
,
341 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
343 wxLogSysError(wxT("Can't create dialog using memory template"));
349 (void)MSWGetCreateWindowFlags(&exflags
);
353 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
354 ::SetWindowPos(GetHwnd(),
355 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
359 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
363 #if defined(__WIN95__)
364 // For some reason, the system menu is activated when we use the
365 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
366 if ( exflags
& WS_EX_CONTEXTHELP
)
368 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
371 wxIcon icon
= winTop
->GetIcon();
374 ::SendMessage(GetHwnd(), WM_SETICON
,
376 (LPARAM
)GetHiconOf(icon
));
382 // move the dialog to its initial position without forcing repainting
384 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
386 if ( x
== (int)CW_USEDEFAULT
)
388 // centre it on the screen - what else can we do?
389 wxSize sizeDpy
= wxGetDisplaySize();
391 x
= (sizeDpy
.x
- w
) / 2;
392 y
= (sizeDpy
.y
- h
) / 2;
395 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
396 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
398 wxLogLastError(wxT("MoveWindow"));
402 if ( !title
.empty() )
404 ::SetWindowText(GetHwnd(), title
);
409 #ifdef __SMARTPHONE__
410 // Work around title non-display glitch
415 #endif // __WXMICROWIN__/!__WXMICROWIN__
418 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
423 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
425 #if !defined(__HANDHELDPC__) && ((defined(_WIN32_WCE) && _WIN32_WCE < 400) || \
426 defined(__POCKETPC__) || \
427 defined(__SMARTPHONE__))
428 // Always expand to fit the screen in PocketPC or SmartPhone
429 wxSize
sz(wxDefaultSize
);
431 #else // other (including normal desktop) Windows
435 bool result
= MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
437 #ifdef __SMARTPHONE__
438 // Work around title non-display glitch
444 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
446 const wxString
& title
,
450 const wxString
& name
)
452 bool ret
wxDUMMY_INITIALIZE(false);
457 wxSize sizeReal
= size
;
458 if ( !sizeReal
.IsFullySpecified() )
460 sizeReal
.SetDefaults(GetDefaultSize());
463 m_windowStyle
= style
;
467 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
469 wxTopLevelWindows
.Append(this);
472 parent
->AddChild(this);
474 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
476 // we have different dialog templates to allows creation of dialogs
477 // with & without captions under MSWindows, resizeable or not (but a
478 // resizeable dialog always has caption - otherwise it would look too
481 // we need 3 additional WORDs for dialog menu, class and title (as we
482 // don't use DS_SETFONT we don't need the fourth WORD for the font)
483 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
484 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
485 memset(dlgTemplate
, 0, dlgsize
);
487 // these values are arbitrary, they won't be used normally anyhow
490 dlgTemplate
->cx
= 144;
491 dlgTemplate
->cy
= 75;
493 // reuse the code in MSWGetStyle() but correct the results slightly for
495 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
497 // all dialogs are popups
498 dlgTemplate
->style
|= WS_POPUP
;
500 // force 3D-look if necessary, it looks impossibly ugly otherwise
501 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
502 dlgTemplate
->style
|= DS_MODALFRAME
;
504 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
509 ret
= CreateFrame(title
, pos
, sizeReal
);
512 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
514 EnableCloseButton(false);
517 // for some reason we need to manually send ourselves this message as
518 // otherwise the mnemonics are always shown -- even if they're configured
519 // to be hidden until "Alt" is pressed in the control panel
521 // this could indicate a bug somewhere else but for now this is the only
529 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
534 // Native look is full screen window on Smartphones and Standard SDK
535 #if defined(__WXWINCE__)
536 if ( style
& wxMAXIMIZE
)
542 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
543 SetRightMenu(); // to nothing for initialization
549 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
551 // after destroying an owned window, Windows activates the next top level
552 // window in Z order but it may be different from our owner (to reproduce
553 // this simply Alt-TAB to another application and back before closing the
554 // owned frame) whereas we always want to yield activation to our parent
555 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
557 wxWindow
*parent
= GetParent();
560 ::BringWindowToTop(GetHwndOf(parent
));
565 // ----------------------------------------------------------------------------
566 // wxTopLevelWindowMSW showing
567 // ----------------------------------------------------------------------------
569 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
571 ::ShowWindow(GetHwnd(), nShowCmd
);
573 m_iconized
= nShowCmd
== SW_MINIMIZE
;
576 bool wxTopLevelWindowMSW::Show(bool show
)
578 // don't use wxWindow version as we want to call DoShowWindow() ourselves
579 if ( !wxWindowBase::Show(show
) )
585 if ( m_maximizeOnShow
)
588 nShowCmd
= SW_MAXIMIZE
;
590 // This is necessary, or no window appears
591 #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__)
592 DoShowWindow(SW_SHOW
);
595 m_maximizeOnShow
= false;
599 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
600 nShowCmd
= SW_SHOWNA
;
610 DoShowWindow(nShowCmd
);
612 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
613 // Addornments have to be added when the frame is the correct size
614 wxFrame
* frame
= wxDynamicCast(this, wxFrame
);
615 if (frame
&& frame
->GetMenuBar())
616 frame
->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
621 ::BringWindowToTop(GetHwnd());
623 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_windowId
);
624 event
.SetEventObject( this );
625 GetEventHandler()->ProcessEvent(event
);
629 // Try to highlight the correct window (the parent)
632 HWND hWndParent
= GetHwndOf(GetParent());
634 ::BringWindowToTop(hWndParent
);
641 // ----------------------------------------------------------------------------
642 // wxTopLevelWindowMSW maximize/minimize
643 // ----------------------------------------------------------------------------
645 void wxTopLevelWindowMSW::Maximize(bool maximize
)
649 // just maximize it directly
650 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
654 // we can't maximize the hidden frame because it shows it as well, so
655 // just remember that we should do it later in this case
656 m_maximizeOnShow
= maximize
;
660 bool wxTopLevelWindowMSW::IsMaximized() const
665 return ::IsZoomed(GetHwnd()) != 0;
669 void wxTopLevelWindowMSW::Iconize(bool iconize
)
671 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
674 bool wxTopLevelWindowMSW::IsIconized() const
679 // also update the current state
680 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
686 void wxTopLevelWindowMSW::Restore()
688 DoShowWindow(SW_RESTORE
);
691 // ----------------------------------------------------------------------------
692 // wxTopLevelWindowMSW fullscreen
693 // ----------------------------------------------------------------------------
695 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
697 if ( show
== IsFullScreen() )
703 m_fsIsShowing
= show
;
709 // zap the frame borders
711 // save the 'normal' window style
712 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
714 // save the old position, width & height, maximize state
715 m_fsOldSize
= GetRect();
716 m_fsIsMaximized
= IsMaximized();
718 // decide which window style flags to turn off
719 LONG newStyle
= m_fsOldWindowStyle
;
722 if (style
& wxFULLSCREEN_NOBORDER
)
724 offFlags
|= WS_BORDER
;
726 offFlags
|= WS_THICKFRAME
;
729 if (style
& wxFULLSCREEN_NOCAPTION
)
730 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
732 newStyle
&= ~offFlags
;
734 // change our window style to be compatible with full-screen mode
735 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
739 // resize to the size of the display containing us
740 int dpy
= wxDisplay::GetFromWindow(this);
741 if ( dpy
!= wxNOT_FOUND
)
743 rect
= wxDisplay(dpy
).GetGeometry();
745 else // fall back to the main desktop
746 #else // wxUSE_DISPLAY
748 // resize to the size of the desktop
749 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
751 // FIXME: size of the bottom menu (toolbar)
752 // should be taken in account
753 rect
.height
+= rect
.y
;
757 #endif // wxUSE_DISPLAY
761 // now flush the window style cache and actually go full-screen
762 long flags
= SWP_FRAMECHANGED
;
764 // showing the frame full screen should also show it if it's still
768 // don't call wxWindow version to avoid flicker from calling
769 // ::ShowWindow() -- we're going to show the window at the correct
770 // location directly below -- but do call the wxWindowBase version
771 // to sync the internal m_isShown flag
772 wxWindowBase::Show();
774 flags
|= SWP_SHOWWINDOW
;
777 SetWindowPos(GetHwnd(), HWND_TOP
,
778 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
781 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
782 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
785 // finally send an event allowing the window to relayout itself &c
786 wxSizeEvent
event(rect
.GetSize(), GetId());
787 GetEventHandler()->ProcessEvent(event
);
789 else // stop showing full screen
791 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
792 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
794 Maximize(m_fsIsMaximized
);
795 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
796 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
797 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
803 // ----------------------------------------------------------------------------
804 // wxTopLevelWindowMSW misc
805 // ----------------------------------------------------------------------------
807 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
809 SetIcons( wxIconBundle( icon
) );
812 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
814 wxTopLevelWindowBase::SetIcons(icons
);
816 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
817 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
818 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
820 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
821 (LPARAM
)GetHiconOf(sml
) );
824 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
825 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
827 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
828 (LPARAM
)GetHiconOf(big
) );
833 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
835 #if !defined(__WXMICROWIN__)
836 // get system (a.k.a. window) menu
837 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
840 // no system menu at all -- ok if we want to remove the close button
841 // anyhow, but bad if we want to show it
845 // enabling/disabling the close item from it also automatically
846 // disables/enables the close title bar button
847 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
849 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
851 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
856 // update appearance immediately
857 if ( !::DrawMenuBar(GetHwnd()) )
859 wxLogLastError(_T("DrawMenuBar"));
862 #endif // !__WXMICROWIN__
869 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
871 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
872 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
874 // The empty region signifies that the shape should be removed from the
876 if ( region
.IsEmpty() )
878 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
880 wxLogLastError(_T("SetWindowRgn"));
886 // Windows takes ownership of the region, so
887 // we'll have to make a copy of the region to give to it.
888 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
889 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
890 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
891 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
892 delete[] (char*) rgnData
;
894 // SetWindowRgn expects the region to be in coordinants
895 // relative to the window, not the client area. Figure
896 // out the offset, if any.
898 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
899 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
900 ::GetClientRect(GetHwnd(), &rect
);
901 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
902 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
904 // Now call the shape API with the new region.
905 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
907 wxLogLastError(_T("SetWindowRgn"));
913 #endif // !__WXWINCE__
915 void wxTopLevelWindowMSW::RequestUserAttention(int flags
)
917 // check if we can use FlashWindowEx(): unfortunately an explicit test for
918 // FLASHW_STOP, for example, doesn't work because MSVC6 headers do #define
919 // it but don't provide FlashWindowEx() declaration
920 #if (WINVER >= 0x0500 && (defined FLASHW_STOP))
921 // available in the headers, check if it is supported by the system
922 typedef BOOL (WINAPI
*FlashWindowEx_t
)(FLASHWINFO
*pfwi
);
923 FlashWindowEx_t s_pfnFlashWindowEx
= NULL
;
924 if ( !s_pfnFlashWindowEx
)
926 wxDynamicLibrary
dllUser32(_T("user32.dll"));
927 s_pfnFlashWindowEx
= (FlashWindowEx_t
)
928 dllUser32
.GetSymbol(_T("FlashWindowEx"));
930 // we can safely unload user32.dll here, it's goign to remain loaded as
931 // long as the program is running anyhow
934 if ( s_pfnFlashWindowEx
)
936 WinStruct
<FLASHWINFO
> fwi
;
937 fwi
.hwnd
= GetHwnd();
938 fwi
.dwFlags
= FLASHW_ALL
;
939 if ( flags
& wxUSER_ATTENTION_INFO
)
941 // just flash a few times
944 else // wxUSER_ATTENTION_ERROR
946 // flash until the user notices it
947 fwi
.dwFlags
|= FLASHW_TIMERNOFG
;
950 s_pfnFlashWindowEx(&fwi
);
952 else // FlashWindowEx() not available
953 #endif // FlashWindowEx() defined
957 ::FlashWindow(GetHwnd(), TRUE
);
958 #endif // __WXWINCE__
962 // ----------------------------------------------------------------------------
963 // wxTopLevelWindow event handling
964 // ----------------------------------------------------------------------------
966 // Default activation behaviour - set the focus for the first child
968 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
970 if ( event
.GetActive() )
972 // restore focus to the child which was last focused unless we already
974 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
976 wxWindow
*winFocus
= FindFocus();
977 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
979 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
986 wxSetFocusToChild(parent
, &m_winLastFocused
);
991 // remember the last focused child if it is our child
992 m_winLastFocused
= FindFocus();
994 if ( m_winLastFocused
)
996 // let it know that it doesn't have focus any more
997 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
999 // and don't remember it if it's a child from some other frame
1000 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
1002 m_winLastFocused
= NULL
;
1006 wxLogTrace(_T("focus"),
1007 _T("wxTLW %08x deactivated, last focused: %08x."),
1009 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
1016 // the DialogProc for all wxWidgets dialogs
1017 LONG APIENTRY _EXPORT
1018 wxDlgProc(HWND hDlg
,
1020 WPARAM
WXUNUSED(wParam
),
1021 LPARAM
WXUNUSED(lParam
))
1023 if ( message
== WM_INITDIALOG
)
1025 // under CE, add a "Ok" button in the dialog title bar and make it full
1028 // VZ: we should probably allow for overriding this, e.g. by including
1029 // MAXIMIZED flag in the dialog style by default and doing this
1030 // only if it is present...
1032 // Standard SDK doesn't have aygshell.dll: see
1033 // include/wx/msw/wince/libraries.h
1034 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1035 SHINITDLGINFO shidi
;
1036 shidi
.dwMask
= SHIDIM_FLAGS
;
1037 shidi
.dwFlags
= SHIDIF_SIZEDLGFULLSCREEN
1038 #ifndef __SMARTPHONE__
1043 SHInitDialog( &shidi
);
1044 #else // no SHInitDialog()
1049 // for almost all messages, returning FALSE means that we didn't process
1052 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1053 // the first control in the dialog box, but as we set the focus
1054 // ourselves, we return FALSE for it as well
1058 // ============================================================================
1059 // wxTLWHiddenParentModule implementation
1060 // ============================================================================
1062 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
1064 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
1066 bool wxTLWHiddenParentModule::OnInit()
1069 ms_className
= NULL
;
1074 void wxTLWHiddenParentModule::OnExit()
1078 if ( !::DestroyWindow(ms_hwnd
) )
1080 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1088 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1090 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1093 ms_className
= NULL
;
1098 HWND
wxTLWHiddenParentModule::GetHWND()
1102 if ( !ms_className
)
1104 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1107 wxZeroMemory(wndclass
);
1109 wndclass
.lpfnWndProc
= DefWindowProc
;
1110 wndclass
.hInstance
= wxGetInstance();
1111 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1113 if ( !::RegisterClass(&wndclass
) )
1115 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1119 ms_className
= HIDDEN_PARENT_CLASS
;
1123 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1124 (HMENU
)NULL
, wxGetInstance(), NULL
);
1127 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));