Ocean
Ocean::Platform::Win::Window Class Reference

This class is the base class for all windows. More...

Inheritance diagram for Ocean::Platform::Win::Window:

Public Types

enum  MouseButton { BUTTON_NONE = 0 , BUTTON_LEFT = 1 , BUTTON_MIDDLE = 2 , BUTTON_RIGHT = 4 }
 Definition of several mouse buttons. More...
 
typedef std::vector< std::wstring > Files
 Definition of a vector holding files. More...
 

Public Member Functions

virtual bool initialize (const HICON icon=nullptr, const std::string &windowClass="window")
 Initializes the window. More...
 
bool initialize (const HINSTANCE applicationInstance, const int iconId, const std::string &windowClass="window")
 Initializes the window. More...
 
virtual void show ()
 Shows the window. More...
 
virtual void hide ()
 Hides the window. More...
 
virtual void update ()
 Updates the window. More...
 
virtual void repaint (const bool eraseBackground=false)
 Repaints the window. More...
 
bool move (const int x, const int y)
 Moves the window. More...
 
bool resize (const unsigned int width, const unsigned int height)
 Resizes the window. More...
 
HINSTANCE applicationInstance () const
 Returns the application instance the window belongs to. More...
 
const std::wstring & name () const
 Returns the name of this window. More...
 
HWND handle () const
 Returns the handle of this window. More...
 
HWND parentHandle () const
 Returns the handle of a possible parent window. More...
 
HDC dc () const
 Returns the device context of this window. More...
 
unsigned int width () const
 Returns the width of the entire window. More...
 
unsigned int height () const
 Returns the height of the window. More...
 
unsigned int clientWidth () const
 Returns the width of the client window. More...
 
unsigned int clientHeight () const
 Returns the height of the client window. More...
 
bool setParent (const HWND parent)
 Sets the parent window handle. More...
 
void setText (const std::wstring &text)
 Sets or changes the text of this windows. More...
 
void setEnableDropAndDrop (const bool state=true)
 Enables or disables drag&drop support for files. More...
 

Protected Types

typedef std::unordered_map< std::wstring, unsigned int > ClassMap
 Map mapping class names to an reference counter. More...
 

Protected Member Functions

 Window (HINSTANCE applicationInstance, const std::wstring &name, const HWND parent=nullptr, const bool isChild=false)
 Creates a new window. More...
 
virtual ~Window ()
 Destructs a window. More...
 
virtual bool registerWindowClass (const HICON icon=nullptr)
 Registers a new windows class for the application window. More...
 
virtual bool createWindow ()
 Creates the window itself using the registered window class. More...
 
virtual void modifyWindowClass (WNDCLASSW &windowClass)
 Allows the modification of the window class before registration. More...
 
virtual void modifyWindowStyle (DWORD &windowStyle, int &windowLeft, int &windowTop, int &windowWidth, int &windowHeight)
 Allows the modification of the window style before creation. More...
 
virtual void onInitialized ()
 Event function if the windows has been initialized successfully. More...
 
virtual void onActivate (const bool active)
 Event function for an activate event. More...
 
virtual void onPaint ()
 Event function to repaint the window. More...
 
virtual void onIdle ()
 Function called by the windows message loop if the process is idling. More...
 
virtual void onShow (const bool visible)
 Function for a show event. More...
 
virtual void onDestroy ()
 Function for a destroy event. More...
 
virtual void onResize (const unsigned int clientWidth, const unsigned int clientHeight)
 Function for window resize event. More...
 
virtual void onKeyDown (const int key)
 Function for keyboard button down events. More...
 
virtual void onMouseDoubleClick (const MouseButton button, const int x, const int y)
 Function for mouse double click events. More...
 
virtual void onMouseDown (const MouseButton button, const int x, const int y)
 Function for mouse button down events. More...
 
virtual void onMouseMove (const MouseButton buttons, const int x, const int y)
 Function for mouse move event. More...
 
virtual void onKeyUp (const int key)
 Function for keyboard button up events. More...
 
virtual void onMouseUp (const MouseButton button, const int x, const int y)
 Function for mouse button up events. More...
 
virtual void onMouseWheel (const MouseButton buttons, const int wheel, const int x, const int y)
 Functions for mouse wheel events. More...
 
virtual void onMinimize ()
 Functions for window minimize event. More...
 
