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 #if defined(__WXWINCE__) && _WIN32_WCE < 400
163 msflags
|= WS_VISIBLE
;
166 // first select the kind of window being created
168 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
169 // creates a window with both caption and border, hence we need to use
170 // WS_POPUP in a few cases just to avoid having caption/border which we
173 #if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
174 // border and caption styles
175 if ( style
& wxRESIZE_BORDER
)
176 msflags
|= WS_THICKFRAME
;
177 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
178 *exflags
|= WS_EX_DLGMODALFRAME
;
179 else if ( !(style
& wxBORDER_NONE
) )
180 msflags
|= WS_BORDER
;
185 // normally we consider that all windows without caption must be popups,
186 // but CE is an exception: there windows normally do not have the caption
187 // but shouldn't be made popups as popups can't have menus and don't look
188 // like normal windows anyhow
189 if ( style
& wxCAPTION
)
190 msflags
|= WS_CAPTION
;
194 #endif // !__WXWINCE__
196 // next translate the individual flags
197 if ( style
& wxMINIMIZE_BOX
)
198 msflags
|= WS_MINIMIZEBOX
;
199 if ( style
& wxMAXIMIZE_BOX
)
200 msflags
|= WS_MAXIMIZEBOX
;
201 if ( style
& wxSYSTEM_MENU
)
202 msflags
|= WS_SYSMENU
;
204 // NB: under CE these 2 styles are not supported currently, we should
205 // call Minimize()/Maximize() "manually" if we want to support them
206 if ( style
& wxMINIMIZE
)
207 msflags
|= WS_MINIMIZE
;
208 if ( style
& wxMAXIMIZE
)
209 msflags
|= WS_MAXIMIZE
;
211 // Keep this here because it saves recoding this function in wxTinyFrame
212 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
213 msflags
|= WS_CAPTION
;
217 // there is no taskbar under CE, so omit all this
218 #if !defined(__WXWINCE__)
219 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
221 if ( style
& wxFRAME_TOOL_WINDOW
)
223 // create the palette-like window
224 *exflags
|= WS_EX_TOOLWINDOW
;
226 // tool windows shouldn't appear on the taskbar (as documented)
227 style
|= wxFRAME_NO_TASKBAR
;
230 // We have to solve 2 different problems here:
232 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
233 // taskbar even if they don't have a parent
235 // 2. frames without this style should appear in the taskbar even
236 // if they're owned (Windows only puts non owned windows into
237 // the taskbar normally)
239 // The second one is solved here by using WS_EX_APPWINDOW flag, the
240 // first one is dealt with in our MSWGetParent() method
242 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
244 // need to force the frame to appear in the taskbar
245 *exflags
|= WS_EX_APPWINDOW
;
247 //else: nothing to do [here]
249 #endif // !__WXWINCE__
251 if ( style
& wxSTAY_ON_TOP
)
252 *exflags
|= WS_EX_TOPMOST
;
254 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
255 *exflags
|= WS_EX_CONTEXTHELP
;
261 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
263 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
264 // parent HWND or it would be always on top of its parent which is not what
265 // we usually want (in fact, we only want it for frames with the
266 // wxFRAME_FLOAT_ON_PARENT flag)
267 HWND hwndParent
= NULL
;
268 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
270 const wxWindow
*parent
= GetParent();
274 // this flag doesn't make sense then and will be ignored
275 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
279 hwndParent
= GetHwndOf(parent
);
282 //else: don't float on parent, must not be owned
284 // now deal with the 2nd taskbar-related problem (see comments above in
286 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
289 hwndParent
= wxTLWHiddenParentModule::GetHWND();
292 return (WXHWND
)hwndParent
;
295 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
296 const wxString
& title
,
300 #ifdef __WXMICROWIN__
301 // no dialogs support under MicroWin yet
302 return CreateFrame(title
, pos
, size
);
303 #else // !__WXMICROWIN__
304 wxWindow
*parent
= GetParent();
306 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
307 // app window as parent - this avoids creating modal dialogs without
309 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
311 parent
= wxTheApp
->GetTopWindow();
315 // don't use transient windows as parents, this is dangerous as it
316 // can lead to a crash if the parent is destroyed before the child
318 // also don't use the window which is currently hidden as then the
319 // dialog would be hidden as well
320 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
328 m_hWnd
= (WXHWND
)::CreateDialogIndirect
331 (DLGTEMPLATE
*)dlgTemplate
,
332 parent
? GetHwndOf(parent
) : NULL
,
338 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
340 wxLogSysError(wxT("Can't create dialog using memory template"));
346 (void)MSWGetCreateWindowFlags(&exflags
);
350 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
351 ::SetWindowPos(GetHwnd(),
352 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
356 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
360 #if defined(__WIN95__)
361 // For some reason, the system menu is activated when we use the
362 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
363 if ( exflags
& WS_EX_CONTEXTHELP
)
365 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
368 wxIcon icon
= winTop
->GetIcon();
371 ::SendMessage(GetHwnd(), WM_SETICON
,
373 (LPARAM
)GetHiconOf(icon
));
379 // move the dialog to its initial position without forcing repainting
381 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
383 if ( x
== (int)CW_USEDEFAULT
)
385 // centre it on the screen - what else can we do?
386 wxSize sizeDpy
= wxGetDisplaySize();
388 x
= (sizeDpy
.x
- w
) / 2;
389 y
= (sizeDpy
.y
- h
) / 2;
392 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
393 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
395 wxLogLastError(wxT("MoveWindow"));
399 if ( !title
.empty() )
401 ::SetWindowText(GetHwnd(), title
);
407 #endif // __WXMICROWIN__/!__WXMICROWIN__
410 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
415 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
417 #if !defined(__HANDHELDPC__) && ((defined(_WIN32_WCE) && _WIN32_WCE < 400) || \
418 defined(__POCKETPC__) || \
419 defined(__SMARTPHONE__))
420 // Always expand to fit the screen in PocketPC or SmartPhone
421 wxSize
sz(wxDefaultSize
);
423 #else // other (including normal desktop) Windows
427 return MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
430 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
432 const wxString
& title
,
436 const wxString
& name
)
438 bool ret
wxDUMMY_INITIALIZE(false);
443 wxSize sizeReal
= size
;
444 if ( !sizeReal
.IsFullySpecified() )
446 sizeReal
.SetDefaults(GetDefaultSize());
449 m_windowStyle
= style
;
453 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
455 wxTopLevelWindows
.Append(this);
458 parent
->AddChild(this);
460 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
462 // we have different dialog templates to allows creation of dialogs
463 // with & without captions under MSWindows, resizeable or not (but a
464 // resizeable dialog always has caption - otherwise it would look too
467 // we need 3 additional WORDs for dialog menu, class and title (as we
468 // don't use DS_SETFONT we don't need the fourth WORD for the font)
469 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
470 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
471 memset(dlgTemplate
, 0, dlgsize
);
473 // these values are arbitrary, they won't be used normally anyhow
476 dlgTemplate
->cx
= 144;
477 dlgTemplate
->cy
= 75;
479 // reuse the code in MSWGetStyle() but correct the results slightly for
481 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
483 // all dialogs are popups
484 dlgTemplate
->style
|= WS_POPUP
;
486 // force 3D-look if necessary, it looks impossibly ugly otherwise
487 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
488 dlgTemplate
->style
|= DS_MODALFRAME
;
490 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
495 ret
= CreateFrame(title
, pos
, sizeReal
);
498 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
500 EnableCloseButton(false);
503 // for some reason we need to manually send ourselves this message as
504 // otherwise the mnemonics are always shown -- even if they're configured
505 // to be hidden until "Alt" is pressed in the control panel
507 // this could indicate a bug somewhere else but for now this is the only
515 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
520 // Native look is full screen window on Smartphones and Standard SDK
521 #if defined(__WXWINCE__)
522 if ( style
& wxMAXIMIZE
)
528 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
529 SetRightMenu(); // to nothing for initialization
535 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
537 // after destroying an owned window, Windows activates the next top level
538 // window in Z order but it may be different from our owner (to reproduce
539 // this simply Alt-TAB to another application and back before closing the
540 // owned frame) whereas we always want to yield activation to our parent
541 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
543 wxWindow
*parent
= GetParent();
546 ::BringWindowToTop(GetHwndOf(parent
));
551 // ----------------------------------------------------------------------------
552 // wxTopLevelWindowMSW showing
553 // ----------------------------------------------------------------------------
555 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
557 ::ShowWindow(GetHwnd(), nShowCmd
);
559 m_iconized
= nShowCmd
== SW_MINIMIZE
;
562 bool wxTopLevelWindowMSW::Show(bool show
)
564 // don't use wxWindow version as we want to call DoShowWindow() ourselves
565 if ( !wxWindowBase::Show(show
) )
571 if ( m_maximizeOnShow
)
574 nShowCmd
= SW_MAXIMIZE
;
576 // This is necessary, or no window appears
577 #ifdef __WINCE_STANDARDSDK__
578 DoShowWindow(SW_SHOW
);
581 m_maximizeOnShow
= false;
585 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
586 nShowCmd
= SW_SHOWNA
;
596 DoShowWindow(nShowCmd
);
598 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
599 // Addornments have to be added when the frame is the correct size
600 wxFrame
* frame
= wxDynamicCast(this, wxFrame
);
601 if (frame
&& frame
->GetMenuBar())
602 frame
->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
607 ::BringWindowToTop(GetHwnd());
609 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_windowId
);
610 event
.SetEventObject( this );
611 GetEventHandler()->ProcessEvent(event
);
615 // Try to highlight the correct window (the parent)
618 HWND hWndParent
= GetHwndOf(GetParent());
620 ::BringWindowToTop(hWndParent
);
627 // ----------------------------------------------------------------------------
628 // wxTopLevelWindowMSW maximize/minimize
629 // ----------------------------------------------------------------------------
631 void wxTopLevelWindowMSW::Maximize(bool maximize
)
635 // just maximize it directly
636 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
640 // we can't maximize the hidden frame because it shows it as well, so
641 // just remember that we should do it later in this case
642 m_maximizeOnShow
= maximize
;
646 bool wxTopLevelWindowMSW::IsMaximized() const
651 return ::IsZoomed(GetHwnd()) != 0;
655 void wxTopLevelWindowMSW::Iconize(bool iconize
)
657 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
660 bool wxTopLevelWindowMSW::IsIconized() const
665 // also update the current state
666 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
672 void wxTopLevelWindowMSW::Restore()
674 DoShowWindow(SW_RESTORE
);
677 // ----------------------------------------------------------------------------
678 // wxTopLevelWindowMSW fullscreen
679 // ----------------------------------------------------------------------------
681 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
683 if ( show
== IsFullScreen() )
689 m_fsIsShowing
= show
;
695 // zap the frame borders
697 // save the 'normal' window style
698 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
700 // save the old position, width & height, maximize state
701 m_fsOldSize
= GetRect();
702 m_fsIsMaximized
= IsMaximized();
704 // decide which window style flags to turn off
705 LONG newStyle
= m_fsOldWindowStyle
;
708 if (style
& wxFULLSCREEN_NOBORDER
)
710 offFlags
|= WS_BORDER
;
712 offFlags
|= WS_THICKFRAME
;
715 if (style
& wxFULLSCREEN_NOCAPTION
)
716 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
718 newStyle
&= ~offFlags
;
720 // change our window style to be compatible with full-screen mode
721 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
725 // resize to the size of the display containing us
726 int dpy
= wxDisplay::GetFromWindow(this);
727 if ( dpy
!= wxNOT_FOUND
)
729 rect
= wxDisplay(dpy
).GetGeometry();
731 else // fall back to the main desktop
732 #else // wxUSE_DISPLAY
734 // resize to the size of the desktop
735 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
737 // FIXME: size of the bottom menu (toolbar)
738 // should be taken in account
739 rect
.height
+= rect
.y
;
743 #endif // wxUSE_DISPLAY
747 // now flush the window style cache and actually go full-screen
748 long flags
= SWP_FRAMECHANGED
;
750 // showing the frame full screen should also show it if it's still
754 // don't call wxWindow version to avoid flicker from calling
755 // ::ShowWindow() -- we're going to show the window at the correct
756 // location directly below -- but do call the wxWindowBase version
757 // to sync the internal m_isShown flag
758 wxWindowBase::Show();
760 flags
|= SWP_SHOWWINDOW
;
763 SetWindowPos(GetHwnd(), HWND_TOP
,
764 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
767 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
768 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
771 // finally send an event allowing the window to relayout itself &c
772 wxSizeEvent
event(rect
.GetSize(), GetId());
773 GetEventHandler()->ProcessEvent(event
);
775 else // stop showing full screen
777 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
778 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
780 Maximize(m_fsIsMaximized
);
781 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
782 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
783 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
789 // ----------------------------------------------------------------------------
790 // wxTopLevelWindowMSW misc
791 // ----------------------------------------------------------------------------
793 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
795 SetIcons( wxIconBundle( icon
) );
798 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
800 wxTopLevelWindowBase::SetIcons(icons
);
802 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
803 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
804 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
806 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
807 (LPARAM
)GetHiconOf(sml
) );
810 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
811 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
813 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
814 (LPARAM
)GetHiconOf(big
) );
819 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
821 #if !defined(__WXMICROWIN__)
822 // get system (a.k.a. window) menu
823 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
826 // no system menu at all -- ok if we want to remove the close button
827 // anyhow, but bad if we want to show it
831 // enabling/disabling the close item from it also automatically
832 // disables/enables the close title bar button
833 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
835 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
837 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
842 // update appearance immediately
843 if ( !::DrawMenuBar(GetHwnd()) )
845 wxLogLastError(_T("DrawMenuBar"));
848 #endif // !__WXMICROWIN__
855 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
857 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
858 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
860 // The empty region signifies that the shape should be removed from the
862 if ( region
.IsEmpty() )
864 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
866 wxLogLastError(_T("SetWindowRgn"));
872 // Windows takes ownership of the region, so
873 // we'll have to make a copy of the region to give to it.
874 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
875 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
876 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
877 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
878 delete[] (char*) rgnData
;
880 // SetWindowRgn expects the region to be in coordinants
881 // relative to the window, not the client area. Figure
882 // out the offset, if any.
884 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
885 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
886 ::GetClientRect(GetHwnd(), &rect
);
887 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
888 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
890 // Now call the shape API with the new region.
891 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
893 wxLogLastError(_T("SetWindowRgn"));
899 #endif // !__WXWINCE__
901 void wxTopLevelWindowMSW::RequestUserAttention(int flags
)
903 // check if we can use FlashWindowEx(): unfortunately an explicit test for
904 // FLASHW_STOP, for example, doesn't work because MSVC6 headers do #define
905 // it but don't provide FlashWindowEx() declaration
906 #if (WINVER >= 0x0500 && (defined FLASHW_STOP))
907 // available in the headers, check if it is supported by the system
908 typedef BOOL (WINAPI
*FlashWindowEx_t
)(FLASHWINFO
*pfwi
);
909 FlashWindowEx_t s_pfnFlashWindowEx
= NULL
;
910 if ( !s_pfnFlashWindowEx
)
912 wxDynamicLibrary
dllUser32(_T("user32.dll"));
913 s_pfnFlashWindowEx
= (FlashWindowEx_t
)
914 dllUser32
.GetSymbol(_T("FlashWindowEx"));
916 // we can safely unload user32.dll here, it's goign to remain loaded as
917 // long as the program is running anyhow
920 if ( s_pfnFlashWindowEx
)
922 WinStruct
<FLASHWINFO
> fwi
;
923 fwi
.hwnd
= GetHwnd();
924 fwi
.dwFlags
= FLASHW_ALL
;
925 if ( flags
& wxUSER_ATTENTION_INFO
)
927 // just flash a few times
930 else // wxUSER_ATTENTION_ERROR
932 // flash until the user notices it
933 fwi
.dwFlags
|= FLASHW_TIMERNOFG
;
936 s_pfnFlashWindowEx(&fwi
);
938 else // FlashWindowEx() not available
939 #endif // FlashWindowEx() defined
943 ::FlashWindow(GetHwnd(), TRUE
);
944 #endif // __WXWINCE__
948 // ----------------------------------------------------------------------------
949 // wxTopLevelWindow event handling
950 // ----------------------------------------------------------------------------
952 // Default activation behaviour - set the focus for the first child
954 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
956 if ( event
.GetActive() )
958 // restore focus to the child which was last focused unless we already
960 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
962 wxWindow
*winFocus
= FindFocus();
963 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
965 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
972 wxSetFocusToChild(parent
, &m_winLastFocused
);
977 // remember the last focused child if it is our child
978 m_winLastFocused
= FindFocus();
980 if ( m_winLastFocused
)
982 // let it know that it doesn't have focus any more
983 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
985 // and don't remember it if it's a child from some other frame
986 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
988 m_winLastFocused
= NULL
;
992 wxLogTrace(_T("focus"),
993 _T("wxTLW %08x deactivated, last focused: %08x."),
995 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
1002 // the DialogProc for all wxWidgets dialogs
1003 LONG APIENTRY _EXPORT
1004 wxDlgProc(HWND hDlg
,
1006 WPARAM
WXUNUSED(wParam
),
1007 LPARAM
WXUNUSED(lParam
))
1009 if ( message
== WM_INITDIALOG
)
1011 // under CE, add a "Ok" button in the dialog title bar and make it full
1014 // VZ: we should probably allow for overriding this, e.g. by including
1015 // MAXIMIZED flag in the dialog style by default and doing this
1016 // only if it is present...
1018 // Standard SDK doesn't have aygshell.dll: see
1019 // include/wx/msw/wince/libraries.h
1020 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1021 SHINITDLGINFO shidi
;
1022 shidi
.dwMask
= SHIDIM_FLAGS
;
1023 shidi
.dwFlags
= SHIDIF_SIZEDLGFULLSCREEN
1024 #ifndef __SMARTPHONE__
1029 SHInitDialog( &shidi
);
1030 #else // no SHInitDialog()
1035 // for almost all messages, returning FALSE means that we didn't process
1038 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1039 // the first control in the dialog box, but as we set the focus
1040 // ourselves, we return FALSE for it as well
1044 // ============================================================================
1045 // wxTLWHiddenParentModule implementation
1046 // ============================================================================
1048 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
1050 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
1052 bool wxTLWHiddenParentModule::OnInit()
1055 ms_className
= NULL
;
1060 void wxTLWHiddenParentModule::OnExit()
1064 if ( !::DestroyWindow(ms_hwnd
) )
1066 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1074 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1076 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1079 ms_className
= NULL
;
1084 HWND
wxTLWHiddenParentModule::GetHWND()
1088 if ( !ms_className
)
1090 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1093 wxZeroMemory(wndclass
);
1095 wndclass
.lpfnWndProc
= DefWindowProc
;
1096 wndclass
.hInstance
= wxGetInstance();
1097 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1099 if ( !::RegisterClass(&wndclass
) )
1101 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1105 ms_className
= HIDDEN_PARENT_CLASS
;
1109 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1110 (HMENU
)NULL
, wxGetInstance(), NULL
);
1113 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));