## wxFrame

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_BORDER | 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 all other windows, see also wxFRAME_FLOAT_ON_PARENT. 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.
wxFRAME_TOOL_WINDOW | Causes a frame with a small titlebar to be created; the frame does not appear in the taskbar under Windows.
wxFRAME_NO_TASKBAR | Creates an otherwise normal frame but it does not appear in the taskbar under Windows (note that it will minimize to the desktop window which may seem strange to the users and thus it might be better to use this style only without wxMINIMIZE_BOX style). Has no effect under other platforms.
wxFRAME_FLOAT_ON_PARENT | The frame will always be on top of its parent (unlike wxSTAY_ON_TOP). A frame created with this style must have a non-NULL parent.
wxFRAME_EX_CONTEXTHELP | Under Windows, puts a query button on the caption. When pressed, Windows will go into a context-sensitive help mode and wxWindows will send a wxEVT_HELP event if the user clicked on an application window. Note that this is an extended style and must be set by calling SetExtraStyle before Create is called (two-step construction). You cannot use this style together with wxMAXIMIZE_BOX or wxMINIMIZE_BOX, so you should use `wxDEFAULT_FRAME_STYLE & (wxMINIMIZE_BOX | wxMAXIMIZE_BOX)` for the frames having this style (the dialogs don't have minimize nor maximize box by default)
wxFRAME_SHAPED | Windows with this style are allowed to have their shape changed with the SetShape method.

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_BORDER | wxRESIZE_BOX | wxMAXIMIZE_BOX)`. See also window styles overview.

Remarks

An application should normally define an wxCloseEvent 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::GetStatusBarPane
wxFrame::GetTitle
wxFrame::GetToolBar
wxFrame::Iconize
wxFrame::IsFullScreen
wxFrame::IsIconized
wxFrame::IsMaximized
wxFrame::Maximize
wxFrame::OnActivate
wxFrame::OnCreateStatusBar
wxFrame::OnCreateToolBar
wxFrame::OnMenuHighlight
wxFrame::OnSize
wxFrame::SendSizeEvent
wxFrame::SetIcon
wxFrame::SetIcons
wxFrame::SetMenuBar
wxFrame::SetShape
wxFrame::SetStatusBar
wxFrame::SetStatusBarPane
wxFrame::SetStatusText
wxFrame::SetStatusWidths
wxFrame::SetToolBar
wxFrame::SetTitle
wxFrame::ShowFullScreen

### wxFrame::wxFrame

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

The window parent. This may be NULL. If it is non-NULL, the frame will always be displayed on top of the parent window on Windows.

id

The window identifier. It may take a value of -1 to indicate a default value.

title

The caption to be displayed on the frame's title bar.

pos

The window position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxWindows, depending on platform.

size

The window size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxWindows, depending on platform.

style

The window style. See wxFrame.

name

The name of the window. This parameter is used to associate a name with the item, allowing the application user to set Motif resource values for individual windows.

Remarks

For Motif, MWM (the Motif Window Manager) should be running for any window styles to work (otherwise all styles take effect).

See also

wxFrame::Create

### wxFrame::~wxFrame

void ~wxFrame()

Destructor. Destroys all child windows and menu bar if present.

### wxFrame::Centre

void Centre(int direction = wxBOTH)

Centres the frame on the display.

Parameters

direction

The parameter may be `wxHORIZONTAL`, `wxVERTICAL` or `wxBOTH`.

### wxFrame::Command

void Command(int id)

Simulate a menu command.

Parameters

id

The identifier for a menu item.

### wxFrame::Create

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.

### wxFrame::CreateStatusBar

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

The number of fields to create. Specify a value greater than 1 to create a multi-field status bar.

style

The status bar style. See wxStatusBar for a list of valid styles.

id

The status bar window identifier. If -1, an identifier will be chosen by wxWindows.

name

The status bar window 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

### wxFrame::CreateToolBar

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

The toolbar style. See wxToolBar for a list of valid styles.

id

The toolbar window identifier. If -1, an identifier will be chosen by wxWindows.

name

The toolbar window 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

### wxFrame::GetClientAreaOrigin

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.

### wxFrame::GetMenuBar

wxMenuBar* GetMenuBar() const

Returns a pointer to the menubar currently associated with the frame (if any).

See also

wxFrame::SetMenuBar, wxMenuBar, wxMenu

### wxFrame::GetStatusBar

wxStatusBar* GetStatusBar() const

Returns a pointer to the status bar currently associated with the frame (if any).

See also

wxFrame::CreateStatusBar, wxStatusBar

### wxFrame::GetStatusBarPane

int GetStatusBarPane()

Returns the status bar pane used to display menu and toolbar help.

See also

wxFrame::SetStatusBarPane

### wxFrame::GetTitle

wxString GetTitle() const

Gets a string containing the frame title. See wxFrame::SetTitle.

### wxFrame::GetToolBar

wxToolBar* GetToolBar() const

Returns a pointer to the toolbar currently associated with the frame (if any).

See also

wxFrame::CreateToolBar, wxToolBar, wxFrame::SetToolBar

### wxFrame::Iconize

void Iconize(bool iconize)

Iconizes or restores the frame.

Parameters

iconize

If TRUE, iconizes the frame; if FALSE, shows and restores it.

See also

wxFrame::IsIconized, wxFrame::Maximize.

### wxFrame::IsFullScreen

bool IsFullScreen()

Returns TRUE if the frame is in fullscreen mode.

See also

wxFrame::ShowFullScreen

### wxFrame::IsIconized

bool IsIconized() const

Returns TRUE if the frame is iconized.

### wxFrame::IsMaximized

bool IsMaximized() const

Returns TRUE if the frame is maximized.

### wxFrame::Maximize

void Maximize(bool maximize)

Maximizes or restores the frame.

Parameters

maximize

If TRUE, maximizes the frame, otherwise it restores it.

Remarks

This function only works under Windows.

See also

wxFrame::Iconize

### wxFrame::OnActivate

void OnActivate(wxActivateEvent& event)

Called when a window is activated or deactivated (MS Windows only). See also wxActivateEvent.

### wxFrame::OnCreateStatusBar

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

The number of fields to create.

style

The window style. See wxStatusBar for a list of valid styles.

id

The window identifier. If -1, an identifier will be chosen by wxWindows.

name

The window 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.

### wxFrame::OnCreateToolBar

virtual wxToolBar* OnCreateToolBar(long style, wxWindowID id, const wxString& name)

Virtual function called when a toolbar is requested by wxFrame::CreateToolBar.

Parameters

style

The toolbar style. See wxToolBar for a list of valid styles.

id

The toolbar window identifier. If -1, an identifier will be chosen by wxWindows.

name

The toolbar window 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.

### wxFrame::OnMenuHighlight

void OnMenuHighlight(wxMenuEvent& event)

The default implementation displays an appropriate help string in the status bar, if there is one.

See wxMenuEvent.

### wxFrame::OnSize

void OnSize(wxSizeEvent& event)

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).

See wxSizeEvent.

### wxFrame::SendSizeEvent

void SendSizeEvent()

This function sends a dummy size event to the frame forcing it to reevaluate its children positions. It is sometimes useful to call this function after adding or deleting a children after the frame creation or if a child size changes.

Note that if the frame is using either sizers or constraints for the children layout, it is enough to call Layout() directly and this function should not be used in this case.

### wxFrame::SetIcon

void SetIcon(const wxIcon& icon)

Sets the icon for this frame.

Parameters

icon

The icon to associate with this frame.

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.

See also wxIcon.

### wxFrame::SetIcons

void SetIcons(const wxIconBundle& icons)

Sets the icons for this frame.

Parameters

icons

The icons to associate with this frame.

See also wxIconBundle.

### wxFrame::SetMenuBar

void SetMenuBar(wxMenuBar* menuBar)

Tells the frame to show the given menu bar.

Parameters

menuBar

The menu bar to associate with the frame.

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.

### wxFrame::SetShape

bool SetShape(const wxRegion& region)

If the platform supports it, sets the shape of the window to that depicted by region. The system will not display or respond to any mouse event for the pixels that lie outside of the region. To reset the window to the normal rectangular shape simply call SetShape again with an empty region. Returns TRUE if the operation is successful.

### wxFrame::SetStatusBar

void SetStatusBar(wxStatusBar* statusBar)

Associates a status bar with the frame.

See also

wxFrame::CreateStatusBar, wxStatusBar, wxFrame::GetStatusBar

### wxFrame::SetStatusBarPane

void SetStatusBarPane(int n)

Set the status bar pane used to display menu and toolbar help. Using -1 disables help display.

### wxFrame::SetStatusText

virtual void SetStatusText(const wxString& text, int number = 0)

Sets the status bar text and redraws the status bar.

Parameters

text

The text for the status field.

number

The status field (starting from zero).

Remarks

Use an empty string to clear the status bar.

See also

wxFrame::CreateStatusBar, wxStatusBar

### wxFrame::SetStatusWidths

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

Must contain an array of n integers, each of which is a status field width in pixels. A value of -1 indicates that the field is variable width; at least one field must be -1. You should delete this array after calling SetStatusWidths.

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.

wxPerl note: In wxPerl this method takes the field widths as parameters.

### wxFrame::SetToolBar

void SetToolBar(wxToolBar* toolBar)

Associates a toolbar with the frame.

See also

wxFrame::CreateToolBar, wxToolBar, wxFrame::GetToolBar

### wxFrame::SetTitle

virtual void SetTitle(const wxString& title)

Sets the frame title.

Parameters

title

The frame title.

See also

wxFrame::GetTitle

### wxFrame::ShowFullScreen

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:

- wxFULLSCREEN_NOMENUBAR
- wxFULLSCREEN_NOTOOLBAR
- wxFULLSCREEN_NOSTATUSBAR
- wxFULLSCREEN_NOBORDER
- wxFULLSCREEN_NOCAPTION
- wxFULLSCREEN_ALL (all of the above)

This function has not been tested with MDI frames.

See also

wxFrame::IsFullScreen