virtual void onDragAndDrop (const Files &files)
 Event functions for drag&drop events for files. More...
 

Static Protected Member Functions

static LRESULT CALLBACK windowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 Window message / event procedure. More...
 
static ClassMapclassMap ()
 Returns the class map for all windows. More...
 
static LockclassMapLock ()
 Returns the lock of the window class map. More...
 

Protected Attributes

HWND parentHandle_ = nullptr
 Window handle of a possible parent window, making this window to a child window. More...
 
std::wstring className_
 Window class name. More...
 
HINSTANCE applicationInstance_ = nullptr
 Application instance. More...
 
std::wstring name_
 Name of the window. More...
 
HWND handle_ = nullptr
 Window handle. More...
 
HDC dc_ = nullptr
 Window device context. More...
 
bool isChild_ = false
 True, if the window is a child window. More...
 

Detailed Description

This class is the base class for all windows.

Member Typedef Documentation

◆ ClassMap

typedef std::unordered_map<std::wstring, unsigned int> Ocean::Platform::Win::Window::ClassMap
protected

Map mapping class names to an reference counter.

◆ Files

typedef std::vector<std::wstring> Ocean::Platform::Win::Window::Files

Definition of a vector holding files.

Member Enumeration Documentation

◆ MouseButton

Definition of several mouse buttons.

Enumerator
BUTTON_NONE 

No mouse button.

BUTTON_LEFT 

Left mouse button.

BUTTON_MIDDLE 

Middle mouse button.

BUTTON_RIGHT 

Right mouse button.

Constructor & Destructor Documentation

◆ Window()

Ocean::Platform::Win::Window::Window ( HINSTANCE  applicationInstance,
const std::wstring &  name,
const HWND  parent = nullptr,
const bool  isChild = false 
)
protected

Creates a new window.

Beware: If a derived window class will use a different window class as the default one you have to change the window class name in the constructor.

Parameters
applicationInstanceThe instance of the application, must be valid
nameThe name of the application window
parentPossible parent window making this window to a child window
isChildTrue, if the window is intended to be a child window

◆ ~Window()

virtual Ocean::Platform::Win::Window::~Window ( )
protectedvirtual

Destructs a window.

Member Function Documentation

◆ applicationInstance()

HINSTANCE Ocean::Platform::Win::Window::applicationInstance ( ) const
inline

Returns the application instance the window belongs to.

Returns
Application instance

◆ classMap()

static ClassMap& Ocean::Platform::Win::Window::classMap ( )
staticprotected

Returns the class map for all windows.

Returns
The window class map

◆ classMapLock()

static Lock& Ocean::Platform::Win::Window::classMapLock ( )
staticprotected

Returns the lock of the window class map.

Returns
The window class map's lock

◆ clientHeight()

unsigned int Ocean::Platform::Win::Window::clientHeight ( ) const

Returns the height of the client window.

Returns
Height in pixel

◆ clientWidth()

unsigned int Ocean::Platform::Win::Window::clientWidth ( ) const

Returns the width of the client window.

Returns
Width in pixel

◆ createWindow()

virtual bool Ocean::Platform::Win::Window::createWindow ( )
protectedvirtual

Creates the window itself using the registered window class.

Returns
True, if succeeded

Reimplemented in Ocean::Platform::Win::TextWindow.

◆ dc()

HDC Ocean::Platform::Win::Window::dc ( ) const
inline

Returns the device context of this window.

Returns
Device context

◆ handle()

HWND Ocean::Platform::Win::Window::handle ( ) const
inline

Returns the handle of this window.

Returns
Window handle

◆ height()

unsigned int Ocean::Platform::Win::Window::height ( ) const

Returns the height of the window.

Returns
Height in pixel

◆ hide()

virtual void Ocean::Platform::Win::Window::hide ( )
virtual

Hides the window.

◆ initialize() [1/2]

virtual bool Ocean::Platform::Win::Window::initialize ( const HICON  icon = nullptr,
const std::string &  windowClass = "window" 
)
virtual

Initializes the window.

Parameters
iconThe optional handle of the icon to be used, nullptr to use default icon
windowClassThe name of the window class
Returns
True, if succeeded

◆ initialize() [2/2]

bool Ocean::Platform::Win::Window::initialize ( const HINSTANCE  applicationInstance,
const int  iconId,
const std::string &  windowClass = "window" 
)
inline

