W32DLib
W32DLib::Window Class Reference

The base Window class. More...

#include <w32dlib/window.h>

Inheritance diagram for W32DLib::Window:
W32DLib::Control W32DLib::Dialog W32DLib::AutoCheck W32DLib::Button W32DLib::ComboBox W32DLib::RadioButton W32DLib::StaticText W32DLib::Text

Public Member Functions

 Window ()
 Constructor.
 
virtual ~Window ()
 Destructor.
 
bool HasMutex ()
 Whether the Window() constructor could create a mutex.
 
HWND GetHWND ()
 Returns the HWND for the window.
 
HMENU GetHMENU ()
 Returns the HMENU associated with this window.
 
bool SetHMENU (HMENU menu)
 Sets the HMENU associated with this window.
 
bool Move (int x, int y, int width, int height, bool repaint=true)
 Sets a Window's position and size.
 
bool MoveBase (Window *w, int x, int y, int width, int height, bool repaint=true)
 Sets a Window's position and size using Dialog base units.
 
LRESULT SendMsg (UINT msg, WPARAM wp, LPARAM lp)
 Send a message to the window.
 
void SetText (const TCHAR *text)
 Sets the window text.
 
void SetText (const W32String &text)
 Sets the window text.
 
W32String GetText ()
 Gets the window text.
 
void Enable (bool enable)
 Enables or disables the window.
 

Protected Member Functions

virtual BOOL InstanceProc (HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
 Handles windows messages.
 

Static Protected Member Functions

static BOOL CALLBACK WindowProc (HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
 The base WindProc.
 

Protected Attributes

HWND m_wnd
 The window handle for this window.
 

Detailed Description

The base Window class.

Constructor & Destructor Documentation

W32DLib::Window::Window ( )

Constructor.

virtual W32DLib::Window::~Window ( )
virtual

Destructor.

Member Function Documentation

void W32DLib::Window::Enable ( bool  enable)

Enables or disables the window.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

Parameters
enableSet true to enable, false to disable.
HMENU W32DLib::Window::GetHMENU ( )

Returns the HMENU associated with this window.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

HWND W32DLib::Window::GetHWND ( )

Returns the HWND for the window.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

W32String W32DLib::Window::GetText ( )

Gets the window text.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

Returns
The control's text
See Also
SetText()
bool W32DLib::Window::HasMutex ( )

Whether the Window() constructor could create a mutex.

Window will create a mutex when constructed to ensure that behaviour is correct if there are multiple threads in the application with their own windows (note that none of the classes are thread-safe in themselves – two threads cannot share a Window instance).

As I'm not overly fond of exceptions, this call means you can detect whether this worked or not if your program requires it. It also means that single-threaded applications aren't stopped by the failure to create a mutex.

Returns
True if this Window can be used safely in a thread.
virtual BOOL W32DLib::Window::InstanceProc ( HWND  wnd,
UINT  msg,
WPARAM  wp,
LPARAM  lp 
)
protectedvirtual

Handles windows messages.

If the window handles messages (like Dialog), then this must be overwridden so that Window::WindowProc will pass on the messages.

If the message has not been handled, or is WM_DESTROY, then the base version should be called.

Note that the reason it should be called for WM_DESTROY is so that the internal mapping of windows to Window class instances can be tidied up.

Parameters
wndThe window handle
msgThe message
wpAdditional parameters. Depends on the value of msg.
lpAdditional parameters. Depends on the value of msg.
Returns
TRUE if the message has been handled.

Reimplemented in W32DLib::Dialog.

bool W32DLib::Window::Move ( int  x,
int  y,
int  width,
int  height,
bool  repaint = true 
)

Sets a Window's position and size.

Parameters
xThe X Co-ord in pixels.
yThe Y Co-ord in pixels.
widthThe width in pixels.
heightThe height in pixels.
repaintCause a repaint of the window and exposed areas.
Returns
True if the call succeeds.
bool W32DLib::Window::MoveBase ( Window w,
int  x,
int  y,
int  width,
int  height,
bool  repaint = true 
)

Sets a Window's position and size using Dialog base units.

Parameters
wThe dialog.
xThe X Co-ord in dialog base units.
yThe Y Co-ord in dialog base units.
widthThe width in dialog base units.
heightThe height in dialog base units.
repaintCause a repaint of the window and exposed areas.
Returns
True if the call succeeds.
LRESULT W32DLib::Window::SendMsg ( UINT  msg,
WPARAM  wp,
LPARAM  lp 
)

Send a message to the window.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

Parameters
msgThe message to send.
wpThe WPARAM for that message type.
lpThe LPARAM for that message type.
Returns
The LRESULT from sending the message.
bool W32DLib::Window::SetHMENU ( HMENU  menu)

Sets the HMENU associated with this window.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

Parameters
menuThe menu to set.
Returns
True if the call succeeds.
void W32DLib::Window::SetText ( const TCHAR *  text)

Sets the window text.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

Parameters
textThe text
See Also
GetText()
void W32DLib::Window::SetText ( const W32String text)

Sets the window text.

This call will only work while the window is on display. The behaviour is undefined if it is called at any other time.

Parameters
textThe text
See Also
GetText()
static BOOL CALLBACK W32DLib::Window::WindowProc ( HWND  wnd,
UINT  msg,
WPARAM  wp,
LPARAM  lp 
)
staticprotected

The base WindProc.

This is the WindProc/DialogProc that should be used. Note that it expects a pointer to a Window in lp when called with WM_INITDIALOG or WM_CREATE.

Parameters
wndThe window handle
msgThe message
wpAdditional parameters. Depends on the value of msg.
lpAdditional parameters. Depends on the value of msg.
Returns
TRUE if the message has been handled.

Member Data Documentation

HWND W32DLib::Window::m_wnd
protected

The window handle for this window.

The base Window::InstanceProc will set this from the wnd parameter for WM_INITDIALOG or WM_CREATE.

Other derived classes should set the window as appropriate (for instance controls from GetDlgItem()).


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