A frame is a window whose size and position can (usually) be changed by the user. It usually has thick borders and a title bar, and can optionally contain a menu bar, toolbar and status bar. A frame can contain any window that is not a frame or dialog.
A frame that has a status bar and toolbar created via the CreateStatusBar/CreateToolBar functions manages these windows, and adjusts the value returned by GetClientSize to reflect the remaining size available to application windows.
Derived from
wxWindow
wxEvtHandler
wxObject
Include files
<wx/frame.h>
Window styles
wxDEFAULT_FRAME_STYLE | Defined as wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BOX | wxSYSTEM_MENU | wxCAPTION. |
wxICONIZE | Display the frame iconized (minimized). Windows only. |
wxCAPTION | Puts a caption on the frame. |
wxMINIMIZE | Identical to wxICONIZE. Windows only. |
wxMINIMIZE_BOX | Displays a minimize box on the frame. |
wxMAXIMIZE | Displays the frame maximized. Windows only. |
wxMAXIMIZE_BOX | Displays a maximize box on the frame. |
wxSTAY_ON_TOP | Stay on top of other windows. Windows only. |
wxSYSTEM_MENU | Displays a system menu. |
wxSIMPLE_BORDER | Displays no border or decorations. GTK and Windows only. |
wxRESIZE_BORDER | Displays a resizeable border around the window (Unix only). |
wxFRAME_FLOAT_ON_PARENT | Causes the frame to be above the parent window in the z-order and not shown in the taskbar. Without this style, frames are created as top-level windows that may be obscured by the parent window, and frame titles are shown in the taskbar. Windows and GTK. |
wxFRAME_TOOL_WINDOW | Causes a frame with a small titlebar to be created; the frame title does not appear in the taskbar. Windows only. |
The default frame style is for normal, resizeable frames. To create a frame which can not be resized by user, you may use the following combination of styles: wxDEFAULT_FRAME_STYLE & | wxRESIZE_BOX | wxMAXIMIZE_BOX). See also window styles overview.
Remarks
An application should normally define an OnCloseWindow handler for the frame to respond to system close events, for example so that related data and subwindows can be cleaned up.
See also
wxMDIParentFrame, wxMDIChildFrame, wxMiniFrame, wxDialog
Members
wxFrame::wxFrame
wxFrame::~wxFrame
wxFrame::Centre
wxFrame::Command
wxFrame::Create
wxFrame::CreateStatusBar
wxFrame::CreateToolBar
wxFrame::GetClientAreaOrigin
wxFrame::GetMenuBar
wxFrame::GetStatusBar
wxFrame::GetTitle
wxFrame::GetToolBar
wxFrame::Iconize
wxFrame::IsIconized
wxFrame::IsMaximized
wxFrame::Maximize
wxFrame::OnActivate
wxFrame::OnCreateStatusBar
wxFrame::OnCreateToolBar
wxFrame::OnMenuCommand
wxFrame::OnMenuHighlight
wxFrame::OnSize
wxFrame::SetIcon
wxFrame::SetMenuBar
wxFrame::SetStatusBar
wxFrame::SetStatusText
wxFrame::SetStatusWidths
wxFrame::SetToolBar
wxFrame::SetTitle
wxFrame::ShowFullScreen
wxFrame()
Default constructor.
wxFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame")
Constructor, creating the window.
Parameters
parent
id
title
pos
size
style
name
Remarks
For Motif, MWM (the Motif Window Manager) should be running for any window styles to work (otherwise all styles take effect).
See also
void ~wxFrame()
Destructor. Destroys all child windows and menu bar if present.
void Centre(int direction = wxBOTH)
Centres the frame on the display.
Parameters
direction
void Command(int id)
Simulate a menu command.
Parameters
id
bool Create(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame")
Used in two-step frame construction. See wxFrame::wxFrame for further details.
virtual wxStatusBar* CreateStatusBar(int number = 1, long style = 0, wxWindowID id = -1, const wxString& name = "statusBar")
Creates a status bar at the bottom of the frame.
Parameters
number
style
id
name
Return value
A pointer to the the status bar if it was created successfully, NULL otherwise.
Remarks
The width of the status bar is the whole width of the frame (adjusted automatically when resizing), and the height and text size are chosen by the host windowing system.
By default, the status bar is an instance of wxStatusBar. To use a different class, override wxFrame::OnCreateStatusBar.
Note that you can put controls and other windows on the status bar if you wish.
See also
wxFrame::SetStatusText, wxFrame::OnCreateStatusBar, wxFrame::GetStatusBar
virtual wxToolBar* CreateToolBar(long style = wxNO_BORDER | wxTB_HORIZONTAL, wxWindowID id = -1, const wxString& name = "toolBar")
Creates a toolbar at the top or left of the frame.
Parameters
style
id
name
Return value
A pointer to the the toolbar if it was created successfully, NULL otherwise.
Remarks
By default, the toolbar is an instance of wxToolBar (which is defined to be a suitable toolbar class on each platform, such as wxToolBar95). To use a different class, override wxFrame::OnCreateToolBar.
When a toolbar has been created with this function, or made known to the frame with wxFrame::SetToolBar, the frame will manage the toolbar position and adjust the return value from wxWindow::GetClientSize to reflect the available space for application windows.
See also
wxFrame::CreateStatusBar, wxFrame::OnCreateToolBar, wxFrame::SetToolBar, wxFrame::GetToolBar
wxPoint GetClientAreaOrigin() const
Returns the origin of the frame client area (in client coordinates). It may be different from (0, 0) if the frame has a toolbar.
wxMenuBar* GetMenuBar() const
Returns a pointer to the menubar currently associated with the frame (if any).
See also
wxFrame::SetMenuBar, wxMenuBar, wxMenu
wxStatusBar* GetStatusBar() const
Returns a pointer to the status bar currently associated with the frame (if any).
See also
wxFrame::CreateStatusBar, wxStatusBar
wxString GetTitle() const
Gets a string containing the frame title. See wxFrame::SetTitle.
wxToolBar* GetToolBar() const
Returns a pointer to the toolbar currently associated with the frame (if any).
See also
wxFrame::CreateToolBar, wxToolBar, wxFrame::SetToolBar
void Iconize(bool iconize)
Iconizes or restores the frame. Windows only.
Parameters
izonize
See also
wxFrame::IsIconized, wxFrame::Maximize.
bool IsIconized() const
Returns TRUE if the frame is iconized. Windows only.
bool IsMaximized() const
Returns TRUE if the frame is maximized.
void Maximize(bool maximize)
Maximizes or restores the frame.
Parameters
maximize
Remarks
This function only works under Windows.
See also
void OnActivate(wxActivateEvent& event)
Called when a window is activated or deactivated (MS Windows only). See also wxActivateEvent.
virtual wxStatusBar* OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name)
Virtual function called when a status bar is requested by wxFrame::CreateStatusBar.
Parameters
number
style
id
name
Return value
A status bar object.
Remarks
An application can override this function to return a different kind of status bar. The default implementation returns an instance of wxStatusBar.
See also
wxFrame::CreateStatusBar, wxStatusBar.
virtual wxToolBar* OnCreateToolBar(long style, wxWindowID id, const wxString& name)
Virtual function called when a toolbar is requested by wxFrame::CreateToolBar.
Parameters
style
id
name
Return value
A toolbar object.
Remarks
An application can override this function to return a different kind of toolbar. The default implementation returns an instance of wxToolBar.
See also
wxFrame::CreateToolBar, wxToolBar.
void OnMenuCommand(wxCommandEvent& event)
void OnMenuHighlight(wxMenuEvent& event)
See wxWindow::OnMenuHighlight.
void OnSize(wxSizeEvent& event)
See wxWindow::OnSize.
The default wxFrame::OnSize implementation looks for a single subwindow, and if one is found, resizes it to fit inside the frame. Override this member if more complex behaviour is required (for example, if there are several subwindows).
void SetIcon(const wxIcon& icon)
Sets the icon for this frame.
Parameters
icon
Remarks
The frame takes a 'copy' of icon, but since it uses reference counting, the copy is very quick. It is safe to delete icon after calling this function.
Under Windows, instead of using SetIcon, you can add the following lines to your MS Windows resource file:
wxSTD_MDIPARENTFRAME ICON icon1.ico wxSTD_MDICHILDFRAME ICON icon2.ico wxSTD_FRAME ICON icon3.icowhere icon1.ico will be used for the MDI parent frame, icon2.ico will be used for MDI child frames, and icon3.ico will be used for non-MDI frames.
If these icons are not supplied, and SetIcon is not called either, then the following defaults apply if you have included wx.rc.
wxDEFAULT_FRAME ICON std.ico wxDEFAULT_MDIPARENTFRAME ICON mdi.ico wxDEFAULT_MDICHILDFRAME ICON child.icoYou can replace std.ico, mdi.ico and child.ico with your own defaults for all your wxWindows application. Currently they show the same icon.
Note: a wxWindows application linked with subsystem equal to 4.0 (i.e. marked as a Windows 95 application) doesn't respond properly to wxFrame::SetIcon. To work around this until a solution is found, mark your program as a 3.5 application. This will also ensure that Windows provides small icons for the application automatically.
See also wxIcon.
void SetMenuBar(wxMenuBar* menuBar)
Tells the frame to show the given menu bar.
Parameters
menuBar
Remarks
If the frame is destroyed, the menu bar and its menus will be destroyed also, so do not delete the menu bar explicitly (except by resetting the frame's menu bar to another frame or NULL).
Under Windows, a call to wxFrame::OnSize is generated, so be sure to initialize data members properly before calling SetMenuBar.
Note that it is not possible to call this function twice for the same frame object.
See also
wxFrame::GetMenuBar, wxMenuBar, wxMenu.
void SetStatusBar(wxStatusBar* statusBar)
Associates a status bar with the frame.
See also
wxFrame::CreateStatusBar, wxStatusBar, wxFrame::GetStatusBar
virtual void SetStatusText(const wxString& text, int number = 0)
Sets the status bar text and redraws the status bar.
Parameters
text
number
Remarks
Use an empty string to clear the status bar.
See also
wxFrame::CreateStatusBar, wxStatusBar
virtual void SetStatusWidths(int n, int *widths)
Sets the widths of the fields in the status bar.
Parameters
nThe number of fields in the status bar. It must be the same used in CreateStatusBar.
widths
Remarks
The widths of the variable fields are calculated from the total width of all fields, minus the sum of widths of the non-variable fields, divided by the number of variable fields.
wxPython note: Only a single parameter is required, a Python list of integers.
void SetToolBar(wxToolBar* toolBar)
Associates a toolbar with the frame.
See also
wxFrame::CreateToolBar, wxToolBar, wxFrame::GetToolBar
virtual void SetTitle(const wxString& title)
Sets the frame title.
Parameters
title
See also
bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL)
Passing TRUE to shows shows the frame full-screen, and passing FALSE restores the frame again. style is a bit list containing some or all of the following values, which indicate what elements of the frame to hide in full-screen mode:
This function only works on Windows and has not been tested with MDI frames.