Initializes the window.

Parameters
applicationInstanceThe instance of the application, must be valid
iconIdThe id of the icon as specified in the resources, with range [0, infinity)
windowClassThe name of the window class
Returns
True, if succeeded

◆ modifyWindowClass()

virtual void Ocean::Platform::Win::Window::modifyWindowClass ( WNDCLASSW &  windowClass)
protectedvirtual

Allows the modification of the window class before registration.


Overload this function to change the window type.
However do not change the class name.

Parameters
windowClassWindow class to modify

Reimplemented in Ocean::Platform::Win::BitmapWindow.

◆ modifyWindowStyle()

virtual void Ocean::Platform::Win::Window::modifyWindowStyle ( DWORD &  windowStyle,
int &  windowLeft,
int &  windowTop,
int &  windowWidth,
int &  windowHeight 
)
protectedvirtual

Allows the modification of the window style before creation.


Overload this function to change the window style.

Parameters
windowStyleWindow style to modify
windowLeftLeft position of the window
windowTopTop position of the window
windowWidthWidth of the window
windowHeightHeight of the window

◆ move()

bool Ocean::Platform::Win::Window::move ( const int  x,
const int  y 
)

Moves the window.

Parameters
xThe new horizontal position
yThe new vertical position

◆ name()

const std::wstring & Ocean::Platform::Win::Window::name ( ) const
inline

Returns the name of this window.

Returns
Window name

◆ onActivate()

virtual void Ocean::Platform::Win::Window::onActivate ( const bool  active)
protectedvirtual

Event function for an activate event.

Parameters
activeTrue, if the window is activated, false if the window is inactivated

◆ onDestroy()

virtual void Ocean::Platform::Win::Window::onDestroy ( )
protectedvirtual

Function for a destroy event.

Reimplemented in Ocean::Platform::Win::ApplicationWindow.

◆ onDragAndDrop()

virtual void Ocean::Platform::Win::Window::onDragAndDrop ( const Files files)
protectedvirtual

Event functions for drag&drop events for files.

Parameters
filesThe files which have been dropped
See also
setEnableDropAndDrop().

◆ onIdle()

virtual void Ocean::Platform::Win::Window::onIdle ( )
protectedvirtual

Function called by the windows message loop if the process is idling.

◆ onInitialized()

virtual void Ocean::Platform::Win::Window::onInitialized ( )
protectedvirtual

Event function if the windows has been initialized successfully.

Reimplemented in Ocean::Platform::GL::Win::WindowContext.

◆ onKeyDown()

virtual void Ocean::Platform::Win::Window::onKeyDown ( const int  key)
protectedvirtual

Function for keyboard button down events.

Parameters
keySpecifies the key button

◆ onKeyUp()

virtual void Ocean::Platform::Win::Window::onKeyUp ( const int  key)
protectedvirtual

Function for keyboard button up events.

Parameters
keySpecifies the key button

◆ onMinimize()

virtual void Ocean::Platform::Win::Window::onMinimize ( )
protectedvirtual

Functions for window minimize event.

◆ onMouseDoubleClick()

virtual void Ocean::Platform::Win::Window::onMouseDoubleClick ( const MouseButton  button,
const int  x,
const int  y 
)
protectedvirtual

Function for mouse double click events.

Parameters
buttonSpecifies the mouse button
xSpecifies the x position of the cursor
ySpecifies the y position of the cursor

Reimplemented in Ocean::Platform::Win::BitmapWindow.

◆ onMouseDown()

virtual void Ocean::Platform::Win::Window::onMouseDown ( const MouseButton  button,
const int  x,
const int  y 
)
protectedvirtual

Function for mouse button down events.

Parameters
buttonSpecifies the mouse button
xSpecifies the x position of the cursor
ySpecifies the y position of the cursor

◆ onMouseMove()

virtual void Ocean::Platform::Win::Window::onMouseMove ( const MouseButton  buttons,
const int  x,
const int  y 
)
protectedvirtual

Function for mouse move event.

Parameters
buttonsHolds all pushed mouse buttons
xSpecifies the x position of the cursor
ySpecifies the y position of the cursor

◆ onMouseUp()

virtual void Ocean::Platform::Win::Window::onMouseUp ( const MouseButton  button,
const int  x,
const int  y 
)
protectedvirtual

Function for mouse button up events.

