Download Source Code

CWin Class Reference

Wraps a HWND handle. More...

#include <Win.h>

Collaboration diagram for CWin:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual LRESULT OnCreate ()
 Called in response to WM_CREATE.
virtual BOOL OnCommand (WPARAM wParam, LPARAM lParam)
 Called in response to WM_COMMAND.
void Attach (HWND hWnd)
 Attaches to existing HWND.
void Detach ()
 Detaches from HWND without destroying the window.
virtual BOOL OnPaint (HDC hDC)
 Called in response to WM_PAINT message.
virtual BOOL OnEraseBkGnd (HDC hDC)
 Called in response to WM_ERASEBKGND message.
void AutoCenter (BOOL b)
 If auto center is enabled, window will center in screen when created.
void CenterOnParent (BOOL b)
 Enable to center window on parent when created.
void CenterWindow ()
 Call to center window properly.
virtual void DestroyWindow ()
 Called in response to WM_DESTROY.
void DefaultCREATESTRUCT ()
 Call to initialize CREATESTRUCT with default values.
BOOL GetUniqueString (LPSTR buf, DWORD max, LPCTSTR prefix=NULL)
 Generates a unique string.
void DefaultWNDCLASS ()
 Initializes WNDCLASS structure to default values.
BOOL RegisterClass ()
 Registers the window class.
BOOL Create (LPCTSTR pTitle)
 Creates the window.
 CWin ()
 Constructor.
 ~CWin ()
 Destructor.
HINSTANCE GetInstance ()
 Returns instance handle.
HWND GetSafeHwnd ()
 Returns window handle.
HWND GetParent ()
 Returns parent window handle.
BOOL IsWindow ()
 Returns non-zero if valid window handle.
BOOL IsWnd ()
 Returns non-zero if valid window handle.
BOOL ShowWindow (int nCmdShow=SW_SHOWNORMAL)
 Sets the windows show state.
BOOL UpdateWindow ()
 Sends a WM_PAINT message to window.
BOOL Invalidate ()
 Marks the window client area as invalid to invoke a redraw.
BOOL RedrawWindow (const RECT *pRect=NULL, HRGN hRgn=NULL, UINT uFlags=RDW_ERASE|RDW_INVALIDATE|RDW_ERASENOW|RDW_UPDATENOW|RDW_ALLCHILDREN)
 Redraws the window.
BOOL SetPos (HWND hWnd)
 Sets the windows position in the Z-Order.
BOOL SetPos (int x, int y)
 Sets the windows position.
BOOL SetWindowPos (HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags)
 Sets the window position.
void SetInstance (HINSTANCE hInst)
 Sets the instance handle.
BOOL SetForegroundWindow ()
 Sets this window as the foreground window.
virtual HDC BeginPaint ()
 Call in response to a WM_PAINT to validate window region.
ATOM GetRegisteredClassAtom ()
 Gets atom registered for class.
virtual LRESULT OnWindowProc (BOOL bSubclassing, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 Called in response to windows message.
void UnregisterClass ()
 Unregisters windows class.
void Quit (int nRet=0)
 Puts WM_QUIT message into Windows message queue.
virtual BOOL OnIdle (DWORD dwCalls)
 Called during idle periods.
BOOL DoMessagePump (HWND hWnd=NULL, HACCEL hAccel=NULL)
 Pumps messages from Windows message queue.
LRESULT CallWindowProc (UINT uMsg, WPARAM wParam, LPARAM lParam)
 Calls previous windows message handler function.
void Destroy ()
 Destroys window and releases resources.
BOOL UnhookHwnd ()
 Unhooks any subclassed window.
BOOL HookHwnd (HWND hWnd)
 Subclasses specified window.
virtual BOOL OnWMMessage (UINT uMsg, WPARAM wParam, LPARAM lParam)
 Called when WMMessage is received.

Static Public Member Functions

static void CenterWindow (HWND hWnd, HWND hParent=NULL, LPRECT pRect=NULL)
 Centers window.
static BOOL SetPos (HWND hWnd, int x, int y)
static BOOL PumpMessage (HWND hWnd=NULL, HACCEL hAccel=NULL)
 Pumps a single message from Windows message queue.
static BOOL PumpMessages (HWND hWnd=NULL, HACCEL hAccel=NULL)
 Pumps all messages from Windows message queue.

Public Attributes

WNDCLASS m_wc
 Window class information structure.
CREATESTRUCT m_cs
 Window create structure information.

Protected Attributes

HWND m_hWnd
 Window handle.

Detailed Description

Wraps a HWND handle.

Basic window encapsulation.


Member Function Documentation

void CWin::Attach HWND  hWnd  )  [inline]
 

Attaches to existing HWND.

Parameters:
[in] hWnd - Window handle

void CWin::AutoCenter BOOL  b  )  [inline]
 

If auto center is enabled, window will center in screen when created.

Parameters:
[in] b - Non-zero to enable auto center.

HDC CWin::BeginPaint  )  [virtual]
 

Call in response to a WM_PAINT to validate window region.

Returns:
DC handle that needs redrawing

LRESULT CWin::CallWindowProc UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam
 

Calls previous windows message handler function.

Parameters:
[in] uMsg - Message ID
[in] wParam - WPARAM
[in] lParam - LPARAM
Returns:
Windows return code
See also:

void CWin::CenterOnParent BOOL  b  )  [inline]
 

Enable to center window on parent when created.

Parameters:
[in] b - Non-zero to center on parent

void CWin::CenterWindow HWND  hWnd,
HWND  hParent = NULL,
LPRECT  pRect = NULL
[static]
 

Centers window.

Parameters:
[in] hWnd - Window handle to center
[in] hParent - Centers within specified window
[in] pRect - Centers within specified rect, ignored if hParent is not NULL
Call with either hParent, or pRect

Returns:
See also:

BOOL CWin::Create LPCTSTR  pTitle  ) 
 

Creates the window.

Parameters:
[in] pTitle - Window title
Returns:
Non-zero if window was created successfully

BOOL CWin::DoMessagePump HWND  hWnd = NULL,
HACCEL  hAccel = NULL
 

Pumps messages from Windows message queue.

Parameters:
[in] hWnd - Window handle to pump messages. Set to NULL to pump all messages.
[in] hAccel - Accelerator table for translating messages.
Returns:
Non-zero unless WM_QUIT was processed.
See also:

BOOL CWin::GetUniqueString LPSTR  buf,
DWORD  max,
LPCTSTR  prefix = NULL
 

Generates a unique string.

Parameters:
[out] buf - Receives unique string
[in] max - Size of buffer in buf
[in] prefix - Prefix for unique string
You may want to use CWin32::GuidToString() instead.

Returns:
Non-zero if success
See also:

BOOL CWin::HookHwnd HWND  hWnd  ) 
 

Subclasses specified window.

Parameters:
[in] hWnd - Handle to window to subclass
Returns:
Non-zero if success

BOOL CWin::Invalidate  )  [inline]
 

Marks the window client area as invalid to invoke a redraw.

Returns:
Non-zero if success

BOOL CWin::OnCommand WPARAM  wParam,
LPARAM  lParam
[virtual]
 

Called in response to WM_COMMAND.

Parameters:
[in] wParam 
[in] lParam 

BOOL CWin::OnEraseBkGnd HDC  hDC  )  [virtual]
 

Called in response to WM_ERASEBKGND message.

Parameters:
[in] hDC - Handle to window Device Context
Returns:
Non-zero unless you want default erase
See also:

BOOL CWin::OnIdle DWORD  dwCalls  )  [virtual]
 

Called during idle periods.

Parameters:
[in] dwCalls - Number of times called since message was received.
Returns:
Non-zero to get called again after checking for messages.
See also:

BOOL CWin::OnPaint HDC  hDC  )  [virtual]
 

Called in response to WM_PAINT message.

Parameters:
[in] hDC - Handle to Window Device Context

LRESULT CWin::OnWindowProc BOOL  bSubclassing,
HWND  hWnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam
[virtual]
 

Called in response to windows message.

Parameters:
[in] bSubclassing - Non-zero if subclassing
[in] hWnd - Window handle
[in] uMsg - Window message
[in] wParam - WPARAM
[in] lParam - LPARAM
Returns:
See also:

BOOL CWin::OnWMMessage UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam
[virtual]
 

Called when WMMessage is received.

Parameters:
[in] uMsg - Message ID
[in] wParam - WPARAM
[in] lParam - LPARAM
Returns:
Non-zero if success

BOOL CWin::PumpMessage HWND  hWnd = NULL,
HACCEL  hAccel = NULL
[static]
 

Pumps a single message from Windows message queue.

Parameters:
[in] hWnd - Window handle to pump messages. Set to NULL to pump all messages.
[in] hAccel - Accelerator table for translating messages.
Returns:
Non-zero unless WM_QUIT was processed.
See also:

BOOL CWin::PumpMessages HWND  hWnd = NULL,
HACCEL  hAccel = NULL
[static]
 

Pumps all messages from Windows message queue.

Parameters:
[in] hWnd - Window handle to pump messages. Set to NULL to pump all messages.
[in] hAccel - Accelerator table for translating messages.
Returns:
Non-zero unless WM_QUIT was processed.
See also:

BOOL CWin::RedrawWindow const RECT *  pRect = NULL,
HRGN  hRgn = NULL,
UINT  uFlags = RDW_ERASE | RDW_INVALIDATE | RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN
[inline]
 

Redraws the window.

Parameters:
[in] pRect - Area to redraw
[in] hRgn - Region to redraw
[in] uFlags - Redraw flags
Returns:
Non-zero if success
See also:

BOOL CWin::RegisterClass  ) 
 

Registers the window class.

Returns:
Non-zero if success

BOOL CWin::SetForegroundWindow  )  [inline]
 

Sets this window as the foreground window.

Returns:
Non-zero if success

void CWin::SetInstance HINSTANCE  hInst  )  [inline]
 

Sets the instance handle.

Parameters:
[in] hInst - Module instance handle

static BOOL CWin::SetPos HWND  hWnd,
int  x,
int  y
[inline, static]
 

Parameters:
[in] hWnd - Window handle
[in] x - Horizontal offset of upper left corner
[in] y - Vertical offset of upper left corner
Returns:
Non-zero if success
See also:

BOOL CWin::SetPos int  x,
int  y
[inline]
 

Sets the windows position.

Parameters:
[in] x - Horizontal offset of upper left corner
[in] y - Vertical offset of upper left corner
Returns:
Non-zero if success
See also:

BOOL CWin::SetPos HWND  hWnd  )  [inline]
 

Sets the windows position in the Z-Order.

Parameters:
[in] hWnd - Window handle to insert after
Returns:
Non-zero if success

BOOL CWin::SetWindowPos HWND  hWndInsertAfter,
int  x,
int  y,
int  cx,
int  cy,
UINT  uFlags
[inline]
 

Sets the window position.

Parameters:
[in] hWndInsertAfter - Window to inser after in Z-order.
[in] x - Horizontal offset of upper left corner.
[in] y - Vertical offset of upper left corner
[in] cx - Horizontal size
[in] cy - Vertical size
[in] uFlags - SetWindowPos() flags
Returns:
Non-zero if success
See also:

BOOL CWin::ShowWindow int  nCmdShow = SW_SHOWNORMAL  )  [inline]
 

Sets the windows show state.

Parameters:
nCmdShow - Show state
Returns:
Non-zero if success

BOOL CWin::UnhookHwnd  ) 
 

Unhooks any subclassed window.

Returns:
Non-zero if success

BOOL CWin::UpdateWindow  )  [inline]
 

Sends a WM_PAINT message to window.

Returns:
Non-zero if success


The documentation for this class was generated from the following files:
  • inc/Win.h
  • Win.cpp
Copyright Robert Umbehant
This documentation is covered by the LGPL