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__)
152 // A dummy menubar for dialogs
157 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
159 // let the base class deal with the common styles but fix the ones which
160 // don't make sense for us (we also deal with the borders ourselves)
161 WXDWORD msflags
= wxWindow::MSWGetStyle
163 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
164 ) & ~WS_CHILD
& ~WS_VISIBLE
;
166 // For some reason, WS_VISIBLE needs to be defined on creation for
167 // SmartPhone 2003. The title can fail to be displayed otherwise.
168 #if defined(__SMARTPHONE__) || (defined(__WXWINCE__) && _WIN32_WCE < 400)
169 msflags
|= WS_VISIBLE
;
170 ((wxTopLevelWindowMSW
*)this)->wxWindowBase::Show(true);
173 // first select the kind of window being created
175 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
176 // creates a window with both caption and border, hence we need to use
177 // WS_POPUP in a few cases just to avoid having caption/border which we
180 #if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
181 // border and caption styles
182 if ( style
& wxRESIZE_BORDER
)
183 msflags
|= WS_THICKFRAME
;
184 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
185 *exflags
|= WS_EX_DLGMODALFRAME
;
186 else if ( !(style
& wxBORDER_NONE
) )
187 msflags
|= WS_BORDER
;
192 // normally we consider that all windows without a caption must be popups,
193 // but CE is an exception: there windows normally do not have the caption
194 // but shouldn't be made popups as popups can't have menus and don't look
195 // like normal windows anyhow
197 // TODO: Smartphone appears to like wxCAPTION, but we should check that
199 #if defined(__SMARTPHONE__) || !defined(__WXWINCE__)
200 if ( style
& wxCAPTION
)
201 msflags
|= WS_CAPTION
;
205 #endif // !__WXWINCE__
208 // next translate the individual flags
209 if ( style
& wxMINIMIZE_BOX
)
210 msflags
|= WS_MINIMIZEBOX
;
211 if ( style
& wxMAXIMIZE_BOX
)
212 msflags
|= WS_MAXIMIZEBOX
;
215 if ( style
& wxSYSTEM_MENU
)
216 msflags
|= WS_SYSMENU
;
219 // NB: under CE these 2 styles are not supported currently, we should
220 // call Minimize()/Maximize() "manually" if we want to support them
221 if ( style
& wxMINIMIZE
)
222 msflags
|= WS_MINIMIZE
;
224 #if !defined(__POCKETPC__)
225 if ( style
& wxMAXIMIZE
)
226 msflags
|= WS_MAXIMIZE
;
229 // Keep this here because it saves recoding this function in wxTinyFrame
230 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
231 msflags
|= WS_CAPTION
;
235 // there is no taskbar under CE, so omit all this
236 #if !defined(__WXWINCE__)
237 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
239 if ( style
& wxFRAME_TOOL_WINDOW
)
241 // create the palette-like window
242 *exflags
|= WS_EX_TOOLWINDOW
;
244 // tool windows shouldn't appear on the taskbar (as documented)
245 style
|= wxFRAME_NO_TASKBAR
;
248 // We have to solve 2 different problems here:
250 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
251 // taskbar even if they don't have a parent
253 // 2. frames without this style should appear in the taskbar even
254 // if they're owned (Windows only puts non owned windows into
255 // the taskbar normally)
257 // The second one is solved here by using WS_EX_APPWINDOW flag, the
258 // first one is dealt with in our MSWGetParent() method
260 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
262 // need to force the frame to appear in the taskbar
263 *exflags
|= WS_EX_APPWINDOW
;
265 //else: nothing to do [here]
268 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
269 *exflags
|= WS_EX_CONTEXTHELP
;
270 #endif // !__WXWINCE__
272 if ( style
& wxSTAY_ON_TOP
)
273 *exflags
|= WS_EX_TOPMOST
;
279 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
281 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
282 // parent HWND or it would be always on top of its parent which is not what
283 // we usually want (in fact, we only want it for frames with the
284 // wxFRAME_FLOAT_ON_PARENT flag)
285 HWND hwndParent
= NULL
;
286 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
288 const wxWindow
*parent
= GetParent();
292 // this flag doesn't make sense then and will be ignored
293 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
297 hwndParent
= GetHwndOf(parent
);
300 //else: don't float on parent, must not be owned
302 // now deal with the 2nd taskbar-related problem (see comments above in
304 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
307 hwndParent
= wxTLWHiddenParentModule::GetHWND();
310 return (WXHWND
)hwndParent
;
313 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
314 const wxString
& title
,
318 #ifdef __WXMICROWIN__
319 // no dialogs support under MicroWin yet
320 return CreateFrame(title
, pos
, size
);
321 #else // !__WXMICROWIN__
322 wxWindow
*parent
= GetParent();
324 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
325 // app window as parent - this avoids creating modal dialogs without
327 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
329 parent
= wxTheApp
->GetTopWindow();
333 // don't use transient windows as parents, this is dangerous as it
334 // can lead to a crash if the parent is destroyed before the child
336 // also don't use the window which is currently hidden as then the
337 // dialog would be hidden as well
338 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
346 m_hWnd
= (WXHWND
)::CreateDialogIndirect
349 (DLGTEMPLATE
*)dlgTemplate
,
350 parent
? GetHwndOf(parent
) : NULL
,
356 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
358 wxLogSysError(wxT("Can't create dialog using memory template"));
364 (void)MSWGetCreateWindowFlags(&exflags
);
368 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
369 ::SetWindowPos(GetHwnd(),
370 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
374 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
378 #if !defined(__WXWINCE__)
379 // For some reason, the system menu is activated when we use the
380 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
381 if ( exflags
& WS_EX_CONTEXTHELP
)
383 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
386 wxIcon icon
= winTop
->GetIcon();
389 ::SendMessage(GetHwnd(), WM_SETICON
,
391 (LPARAM
)GetHiconOf(icon
));
397 // move the dialog to its initial position without forcing repainting
399 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
401 if ( x
== (int)CW_USEDEFAULT
)
403 // centre it on the screen - what else can we do?
404 wxSize sizeDpy
= wxGetDisplaySize();
406 x
= (sizeDpy
.x
- w
) / 2;
407 y
= (sizeDpy
.y
- h
) / 2;
410 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
411 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
413 wxLogLastError(wxT("MoveWindow"));
417 if ( !title
.empty() )
419 ::SetWindowText(GetHwnd(), title
);
423 // Create an empty menubar so that we don't see the menubar underneath
426 memset (&mbi
, 0, sizeof (SHMENUBARINFO
));
427 mbi
.cbSize
= sizeof (SHMENUBARINFO
);
428 mbi
.hwndParent
= (HWND
) GetParent()->GetHWND();
429 mbi
.nToolBarId
= 5000;
432 mbi
.dwFlags
= 0 ; // SHCMBF_EMPTYBAR;
433 mbi
.hInstRes
= wxGetInstance();
435 if (!SHCreateMenuBar(&mbi
))
437 wxFAIL_MSG( _T("SHCreateMenuBar failed") );
440 m_menuBarHWND
= (WXHWND
) mbi
.hwndMB
;
445 #ifdef __SMARTPHONE__
446 // Work around title non-display glitch
451 #endif // __WXMICROWIN__/!__WXMICROWIN__
454 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
459 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
461 #if !defined(__HANDHELDPC__) && ((defined(_WIN32_WCE) && _WIN32_WCE < 400) || \
462 defined(__POCKETPC__) || \
463 defined(__SMARTPHONE__))
464 // Always expand to fit the screen in PocketPC or SmartPhone
465 wxSize
sz(wxDefaultSize
);
467 #else // other (including normal desktop) Windows
471 bool result
= MSWCreate(wxCanvasClassName
, title
, pos
, sz
, flags
, exflags
);
473 #ifdef __SMARTPHONE__
474 // Work around title non-display glitch
480 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
482 const wxString
& title
,
486 const wxString
& name
)
488 bool ret
wxDUMMY_INITIALIZE(false);
493 wxSize sizeReal
= size
;
494 if ( !sizeReal
.IsFullySpecified() )
496 sizeReal
.SetDefaults(GetDefaultSize());
499 m_windowStyle
= style
;
503 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
505 wxTopLevelWindows
.Append(this);
508 parent
->AddChild(this);
510 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
512 // we have different dialog templates to allows creation of dialogs
513 // with & without captions under MSWindows, resizeable or not (but a
514 // resizeable dialog always has caption - otherwise it would look too
517 // we need 3 additional WORDs for dialog menu, class and title (as we
518 // don't use DS_SETFONT we don't need the fourth WORD for the font)
519 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
520 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
521 memset(dlgTemplate
, 0, dlgsize
);
523 // these values are arbitrary, they won't be used normally anyhow
526 dlgTemplate
->cx
= 144;
527 dlgTemplate
->cy
= 75;
529 // reuse the code in MSWGetStyle() but correct the results slightly for
531 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
533 // all dialogs are popups
534 dlgTemplate
->style
|= WS_POPUP
;
536 // force 3D-look if necessary, it looks impossibly ugly otherwise
537 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
538 dlgTemplate
->style
|= DS_MODALFRAME
;
540 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
545 ret
= CreateFrame(title
, pos
, sizeReal
);
549 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
551 EnableCloseButton(false);
555 // for some reason we need to manually send ourselves this message as
556 // otherwise the mnemonics are always shown -- even if they're configured
557 // to be hidden until "Alt" is pressed in the control panel
559 // this could indicate a bug somewhere else but for now this is the only
567 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
572 // Native look is full screen window on Smartphones and Standard SDK.
573 // TODO: check that we need this (if we're passing default values to ctor).
574 // Also check that there really is a difference between PocketPC and Smartphone in this regard.
575 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__))
576 if ( style
& wxMAXIMIZE
)
582 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
583 SetRightMenu(); // to nothing for initialization
589 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
592 // Destroy the dummy menubar for dialogs
595 ::DestroyWindow((HWND
) m_menuBarHWND
);
600 // after destroying an owned window, Windows activates the next top level
601 // window in Z order but it may be different from our owner (to reproduce
602 // this simply Alt-TAB to another application and back before closing the
603 // owned frame) whereas we always want to yield activation to our parent
604 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
606 wxWindow
*parent
= GetParent();
609 ::BringWindowToTop(GetHwndOf(parent
));
614 // ----------------------------------------------------------------------------
615 // wxTopLevelWindowMSW showing
616 // ----------------------------------------------------------------------------
618 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
620 ::ShowWindow(GetHwnd(), nShowCmd
);
622 m_iconized
= nShowCmd
== SW_MINIMIZE
;
625 bool wxTopLevelWindowMSW::Show(bool show
)
627 // don't use wxWindow version as we want to call DoShowWindow() ourselves
628 if ( !wxWindowBase::Show(show
) )
634 if ( m_maximizeOnShow
)
637 nShowCmd
= SW_MAXIMIZE
;
639 // This is necessary, or no window appears
640 #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__)
641 DoShowWindow(SW_SHOW
);
644 m_maximizeOnShow
= false;
648 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
649 nShowCmd
= SW_SHOWNA
;
659 DoShowWindow(nShowCmd
);
661 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
662 // Addornments have to be added when the frame is the correct size
663 wxFrame
* frame
= wxDynamicCast(this, wxFrame
);
664 if (frame
&& frame
->GetMenuBar())
665 frame
->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
670 ::BringWindowToTop(GetHwnd());
672 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_windowId
);
673 event
.SetEventObject( this );
674 GetEventHandler()->ProcessEvent(event
);
678 // Try to highlight the correct window (the parent)
681 HWND hWndParent
= GetHwndOf(GetParent());
683 ::BringWindowToTop(hWndParent
);
690 // ----------------------------------------------------------------------------
691 // wxTopLevelWindowMSW maximize/minimize
692 // ----------------------------------------------------------------------------
694 void wxTopLevelWindowMSW::Maximize(bool maximize
)
698 // just maximize it directly
699 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
703 // we can't maximize the hidden frame because it shows it as well, so
704 // just remember that we should do it later in this case
705 m_maximizeOnShow
= maximize
;
709 bool wxTopLevelWindowMSW::IsMaximized() const
714 return ::IsZoomed(GetHwnd()) != 0;
718 void wxTopLevelWindowMSW::Iconize(bool iconize
)
720 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
723 bool wxTopLevelWindowMSW::IsIconized() const
728 // also update the current state
729 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
735 void wxTopLevelWindowMSW::Restore()
737 DoShowWindow(SW_RESTORE
);
740 // ----------------------------------------------------------------------------
741 // wxTopLevelWindowMSW fullscreen
742 // ----------------------------------------------------------------------------
744 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
746 if ( show
== IsFullScreen() )
752 m_fsIsShowing
= show
;
758 // zap the frame borders
760 // save the 'normal' window style
761 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
763 // save the old position, width & height, maximize state
764 m_fsOldSize
= GetRect();
765 m_fsIsMaximized
= IsMaximized();
767 // decide which window style flags to turn off
768 LONG newStyle
= m_fsOldWindowStyle
;
771 if (style
& wxFULLSCREEN_NOBORDER
)
773 offFlags
|= WS_BORDER
;
775 offFlags
|= WS_THICKFRAME
;
778 if (style
& wxFULLSCREEN_NOCAPTION
)
779 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
781 newStyle
&= ~offFlags
;
783 // change our window style to be compatible with full-screen mode
784 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
788 // resize to the size of the display containing us
789 int dpy
= wxDisplay::GetFromWindow(this);
790 if ( dpy
!= wxNOT_FOUND
)
792 rect
= wxDisplay(dpy
).GetGeometry();
794 else // fall back to the main desktop
795 #else // wxUSE_DISPLAY
797 // resize to the size of the desktop
798 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
800 // FIXME: size of the bottom menu (toolbar)
801 // should be taken in account
802 rect
.height
+= rect
.y
;
806 #endif // wxUSE_DISPLAY
810 // now flush the window style cache and actually go full-screen
811 long flags
= SWP_FRAMECHANGED
;
813 // showing the frame full screen should also show it if it's still
817 // don't call wxWindow version to avoid flicker from calling
818 // ::ShowWindow() -- we're going to show the window at the correct
819 // location directly below -- but do call the wxWindowBase version
820 // to sync the internal m_isShown flag
821 wxWindowBase::Show();
823 flags
|= SWP_SHOWWINDOW
;
826 SetWindowPos(GetHwnd(), HWND_TOP
,
827 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
830 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
831 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
834 // finally send an event allowing the window to relayout itself &c
835 wxSizeEvent
event(rect
.GetSize(), GetId());
836 GetEventHandler()->ProcessEvent(event
);
838 else // stop showing full screen
840 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
841 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
843 Maximize(m_fsIsMaximized
);
844 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
845 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
846 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
852 // ----------------------------------------------------------------------------
853 // wxTopLevelWindowMSW misc
854 // ----------------------------------------------------------------------------
856 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
858 SetIcons( wxIconBundle( icon
) );
861 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
863 wxTopLevelWindowBase::SetIcons(icons
);
865 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
866 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
867 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
869 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
870 (LPARAM
)GetHiconOf(sml
) );
873 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
874 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
876 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
877 (LPARAM
)GetHiconOf(big
) );
882 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
884 #if !defined(__WXMICROWIN__)
885 // get system (a.k.a. window) menu
886 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
889 // no system menu at all -- ok if we want to remove the close button
890 // anyhow, but bad if we want to show it
894 // enabling/disabling the close item from it also automatically
895 // disables/enables the close title bar button
896 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
898 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
900 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
905 // update appearance immediately
906 if ( !::DrawMenuBar(GetHwnd()) )
908 wxLogLastError(_T("DrawMenuBar"));
911 #endif // !__WXMICROWIN__
918 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
920 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
921 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
923 // The empty region signifies that the shape should be removed from the
925 if ( region
.IsEmpty() )
927 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
929 wxLogLastError(_T("SetWindowRgn"));
935 // Windows takes ownership of the region, so
936 // we'll have to make a copy of the region to give to it.
937 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
938 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
939 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
940 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
941 delete[] (char*) rgnData
;
943 // SetWindowRgn expects the region to be in coordinants
944 // relative to the window, not the client area. Figure
945 // out the offset, if any.
947 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
948 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
949 ::GetClientRect(GetHwnd(), &rect
);
950 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
951 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
953 // Now call the shape API with the new region.
954 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
956 wxLogLastError(_T("SetWindowRgn"));
962 #endif // !__WXWINCE__
964 void wxTopLevelWindowMSW::RequestUserAttention(int flags
)
966 // check if we can use FlashWindowEx(): unfortunately an explicit test for
967 // FLASHW_STOP, for example, doesn't work because MSVC6 headers do #define
968 // it but don't provide FlashWindowEx() declaration
969 #if (WINVER >= 0x0500 && (defined FLASHW_STOP))
970 // available in the headers, check if it is supported by the system
971 typedef BOOL (WINAPI
*FlashWindowEx_t
)(FLASHWINFO
*pfwi
);
972 FlashWindowEx_t s_pfnFlashWindowEx
= NULL
;
973 if ( !s_pfnFlashWindowEx
)
975 wxDynamicLibrary
dllUser32(_T("user32.dll"));
976 s_pfnFlashWindowEx
= (FlashWindowEx_t
)
977 dllUser32
.GetSymbol(_T("FlashWindowEx"));
979 // we can safely unload user32.dll here, it's goign to remain loaded as
980 // long as the program is running anyhow
983 if ( s_pfnFlashWindowEx
)
985 WinStruct
<FLASHWINFO
> fwi
;
986 fwi
.hwnd
= GetHwnd();
987 fwi
.dwFlags
= FLASHW_ALL
;
988 if ( flags
& wxUSER_ATTENTION_INFO
)
990 // just flash a few times
993 else // wxUSER_ATTENTION_ERROR
995 // flash until the user notices it
996 fwi
.dwFlags
|= FLASHW_TIMERNOFG
;
999 s_pfnFlashWindowEx(&fwi
);
1001 else // FlashWindowEx() not available
1002 #endif // FlashWindowEx() defined
1006 ::FlashWindow(GetHwnd(), TRUE
);
1007 #endif // __WXWINCE__
1011 // ----------------------------------------------------------------------------
1012 // wxTopLevelWindow event handling
1013 // ----------------------------------------------------------------------------
1015 // Default activation behaviour - set the focus for the first child
1017 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
1019 if ( event
.GetActive() )
1021 // restore focus to the child which was last focused unless we already
1023 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
1025 wxWindow
*winFocus
= FindFocus();
1026 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
1028 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
1035 wxSetFocusToChild(parent
, &m_winLastFocused
);
1038 else // deactivating
1040 // remember the last focused child if it is our child
1041 m_winLastFocused
= FindFocus();
1043 if ( m_winLastFocused
)
1045 // let it know that it doesn't have focus any more
1046 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
1048 // and don't remember it if it's a child from some other frame
1049 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
1051 m_winLastFocused
= NULL
;
1055 wxLogTrace(_T("focus"),
1056 _T("wxTLW %08x deactivated, last focused: %08x."),
1058 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
1065 // the DialogProc for all wxWidgets dialogs
1066 LONG APIENTRY _EXPORT
1067 wxDlgProc(HWND hDlg
,
1069 WPARAM
WXUNUSED(wParam
),
1070 LPARAM
WXUNUSED(lParam
))
1072 if ( message
== WM_INITDIALOG
)
1074 // under CE, add a "Ok" button in the dialog title bar and make it full
1077 // TODO: find the window for this HWND, and take into account
1078 // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present.
1080 // Standard SDK doesn't have aygshell.dll: see
1081 // include/wx/msw/wince/libraries.h
1082 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1083 SHINITDLGINFO shidi
;
1084 shidi
.dwMask
= SHIDIM_FLAGS
;
1085 shidi
.dwFlags
= SHIDIF_SIZEDLG
// take account of the SIP or menubar
1086 #ifndef __SMARTPHONE__
1091 SHInitDialog( &shidi
);
1092 #else // no SHInitDialog()
1097 // for almost all messages, returning FALSE means that we didn't process
1100 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1101 // the first control in the dialog box, but as we set the focus
1102 // ourselves, we return FALSE for it as well
1106 // ============================================================================
1107 // wxTLWHiddenParentModule implementation
1108 // ============================================================================
1110 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
1112 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
1114 bool wxTLWHiddenParentModule::OnInit()
1117 ms_className
= NULL
;
1122 void wxTLWHiddenParentModule::OnExit()
1126 if ( !::DestroyWindow(ms_hwnd
) )
1128 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1136 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
1138 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
1141 ms_className
= NULL
;
1146 HWND
wxTLWHiddenParentModule::GetHWND()
1150 if ( !ms_className
)
1152 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1155 wxZeroMemory(wndclass
);
1157 wndclass
.lpfnWndProc
= DefWindowProc
;
1158 wndclass
.hInstance
= wxGetInstance();
1159 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1161 if ( !::RegisterClass(&wndclass
) )
1163 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1167 ms_className
= HIDDEN_PARENT_CLASS
;
1171 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1172 (HMENU
)NULL
, wxGetInstance(), NULL
);
1175 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));