Parameters
buttonSpecifies the mouse button
xSpecifies the x position of the cursor
ySpecifies the y position of the cursor

◆ onMouseWheel()

virtual void Ocean::Platform::Win::Window::onMouseWheel ( const MouseButton  buttons,
const int  wheel,
const int  x,
const int  y 
)
protectedvirtual

Functions for mouse wheel events.

Parameters
buttonsHolds all pushed mouse buttons
wheelSpecifies the wheel delta value
xSpecifies the x position of the cursor
ySpecifies the y position of the cursor

◆ onPaint()

virtual void Ocean::Platform::Win::Window::onPaint ( )
protectedvirtual

Event function to repaint the window.

Reimplemented in Ocean::Platform::Win::BitmapWindow.

◆ onResize()

virtual void Ocean::Platform::Win::Window::onResize ( const unsigned int  clientWidth,
const unsigned int  clientHeight 
)
protectedvirtual

Function for window resize event.

Parameters
clientWidthNew client width
clientHeightNew client height

Reimplemented in Ocean::Platform::Win::BitmapWindow.

◆ onShow()

virtual void Ocean::Platform::Win::Window::onShow ( const bool  visible)
protectedvirtual

Function for a show event.

Parameters
visibleTrue, if the window is being shown, false if the window is being hidden

◆ parentHandle()

HWND Ocean::Platform::Win::Window::parentHandle ( ) const
inline

Returns the handle of a possible parent window.

Returns
Parent window handle, nullptr otherwise

◆ registerWindowClass()

virtual bool Ocean::Platform::Win::Window::registerWindowClass ( const HICON  icon = nullptr)
protectedvirtual

Registers a new windows class for the application window.

Parameters
iconThe optional handle of the icon to be used, nullptr to use default icon
Returns
True, if succeeded

◆ repaint()

virtual void Ocean::Platform::Win::Window::repaint ( const bool  eraseBackground = false)
virtual

Repaints the window.

Parameters
eraseBackgroundTrue, to erase the background

◆ resize()

bool Ocean::Platform::Win::Window::resize ( const unsigned int  width,
const unsigned int  height 
)

Resizes the window.

Parameters
widthNew window width
heightNew window height
Returns
True, if succeeded

◆ setEnableDropAndDrop()

void Ocean::Platform::Win::Window::setEnableDropAndDrop ( const bool  state = true)

Enables or disables drag&drop support for files.

Parameters
stateTrue, to enable support for drag&drop of file for this window; False, to disable drag&drop.
See also
onDragAndDrop().

◆ setParent()

bool Ocean::Platform::Win::Window::setParent ( const HWND  parent)

Sets the parent window handle.

Returns
True, if succeeded

◆ setText()

void Ocean::Platform::Win::Window::setText ( const std::wstring &  text)

Sets or changes the text of this windows.

Parameters
textThe text to be set

◆ show()

virtual void Ocean::Platform::Win::Window::show ( )
virtual

Shows the window.

◆ update()

virtual void Ocean::Platform::Win::Window::update ( )
virtual

Updates the window.

◆ width()

unsigned int Ocean::Platform::Win::Window::width ( ) const

Returns the width of the entire window.

Returns
Width in pixel

◆ windowProc()

static LRESULT CALLBACK Ocean::Platform::Win::Window::windowProc ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
staticprotected

Window message / event procedure.

Parameters
hwndWindow handle
uMsgMessage id
wParamHigh message parameter
lParamLow message parameter

Field Documentation

◆ applicationInstance_

HINSTANCE Ocean::Platform::Win::Window::applicationInstance_ = nullptr
protected

Application instance.

◆ className_

std::wstring Ocean::Platform::Win::Window::className_
protected

Window class name.

◆ dc_

HDC Ocean::Platform::Win::Window::dc_ = nullptr
protected

Window device context.

◆ handle_

HWND Ocean::Platform::Win::Window::handle_ = nullptr
protected

Window handle.

◆ isChild_

bool Ocean::Platform::Win::Window::isChild_ = false
protected

True, if the window is a child window.

◆ name_

std::wstring Ocean::Platform::Win::Window::name_
protected

Name of the window.

◆ parentHandle_

HWND Ocean::Platform::Win::Window::parentHandle_ = nullptr
protected

Window handle of a possible parent window, making this window to a child window.


The documentation for this class was generated from the following file: