Rediger

Del via


CWindow Class

This class provides methods for manipulating a window.

Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

Syntax

class CWindow

Members

Public Constructors

Name Description
CWindow::CWindow Constructor.

Public Methods

Name Description
CWindow::ArrangeIconicWindows Arranges all minimized child windows.
CWindow::Attach Attaches a window to the CWindow object.
CWindow::BeginPaint Prepares the window for painting.
CWindow::BringWindowToTop Brings the window to the top of the Z order.
CWindow::CenterWindow Centers the window against a given window.
CWindow::ChangeClipboardChain Removes the window from the chain of Clipboard viewers.
CWindow::CheckDlgButton Changes the check state of the specified button.
CWindow::CheckRadioButton Checks the specified radio button.
CWindow::ChildWindowFromPoint Retrieves the child window containing the specified point.
CWindow::ChildWindowFromPointEx Retrieves a particular type of child window containing the specified point.
CWindow::ClientToScreen Converts client coordinates to screen coordinates.
CWindow::Create Creates a window.
CWindow::CreateCaret Creates a new shape for the system caret.
CWindow::CreateGrayCaret Creates a gray rectangle for the system caret.
CWindow::CreateSolidCaret Creates a solid rectangle for the system caret.
CWindow::DeferWindowPos Updates the specified multiple-window-position structure for the specified window.
CWindow::DestroyWindow Destroys the window associated with the CWindow object.
CWindow::Detach Detaches the window from the CWindow object.
CWindow::DlgDirList Fills a list box with the names of all files matching a specified path or file name.
CWindow::DlgDirListComboBox Fills a combo box with the names of all files matching a specified path or file name.
CWindow::DlgDirSelect Retrieves the current selection from a list box.
CWindow::DlgDirSelectComboBox Retrieves the current selection from a combo box.
CWindow::DragAcceptFiles Registers whether the window accepts dragged files.
CWindow::DrawMenuBar Redraws the window's menu bar.
CWindow::EnableScrollBar Enables or disables the scroll bar arrows.
CWindow::EnableWindow Enables or disables input.
CWindow::EndPaint Marks the end of painting.
CWindow::FlashWindow Flashes the window once.
CWindow::GetClientRect Retrieves the coordinates of the client area.
CWindow::GetDC Retrieves a device context for the client area.
CWindow::GetDCEx Retrieves a device context for the client area and allows clipping options.
CWindow::GetDescendantWindow Retrieves the specified descendant window.
CWindow::GetDlgControl Retrieves an interface on the specified control.
CWindow::GetDlgCtrlID Retrieves the window's identifier (for child windows only).
CWindow::GetDlgHost Retrieves a pointer to an interface to the ATL Control hosting container.
CWindow::GetDlgItem Retrieves the specified child window.
CWindow::GetDlgItemInt Translates a control's text to an integer.
CWindow::GetDlgItemText Retrieves a control's text.
CWindow::GetExStyle Retrieves the extended window styles.
CWindow::GetFont Retrieves the window's current font.
CWindow::GetHotKey Determines the hot key associated with the window.
CWindow::GetIcon Retrieves the window's large or small icon.
CWindow::GetLastActivePopup Retrieves the most recently active pop-up window.
CWindow::GetMenu Retrieves the window's menu.
CWindow::GetNextDlgGroupItem Retrieves the previous or next control within a group of controls.
CWindow::GetNextDlgTabItem Retrieves the previous or next control having the WS_TABSTOP style.
CWindow::GetParent Retrieves the immediate parent window.
CWindow::GetScrollInfo Retrieves the parameters of a scroll bar.
CWindow::GetScrollPos Retrieves the position of the scroll box.
CWindow::GetScrollRange Retrieves the scroll bar range.
CWindow::GetStyle Retrieves the window styles.
CWindow::GetSystemMenu Creates a copy of the system menu for modification.
CWindow::GetTopLevelParent Retrieves the top-level parent or owner window.
CWindow::GetTopLevelWindow Retrieves the top-level owner window.
CWindow::GetTopWindow Retrieves the top-level child window.
CWindow::GetUpdateRect Retrieves the coordinates of the smallest rectangle that completely encloses the update region.
CWindow::GetUpdateRgn Retrieves the update region and copies it into a specified region.
CWindow::GetWindow Retrieves the specified window.
CWindow::GetWindowContextHelpId Retrieves the window's help context identifier.
CWindow::GetWindowDC Retrieves a device context for the entire window.
CWindow::GetWindowLong Retrieves a 32-bit value at a specified offset into the extra window memory.
CWindow::GetWindowLongPtr Retrieves information about the specified window, including a value at a specified offset into the extra window memory.
CWindow::GetWindowPlacement Retrieves the show state and positions.
CWindow::GetWindowProcessID Retrieves the identifier of the process that created the window.
CWindow::GetWindowRect Retrieves the window's bounding dimensions.
CWindow::GetWindowRgn Obtains a copy of the window region of a window.
CWindow::GetWindowText Retrieves the window's text.
CWindow::GetWindowTextLength Retrieves the length of the window's text.
CWindow::GetWindowThreadID Retrieves the identifier of the thread that created the specified window.
CWindow::GetWindowWord Retrieves a 16-bit value at a specified offset into the extra window memory.
CWindow::GotoDlgCtrl Sets the keyboard focus to a control in the dialog box.
CWindow::HideCaret Hides the system caret.
CWindow::HiliteMenuItem Highlights or removes the highlight from a top-level menu item.
CWindow::Invalidate Invalidates the entire client area.
CWindow::InvalidateRect Invalidates the client area within the specified rectangle.
CWindow::InvalidateRgn Invalidates the client area within the specified region.
CWindow::IsChild Determines whether the specified window is a child window.
CWindow::IsDialogMessage Determines whether a message is intended for the specified dialog box.
CWindow::IsDlgButtonChecked Determines the check state of the button.
CWindow::IsIconic Determines whether the window is minimized.
CWindow::IsParentDialog Determines if the parent window of a control is a dialog window.
CWindow::IsWindow Determines whether the specified window handle identifies an existing window.
CWindow::IsWindowEnabled Determines whether the window is enabled for input.
CWindow::IsWindowUnicode Determines whether the specified window is a native Unicode window.
CWindow::IsWindowVisible Determines the window's visibility state.
CWindow::IsZoomed Determines whether the window is maximized.
CWindow::KillTimer Destroys a timer event.
CWindow::LockWindowUpdate Disables or enables drawing in the window.
CWindow::MapWindowPoints Converts a set of points from the window's coordinate space to the coordinate space of another window.
CWindow::MessageBox Displays a message box.
CWindow::ModifyStyle Modifies the window styles.
CWindow::ModifyStyleEx Modifies the extended window styles.
CWindow::MoveWindow Changes the window's size and position.
CWindow::NextDlgCtrl Sets the keyboard focus to the next control in the dialog box.
CWindow::OpenClipboard Opens the Clipboard.
CWindow::PostMessage Places a message in the message queue associated with the thread that created the window. Returns without waiting for the thread to process the message.
CWindow::PrevDlgCtrl Sets the keyboard focus to the previous control in the dialog box.
CWindow::Print Requests that the window be drawn in a specified device context.
CWindow::PrintClient Requests that the window's client area be drawn in a specified device context.
CWindow::RedrawWindow Updates a specified rectangle or region in the client area.
CWindow::ReleaseDC Releases a device context.
CWindow::ResizeClient Resizes the window.
CWindow::ScreenToClient Converts screen coordinates to client coordinates.
CWindow::ScrollWindow Scrolls the specified client area.
CWindow::ScrollWindowEx Scrolls the specified client area with additional features.
CWindow::SendDlgItemMessage Sends a message to a control.
CWindow::SendMessage Sends a message to the window and doesn't return until the window procedure has processed the message.
CWindow::SendMessageToDescendants Sends a message to the specified descendant windows.
CWindow::SendNotifyMessage Sends a message to the window. If the window was created by the calling thread, SendNotifyMessage doesn't return until the window procedure has processed the message. Otherwise, it returns immediately.
CWindow::SetActiveWindow Activates the window.
CWindow::SetCapture Sends all subsequent mouse input to the window.
CWindow::SetClipboardViewer Adds the window to the Clipboard viewer chain.
CWindow::SetDlgCtrlID Changes the window's identifier.
CWindow::SetDlgItemInt Changes a control's text to the string representation of an integer value.
CWindow::SetDlgItemText Changes a control's text.
CWindow::SetFocus Sets the input focus to the window.
CWindow::SetFont Changes the window's current font.
CWindow::SetHotKey Associates a hot key with the window.
CWindow::SetIcon Changes the window's large or small icon.
CWindow::SetMenu Changes the window's current menu.
CWindow::SetParent Changes the parent window.
CWindow::SetRedraw Sets or clears the redraw flag.
CWindow::SetScrollInfo Sets the parameters of a scroll bar.
CWindow::SetScrollPos Changes the position of the scroll box.
CWindow::SetScrollRange Changes the scroll bar range.
CWindow::SetTimer Creates a timer event.
CWindow::SetWindowContextHelpId Sets the window's help context identifier.
CWindow::SetWindowLong Sets a 32-bit value at a specified offset into the extra window memory.
CWindow::SetWindowLongPtr Changes an attribute of the specified window, and also sets a value at the specified offset in the extra window memory.
CWindow::SetWindowPlacement Sets the show state and positions.
CWindow::SetWindowPos Sets the size, position, and Z order.
CWindow::SetWindowRgn Sets the window region of a window.
CWindow::SetWindowText Changes the window's text.
CWindow::SetWindowWord Sets a 16-bit value at a specified offset into the extra window memory.
CWindow::ShowCaret Displays the system caret.
CWindow::ShowOwnedPopups Shows or hides the pop-up windows owned by the window.
CWindow::ShowScrollBar Shows or hides a scroll bar.
CWindow::ShowWindow Sets the window's show state.
CWindow::ShowWindowAsync Sets the show state of a window created by a different thread.
CWindow::UpdateWindow Updates the client area.
CWindow::ValidateRect Validates the client area within the specified rectangle.
CWindow::ValidateRgn Validates the client area within the specified region.
CWindow::WinHelp Starts Windows Help.

Public Operators

Name Description
CWindow::operator HWND Converts the CWindow object to an HWND.
CWindow::operator = Assigns an HWND to the CWindow object.

Public Data Members

Name Description
CWindow::m_hWnd The handle to the window associated with the CWindow object.
CWindow::rcDefault Contains default window dimensions.

Remarks

CWindow provides the base functionality for manipulating a window in ATL. Many of the CWindow methods simply wrap one of the Win32 API functions. For example, compare the prototypes for CWindow::ShowWindow and ShowWindow:

CWindow method Win32 function
BOOL ShowWindow( int nCmdShow ); BOOL ShowWindow( HWND hWnd , int nCmdShow );

CWindow::ShowWindow calls the Win32 function ShowWindow by passing CWindow::m_hWnd as the first parameter. Every CWindow method that directly wraps a Win32 function passes the m_hWnd member; therefore, much of the CWindow documentation will refer you to the Windows SDK.

Note

Not every window-related Win32 function is wrapped by CWindow, and not every CWindow method wraps a Win32 function.

CWindow::m_hWnd stores the HWND that identifies a window. An HWND is attached to your object when you:

  • Specify an HWND in CWindow's constructor.

  • Call CWindow::Attach.

  • Use CWindow's operator =.

  • Create or subclass a window using one of the following classes derived from CWindow:

CWindowImpl Allows you to create a new window or subclass an existing window.

CContainedWindow Implements a window contained within another object. You can create a new window or subclass an existing window.

CDialogImpl Allows you to create a modal or modeless dialog box.

For more information about windows, see Windows and subsequent topics in the Windows SDK. For more information about using windows in ATL, see the article ATL Window Classes.

Requirements

Header: atlwin.h

CWindow::ArrangeIconicWindows

Arranges all minimized child windows.

UINT ArrangeIconicWindows() throw();

Remarks

See ArrangeIconicWindows in the Windows SDK.

CWindow::Attach

Attaches the window identified by hWndNew to the CWindow object.

void Attach(HWND hWndNew) throw();

Parameters

hWndNew
[in] The handle to a window.

Example

//The following example attaches an HWND to the CWindow object
HWND hWnd  = ::GetDesktopWindow();
CWindow myWindow;
myWindow.Attach(hWnd);

CWindow::BeginPaint

Prepares the window for painting.

HDC BeginPaint(LPPAINTSTRUCT lpPaint) throw();

Remarks

See BeginPaint in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object
//and calls CWindow::BeginPaint() and CWindow::EndPaint() in the 
// WM_PAINT handler of a CWindowImpl-derived class
LRESULT CMyCtrl::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, 
   BOOL& /*bHandled*/)
{
   CWindow myWindow;
   myWindow.Attach(m_hWnd);
   PAINTSTRUCT ps;
   HDC hDC  = myWindow.BeginPaint(&ps);
   //Use the hDC as much as you want
   ::Rectangle(hDC, 0, 0, 50, 50);

   myWindow.EndPaint(&ps);

   return 0;
}

CWindow::BringWindowToTop

Brings the window to the top of the Z order.

BOOL BringWindowToTop() throw();

Remarks

See BringWindowToTop in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::BringWindowToTop() to bring the window to the top 
//of the z-order.

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bOnTop = myWindow.BringWindowToTop();

//check if we could bring the window on top
if(bOnTop)
{
   //Do something
}

CWindow::CenterWindow

Centers the window against a given window.

BOOL CenterWindow(HWND hWndCenter = NULL) throw();

Parameters

hWndCenter
[in] The handle to the window against which to center. If this parameter is NULL (the default value), the method will set hWndCenter to the window's parent window if it's a child window. Otherwise, it will set hWndCenter to the window's owner window.

Return Value

TRUE if the window is successfully centered; otherwise, FALSE.

Example

//The following example attaches various HWNDs to the CWindow objects 
//and calls CWindow::CenterWindow() for each of them

CWindow childWindow, popupWindow, overlappedWindow;

childWindow.Attach(hWndChild); //a window created with WS_CHILD style
childWindow.CenterWindow();    //This will center the child 
                               //window against its Parent window

popupWindow.Attach(hWndPopup); //a window created with WS_POPUP style
popupWindow.CenterWindow();    //This will center the popup window 
                               //against its Owner window

overlappedWindow.Attach(hWndOverlapped); //a window created with 
                                         //WS_OVERLAPPED style
overlappedWindow.CenterWindow(::GetDesktopWindow()); //This will center 
                       //the overlapped window against the DeskTop window

CWindow::ChangeClipboardChain

Removes the window from the chain of Clipboard viewers.

BOOL ChangeClipboardChain(HWND hWndNewNext) throw();

Remarks

See ChangeClipboardChain in the Windows SDK.

CWindow::CheckDlgButton

Changes the check state of the specified button.

BOOL CheckDlgButton(int nIDButton, UINT nCheck) throw();

Remarks

See CheckDlgButton in the Windows SDK.

CWindow::CheckRadioButton

Checks the specified radio button.

BOOL CheckRadioButton(
    int nIDFirstButton,
    int nIDLastButton,
    int nIDCheckButton) throw();

Remarks

See CheckRadioButton in the Windows SDK.

CWindow::ChildWindowFromPoint

Retrieves the child window containing the specified point.

HWND ChildWindowFromPoint(POINT point) const throw();

Remarks

See ChildWindowFromPoint in the Windows SDK.

CWindow::ChildWindowFromPointEx

Retrieves a particular type of child window containing the specified point.

HWND ChildWindowFromPoint(POINT point, UINT uFlags) const throw();

Remarks

See ChildWindowFromPointEx in the Windows SDK.

CWindow::ClientToScreen

Converts client coordinates to screen coordinates.

BOOL ClientToScreen(LPPOINT lpPoint) const throw();
BOOL ClientToScreen(LPRECT lpRect) const throw();

Remarks

See ClientToScreen in the Windows SDK.

The second version of this method allows you to convert the coordinates of a RECT structure.

CWindow::Create

Creates a window.

HWND Create(
    LPCTSTR lpstrWndClass,
    HWND hWndParent,
    _U_RECT rect = NULL,
    LPCTSTR szWindowName = NULL,
    DWORD dwStyle = 0,
    DWORD dwExStyle = 0,
    _U_MENUorID MenuOrID = 0U,
    LPVOID lpCreateParam = NULL) throw();

Parameters

lpstrWndClass
[in] A pointer to the window's class.

hWndParent
[in] The handle to the parent or owner window.

rect
[in] A variable of type _U_RECT specifying the position of the window. The default value is NULL. When this parameter is NULL, the value of CWindow::rcDefault is used.

szWindowName
[in] Specifies the name of the window. The default value is NULL.

dwStyle
[in] The style of the window. The default value is 0, meaning no style is specified. For a list of possible values, see CreateWindow in the Windows SDK.

dwExStyle
[in] The extended window style. The default value is 0, meaning no extended style is specified. For a list of possible values, see CreateWindowEx in the Windows SDK.

MenuOrID
[in] A variable of type _U_MENUorID specifying a handle to a menu or a window identifier. The default value is 0U.

lpCreateParam
A pointer to the window-creation data contained in a CREATESTRUCT structure.

Return Value

If successful, the handle to the newly created window, specified by m_hWnd. Otherwise, NULL.

Remarks

CWindow::rcDefault is defined as __declspec(selectany) RECT CWindow::rcDefault = {CW_USEDEFAULT, CW_USEDEFAULT, 0, 0};.

See CreateWindow in the Windows SDK for more information.

Note If 0 is used as the value for the MenuOrID parameter, it must be specified as 0U (the default value) to avoid a compiler error.

CWindow::CreateCaret

Creates a new shape for the system caret.

BOOL CreateCaret(HBITMAP pBitmap) throw();

Remarks

See CreateCaret in the Windows SDK.

CWindow::CreateGrayCaret

Creates a gray rectangle for the system caret.

BOOL CreateGrayCaret(int nWidth, int nHeight) throw();

Remarks

See CreateCaret in the Windows SDK.

Passes (HBITMAP) 1 for the bitmap handle parameter to the Win32 function.

CWindow::CreateSolidCaret

Creates a solid rectangle for the system caret.

BOOL CreateSolidCaret(int nWidth, int nHeight) throw();

Remarks

See CreateCaret in the Windows SDK.

Passes (HBITMAP) 0 for the bitmap handle parameter to the Win32 function.

CWindow::CWindow

The constructor.

CWindow(HWND hWnd = NULL) throw();

Parameters

hWnd
[in] The handle to a window.

Remarks

Initializes the m_hWnd member to hWnd, which by default is NULL.

Note

CWindow::CWindow does not create a window. Classes CWindowImpl, CContainedWindow, and CDialogImpl (all of which derive from CWindow) provide a method to create a window or dialog box, which is then assigned to CWindow::m_hWnd. You can also use the CreateWindow Win32 function.

CWindow::DeferWindowPos

Updates the specified multiple-window-position structure for the specified window.

HDWP DeferWindowPos(
    HDWP hWinPosInfo,
    HWND hWndInsertAfter,
    int x,
    int y,
    int cx,
    int cy,
    UINT uFlags) throw();

Remarks

See DeferWindowPos in the Windows SDK.

CWindow::DestroyWindow

Destroys the window associated with the CWindow object and sets m_hWnd to NULL.

BOOL DestroyWindow() throw();

Remarks

See DestroyWindow in the Windows SDK.

It doesn't destroy the CWindow object itself.

Example

  //The following example attaches an HWND to the CWindow object and 
  //calls CWindow::DestroyWindow() to destroy the window

  CWindow myWindow;
  myWindow.Attach(hWndChild);
  //call the CWindow wrappers

  myWindow.DestroyWindow();
  hWndChild = NULL;

CWindow::Detach

Detaches m_hWnd from the CWindow object and sets m_hWnd to NULL.

HWND Detach() throw();

Return Value

The HWND associated with the CWindow object.

Example

//The following example attaches an HWND to the CWindow object and 
//later detaches the CWindow object from the HWND when no longer needed

CWindow myWindow;
myWindow.Attach(hWnd);

//call CWindow wrappers

//We don't need the C++ object any more, so detach it from the HWND.
myWindow.Detach(); 

CWindow::DlgDirList

Fills a list box with the names of all files matching a specified path or file name.

int DlgDirList(
    LPTSTR lpPathSpec,
    int nIDListBox,
    int nIDStaticPath,
    UINT nFileType) throw();

Remarks

See DlgDirList in the Windows SDK.

CWindow::DlgDirListComboBox

Fills a combo box with the names of all files matching a specified path or file name.

int DlgDirListComboBox(
    LPTSTR lpPathSpec,
    int nIDComboBox,
    int nIDStaticPath,
    UINT nFileType) throw();

Remarks

See DlgDirListComboBox in the Windows SDK.

CWindow::DlgDirSelect

Retrieves the current selection from a list box.

BOOL DlgDirSelect(
    LPTSTR lpString,
    int nCount,
    int nIDListBox) throw();

Remarks

See DlgDirSelectEx in the Windows SDK.

CWindow::DlgDirSelectComboBox

Retrieves the current selection from a combo box.

BOOL DlgDirSelectComboBox(
    LPTSTR lpString,
    int nCount,
    int nIDComboBox) throw();

Remarks

See DlgDirSelectComboBoxEx in the Windows SDK.

CWindow::DragAcceptFiles

Registers whether the window accepts dragged files.

void DragAcceptFiles(BOOL bAccept = TRUE);

Remarks

See DragAcceptFiles in the Windows SDK.

CWindow::DrawMenuBar

Redraws the window's menu bar.

BOOL DrawMenuBar() throw();

Remarks

See DrawMenuBar in the Windows SDK.

CWindow::EnableScrollBar

Enables or disables the scroll bar arrows.

BOOL EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH) throw();

Remarks

See EnableScrollBar in the Windows SDK.

CWindow::EnableWindow

Enables or disables input.

BOOL EnableWindow(BOOL bEnable = TRUE) throw();

Remarks

See EnableWindow in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::EnableWindow() to enable and disable the window
//wrapped by the CWindow object

CWindow myWindow;
myWindow.Attach(hWnd);

//The following call enables the window 
//CWindow::EnableWindow() takes TRUE as the default parameter

myWindow.EnableWindow();

if(myWindow.IsWindowEnabled())
{
   //Do something now that the window is enabled

   //Now it's time to disable the window again
   myWindow.EnableWindow(FALSE);
}

CWindow::EndPaint

Marks the end of painting.

void EndPaint(LPPAINTSTRUCT lpPaint) throw();

Remarks

See EndPaint in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object
//and calls CWindow::BeginPaint() and CWindow::EndPaint() in the 
// WM_PAINT handler of a CWindowImpl-derived class
LRESULT CMyCtrl::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, 
   BOOL& /*bHandled*/)
{
   CWindow myWindow;
   myWindow.Attach(m_hWnd);
   PAINTSTRUCT ps;
   HDC hDC  = myWindow.BeginPaint(&ps);
   //Use the hDC as much as you want
   ::Rectangle(hDC, 0, 0, 50, 50);

   myWindow.EndPaint(&ps);

   return 0;
}

CWindow::FlashWindow

Flashes the window once.

BOOL FlashWindow(BOOL bInvert) throw();

Remarks

See FlashWindow in the Windows SDK.

CWindow::GetClientRect

Retrieves the coordinates of the client area.

BOOL GetClientRect(LPRECT lpRect) const throw();

Remarks

See GetClientRect in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::GetClientRect() to get the client area rectangle
//of the window

CWindow myWindow;
myWindow.Attach(hWnd);
RECT rc;
myWindow.GetClientRect(&rc);

CWindow::GetDC

Retrieves a device context for the client area.

HDC GetDC() throw();

Remarks

See GetDC in the Windows SDK.

Example

// The following example attaches a HWND to the CWindow object,
// calls CWindow::GetDC to retrieve the DC of the client
// area of the window wrapped by CWindow Object, and calls
// CWindow::ReleaseDC to release the DC. 

CWindow myWindow;
myWindow.Attach(hWnd);   
HDC hDC = myWindow.GetDC();

// Use the DC

myWindow.ReleaseDC(hDC);
hDC = NULL;

CWindow::GetDCEx

Retrieves a device context for the client area and allows clipping options.

HDC GetDCEx(HRGN hRgnClip, DWORD flags) throw();

Remarks

See GetDCEx in the Windows SDK.

CWindow::GetDescendantWindow

Finds the descendant window specified by the given identifier.

HWND GetDescendantWindow(int nID) const throw();

Parameters

nID
[in] The identifier of the descendant window to be retrieved.

Return Value

The handle to a descendant window.

Remarks

GetDescendantWindow searches the entire tree of child windows, not only the windows that are immediate children.

CWindow::GetDlgControl

Call this function to get a pointer to an interface of an ActiveX control that is hosted by a composite control or a control-hosting dialog.

HRESULT GetDlgControl(
    int nID,
    REFIID iid,
    void** ppCtrl) throw();

Parameters

nID
[in] The resource ID of the control being retrieved.

iid
[in] The ID of the interface you would like to get from the control.

ppCtrl
[out] The pointer to the interface.

Return Value

Returns S_OK on success or any valid error HRESULT. For example, the function returns E_FAIL if the control specified by nID can't be found and it returns E_NOINTERFACE if the control can be found, but it doesn't support the interface specified by iid.

Remarks

Using this pointer, you can call methods on the interface.

CWindow::GetDlgCtrlID

Retrieves the window's identifier (for child windows only).

int GetDlgCtrlID() const throw();

Remarks

See GetDlgCtrlID in the Windows SDK.

CWindow::GetDlgHost

Retrieves a pointer to an interface to the ATL Control hosting container.

HRESULT GetDlgHost(
    int nID,
    REFIID iid,
    void** ppHost) throw();

Parameters

nID
[in] The resource ID of the control being retrieved.

iid
[in] The ID of the interface you would like to get from the control.

ppHost
[out] The pointer to the interface.

Return Value

Returns S_OK if the window specified by iid is a Control Container, and the requested interface could be retrieved. Returns E_FAIL if the window isn't a Control Container, or if the interface requested couldn't be retrieved. If a window with the specified ID couldn't be found, then the return value is equal to HRESULT_FROM_WIN32(ERROR_CONTROL_ID_NOT_FOUND).

Remarks

Using this pointer, you can call methods on the interface.

CWindow::GetDlgItem

Retrieves the specified child window.

HWND GetDlgItem(int nID) const throw();

Remarks

See GetDlgItem in the Windows SDK.

CWindow::GetDlgItemInt

Translates a control's text to an integer.

UINT GetDlgItemInt(
    int nID,
    BOOL* lpTrans = NULL,
    BOOL bSigned = TRUE) const throw();

Remarks

See GetDlgItemInt in the Windows SDK.

CWindow::GetDlgItemText

Retrieves a control's text.

UINT GetDlgItemText(
    int nID,
    LPTSTR lpStr,
    int nMaxCount) const throw();

BOOL GetDlgItemText(
    int nID,
    BSTR& bstrText) const throw();

Remarks

For more information, see GetDlgItemText in the Windows SDK.

The second version of this method allows you to copy the control's text to a BSTR. This version returns TRUE if the text is successfully copied; otherwise, FALSE.

CWindow::GetExStyle

Retrieves the extended window styles of the window.

DWORD GetExStyle() const throw();

Return Value

The window's extended styles.

Remarks

To retrieve the regular window styles, call GetStyle.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::GetExStyle() to retrieve the extended styles of 
//the window

CWindow myWindow;
myWindow.Attach(hWnd);
DWORD dwExStyles = myWindow.GetExStyle();

CWindow::GetFont

Retrieves the window's current font by sending a WM_GETFONT message to the window.

HFONT GetFont() const throw();

Return Value

A font handle.

CWindow::GetHotKey

Determines the hot key associated with the window by sending a WM_GETHOTKEY message.

DWORD GetHotKey() const throw();

Return Value

The virtual key code and modifiers for the hot key associated with the window. For a list of possible modifiers, see WM_GETHOTKEY in the Windows SDK. For a list of standard virtual key codes, see Winuser.h.

CWindow::GetIcon

Retrieves the handle to the window's large or small icon.

HICON GetIcon(BOOL bBigIcon = TRUE) const;

Parameters

bBigIcon
[in] If TRUE (the default value) the method returns the large icon. Otherwise, it returns the small icon.

Return Value

An icon handle.

Remarks

GetIcon sends a WM_GETICON message to the window.

CWindow::GetLastActivePopup

Retrieves the most recently active pop-up window.

HWND GetLastActivePopup() const throw();

Remarks

See GetLastActivePopup in the Windows SDK.

CWindow::GetMenu

Retrieves the window's menu.

HMENU GetMenu() const throw();

Remarks

See GetMenu in the Windows SDK.

CWindow::GetNextDlgGroupItem

Retrieves the previous or next control within a group of controls.

HWND GetNextDlgGroupItem(HWND hWndCtl, BOOL bPrevious = FALSE) const throw();

Remarks

See GetNextDlgGroupItem in the Windows SDK.

CWindow::GetNextDlgTabItem

Retrieves the previous or next control having the WS_TABSTOP style.

HWND GetNextDlgTabItem(HWND hWndCtl, BOOL bPrevious = FALSE) const throw();

Remarks

See GetNextDlgTabItem in the Windows SDK.

CWindow::GetParent

Retrieves the immediate parent window.

HWND GetParent() const throw();

Remarks

See GetParent in the Windows SDK.

Example

// The following example attaches a HWND to the CWindow object
// and calls CWindow::GetParent to find out the parent
// window of the window wrapped by CWindow object.

CWindow myWindow;
myWindow.Attach(hWnd);   
HWND hWndParent = myWindow.GetParent();

CWindow::GetScrollInfo

Retrieves the parameters of a scroll bar.

BOOL GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) throw();

Remarks

See GetScrollInfo in the Windows SDK.

CWindow::GetScrollPos

Retrieves the position of the scroll box.

int GetScrollPos(int nBar) const throw();

Remarks

See GetScrollPos in the Windows SDK.

CWindow::GetScrollRange

Retrieves the scroll bar range.

BOOL GetScrollRange(
    int nBar,
    LPINT lpMinPos,
    LPINT lpMaxPos) const throw();

Remarks

See GetScrollRange in the Windows SDK.

CWindow::GetStyle

Retrieves the window styles of the window.

DWORD GetStyle() const throw();

Return Value

The window's styles.

Remarks

To retrieve the extended window styles, call GetExStyle.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::GetStyle() to retrieve the styles of the window

CWindow myWindow;
myWindow.Attach(hWnd);
DWORD dwStyles = myWindow.GetStyle();

CWindow::GetSystemMenu

Creates a copy of the system menu for modification.

HMENU GetSystemMenu(BOOL bRevert) const throw();

Remarks

See GetSystemMenu in the Windows SDK.

CWindow::GetTopLevelParent

Retrieves the window's top-level parent window.

HWND GetTopLevelParent() const throw();

Return Value

The handle to the top-level parent window.

CWindow::GetTopLevelWindow

Retrieves the window's top-level parent or owner window.

HWND GetTopLevelWindow() const throw();

Return Value

The handle to the top-level owner window.

CWindow::GetTopWindow

Retrieves the top-level child window.

HWND GetTopWindow() const throw();

Remarks

See GetTopWindow in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::GetTopWindow() to get the top-level child window

CWindow myWindow;
myWindow.Attach(hWnd);
HWND hWndFavoriteChild = myWindow.GetTopWindow();

CWindow::GetUpdateRect

Retrieves the coordinates of the smallest rectangle that completely encloses the update region.

BOOL GetUpdateRect(LPRECT lpRect, BOOL bErase = FALSE) throw();

Remarks

See GetUpdateRect in the Windows SDK.

CWindow::GetUpdateRgn

Retrieves the update region and copies it into a specified region.

int GetUpdateRgn(HRGN hRgn, BOOL bErase = FALSE) throw();

Remarks

See GetUpdateRgn in the Windows SDK.

CWindow::GetWindow

Retrieves the specified window.

HWND GetWindow(UINT nCmd) const throw();

Remarks

See GetWindow in the Windows SDK.

CWindow::GetWindowContextHelpId

Retrieves the window's help context identifier.

DWORD GetWindowContextHelpId() const throw();

Remarks

See GetWindowContextHelpId in the Windows SDK.

CWindow::GetWindowDC

Retrieves a device context for the entire window.

HDC GetWindowDC() throw();

Remarks

See GetWindowDC in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::GetWindowDC() to retrieve the DC of the entire window

CWindow myWindow;
myWindow.Attach(hWnd);
HDC hDC = myWindow.GetWindowDC();

CWindow::GetWindowLong

Retrieves a 32-bit value at a specified offset into the extra window memory.

LONG GetWindowLong(int nIndex) const throw();

Remarks

See GetWindowLong in the Windows SDK.

Note

To write code that is compatible with both 32-bit and 64-bit versions of Windows, use CWindow::GetWindowLongPtr.

CWindow::GetWindowLongPtr

Retrieves information about the specified window, including a value at a specified offset into the extra window memory.

LONG_PTR GetWindowLongPtr(int nIndex) const throw();

Remarks

For more information, see GetWindowLongPtr in the Windows SDK.

If you're retrieving a pointer or a handle, this function supersedes the CWindow::GetWindowLong method.

Note

Pointers and handles are 32 bits on 32-bit Windows and 64 bits on 64-bit Windows.

To write code that is compatible with both 32-bit and 64-bit versions of Windows, use CWindow::GetWindowLongPtr.

CWindow::GetWindowPlacement

Retrieves the show state and positions.

BOOL GetWindowPlacement(WINDOWPLACEMENT FAR* lpwndpl) const throw();

Remarks

See GetWindowPlacement in the Windows SDK.

CWindow::GetWindowProcessID

Retrieves the identifier of the process that created the window.

DWORD GetWindowProcessID() throw();

Remarks

See GetWindowThreadProcessID in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::GetWindowProcessID() to retrieve the id of the 
//process that created the window

CWindow myWindow;
myWindow.Attach(hWnd);
DWORD dwID = myWindow.GetWindowProcessID();

CWindow::GetWindowRect

Retrieves the window's bounding dimensions.

BOOL GetWindowRect(LPRECT lpRect) const throw();

Remarks

See GetWindowRect in the Windows SDK.

CWindow::GetWindowRgn

Obtains a copy of the window region of a window.

int GetWindowRgn(HRGN hRgn) throw();

Remarks

See GetWindowRgn in the Windows SDK.

CWindow::GetWindowText

Retrieves the window's text.

int GetWindowText(LPTSTR lpszStringBuf, int nMaxCount) const throw();
BOOL GetWindowText(BSTR& bstrText) throw();
int GetWindowText(CSimpleString& strText) const;

Parameters

lpszStringBuf
A buffer to which to write the window text.

nMaxCount
The size of the buffer in characters; also the maximum number of characters to write.

bstrText
A BSTR in which to store the window text.

strText
A CString in which to store the window text.

Return Value

If the text is successfully copied, the return value is TRUE; otherwise, the return value is FALSE.

Remarks

See GetWindowText in the Windows SDK.

The second version of this method allows you to store the text in a BSTR; the third version allows you to store the result in a CString, since CSimpleString is the base class of CString.

CWindow::GetWindowTextLength

Retrieves the length of the window's text.

int GetWindowTextLength() const throw();

Remarks

See GetWindowTextLength in the Windows SDK.

CWindow::GetWindowThreadID

Retrieves the identifier of the thread that created the specified window.

DWORD GetWindowThreadID() throw();

Remarks

See GetWindowThreadProcessID in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::GetWindowThreadID() to retrieve the id of the thread 
//that created the window

CWindow myWindow;
myWindow.Attach(hWnd);
DWORD dwID = myWindow.GetWindowThreadID();

CWindow::GetWindowWord

Retrieves a 16-bit value at a specified offset into the extra window memory.

WORD GetWindowWord(int nIndex) const throw();

Remarks

See GetWindowLong in the Windows SDK.

CWindow::GotoDlgCtrl

Sets the keyboard focus to a control in the dialog box.

void GotoDlgCtrl(HWND hWndCtrl) const throw();

Remarks

See WM_NEXTDLGCTL in the Windows SDK.

CWindow::HideCaret

Hides the system caret.

BOOL HideCaret() throw();

Remarks

See HideCaret in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::HideCaret() to hide the caret of the window owning 
//the caret

CWindow myWindow;
myWindow.Attach(hWndEdit);
myWindow.HideCaret();

CWindow::HiliteMenuItem

Highlights or removes the highlight from a top-level menu item.

BOOL HiliteMenuItem(
    HMENU hMenu,
    UINT uHiliteItem,
    UINT uHilite) throw();

Remarks

See HiliteMenuItem in the Windows SDK.

CWindow::Invalidate

Invalidates the entire client area.

BOOL Invalidate(BOOL bErase = TRUE) throw();

Remarks

See InvalidateRect in the Windows SDK.

Passes NULL for the RECT parameter to the InvalidateRect Win32 function.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::Invalidate() to invalidate the entire client area

CWindow myWindow;
myWindow.Attach(hWnd);
myWindow.Invalidate();

CWindow::InvalidateRect

Invalidates the client area within the specified rectangle.

BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE) throw();

Remarks

See InvalidateRect in the Windows SDK.

CWindow::InvalidateRgn

Invalidates the client area within the specified region.

void InvalidateRgn(HRGN hRgn, BOOL bErase = TRUE) throw();

Remarks

For more information, see InvalidateRgn in the Windows SDK.

Specifies a void return type, while the InvalidateRgn Win32 function always returns TRUE.

CWindow::IsChild

Determines whether the specified window is a child window.

BOOL IsChild(const HWND hWnd) const throw();

Remarks

See IsChild in the Windows SDK.

CWindow::IsDialogMessage

Determines whether a message is intended for the specified dialog box.

BOOL IsDialogMessage(LPMSG lpMsg) throw();

Remarks

See IsDialogMessage in the Windows SDK.

CWindow::IsDlgButtonChecked

Determines the check state of the button.

UINT IsDlgButtonChecked(int nIDButton) const throw();

Remarks

See IsDlgButtonChecked in the Windows SDK.

CWindow::IsIconic

Determines whether the window is minimized.

BOOL IsIconic() const throw();

Remarks

See IsIconic in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::IsIconic() to determine if the window is minimized

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bIconic = myWindow.IsIconic();

CWindow::IsParentDialog

Determines if the parent window of the control is a dialog window.

BOOL IsParentDialog() throw();

Return Value

Returns TRUE if the parent window is a dialog, FALSE otherwise.

CWindow::IsWindow

Determines whether the specified window handle identifies an existing window.

BOOL IsWindow() throw();

Remarks

See IsWindow in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::IsWindow() to verify if the HWND corresponds 
//to an existing window

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bWindow = myWindow.IsWindow();

CWindow::IsWindowEnabled

Determines whether the window is enabled for input.

BOOL IsWindowEnabled() const throw();

Remarks

See IsWindowEnabled in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::IsWindowEnabled() to verify if the window is enabled 
//for receiving input

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bEnabled = myWindow.IsWindowEnabled();

CWindow::IsWindowVisible

Determines the window's visibility state.

BOOL IsWindowVisible() const throw();

Remarks

See IsWindowVisible in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::IsWindowVisible() to determine the visibility state 
//of the window

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bVisible = myWindow.IsWindowVisible();

CWindow::IsWindowUnicode

Determines whether the specified window is a native Unicode window.

BOOL IsWindowUnicode() throw();

Remarks

See IsWindowUnicode in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::IsWindowUnicode() to determine if the window is a 
//UNICODE window or an ANSI one.

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bUnicode = myWindow.IsWindowUnicode();

CWindow::IsZoomed

Determines whether the window is maximized.

BOOL IsZoomed() const throw();

Remarks

See IsZoomed in the Windows SDK.

CWindow::KillTimer

Destroys a timer event created by CWindow::SetTimer.

BOOL KillTimer(UINT nIDEvent) throw();

Remarks

See KillTimer in the Windows SDK.

CWindow::LockWindowUpdate

Disables or enables drawing in the window by calling the LockWindowUpdate Win32 function.

BOOL LockWindowUpdate(BOOL bLock = TRUE) throw();

Parameters

bLock
[in] If TRUE (the default value), the window will be locked. Otherwise, it will be unlocked.

Return Value

TRUE if the window is successfully locked; otherwise, FALSE.

Remarks

If bLock is TRUE, this method passes m_hWnd to the Win32 function; otherwise, it passes NULL.

CWindow::m_hWnd

Contains a handle to the window associated with the CWindow object.

HWND m_hWnd throw() throw();

CWindow::MapWindowPoints

Converts a set of points from the window's coordinate space to the coordinate space of another window.

int MapWindowPoints(
    HWND hWndTo,
    LPPOINT lpPoint,
    UINT nCount) const throw();

int MapWindowPoints(
    HWND hWndTo,
    LPRECT lpRect) const throw();

Remarks

See MapWindowPoints in the Windows SDK.

The second version of this method allows you to convert the coordinates of a RECT structure.

CWindow::MessageBox

Displays a message box.

int MessageBox(
    LPCTSTR lpszText,
    LPCTSTR lpszCaption = NULL,
    UINT nType = MB_OK) throw();

Remarks

See MessageBox in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::MessageBox() to pop up a Windows message box

CWindow myWindow;
myWindow.Attach(hWnd);
myWindow.MessageBox(_T("Hello World"));

CWindow::ModifyStyle

Modifies the window styles of the CWindow object.

BOOL ModifyStyle(
    DWORD dwRemove,
    DWORD dwAdd,
    UINT nFlags = 0) throw();

Parameters

dwRemove
[in] Specifies the window styles to be removed during style modification.

dwAdd
[in] Specifies the window styles to be added during style modification.

nFlags
[in] Window-positioning flags. For a list of possible values, see the SetWindowPos function in the Windows SDK.

Return Value

TRUE if the window styles are modified; otherwise, FALSE.

Remarks

Styles to be added or removed can be combined by using the bitwise "or" (|) operator. See the CreateWindow function in the Windows SDKfor information about the available window styles.

If nFlags is nonzero, ModifyStyle calls the Win32 function SetWindowPos, and redraws the window by combining nFlags with the following four flags:

  • SWP_NOSIZE Retains the current size.

  • SWP_NOMOVE Retains the current position.

  • SWP_NOZORDER Retains the current Z order.

  • SWP_NOACTIVATE Doesn't activate the window.

To modify a window's extended styles, call ModifyStyleEx.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::ModifyStyle() to add and remove the window styles

CWindow myWindow;
myWindow.Attach(hWnd);

//The following line removes the WS_CLIPCHILDREN style from the 
//window and adds the WS_CAPTION style to the window
myWindow.ModifyStyle(WS_CLIPCHILDREN, WS_CAPTION);

CWindow::ModifyStyleEx

Modifies the extended window styles of the CWindow object.

BOOL ModifyStyleEx(
    DWORD dwRemove,
    DWORD dwAdd,
    UINT nFlags = 0) throw();

Parameters

dwRemove
[in] Specifies the extended styles to be removed during style modification.

dwAdd
[in] Specifies the extended styles to be added during style modification.

nFlags
[in] Window-positioning flags. For a list of possible values, see the SetWindowPos function in the Windows SDK.

Return Value

TRUE if the extended window styles are modified; otherwise, FALSE.

Remarks

Styles to be added or removed can be combined by using the bitwise "or" (|) operator. See the CreateWindowEx function in the Windows SDK for information about the available extended styles.

If nFlags is nonzero, ModifyStyleEx calls the Win32 function SetWindowPos, and redraws the window by combining nFlags with the following four flags:

  • SWP_NOSIZE Retains the current size.

  • SWP_NOMOVE Retains the current position.

  • SWP_NOZORDER Retains the current Z order.

  • SWP_NOACTIVATE Doesn't activate the window.

To modify windows using regular window styles, call ModifyStyle.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::ModifyStyleEx() to add and remove the extended 
//window styles

CWindow myWindow;
myWindow.Attach(hWnd);

//The following line removes WS_EX_CONTEXTHELP extended style from 
//the window and adds WS_EX_TOOLWINDOW extended style to the window 

myWindow.ModifyStyleEx(WS_EX_CONTEXTHELP, WS_EX_TOOLWINDOW);

CWindow::MoveWindow

Changes the window's size and position.

BOOL MoveWindow(
    int x,
    int y,
    int nWidth,
    int nHeight,
    BOOL bRepaint = TRUE) throw();

BOOL MoveWindow(
    LPCRECT lpRect,
    BOOL bRepaint = TRUE) throw();

Remarks

For a top-level window object, the x and y parameters are relative to the upper-left corner of the screen. For a child window object, they're relative to the upper-left corner of the parent window's client area.

The second version of this method uses a RECT structure to determine the window's new position, width, and height.

CWindow::NextDlgCtrl

Sets the keyboard focus to the next control in the dialog box.

void NextDlgCtrl() const throw();

Remarks

See WM_NEXTDLGCTL in the Windows SDK.

CWindow::OpenClipboard

Opens the Clipboard.

BOOL OpenClipboard() throw();

Remarks

See OpenClipboard in the Windows SDK.

CWindow::operator HWND

Converts a CWindow object to an HWND.

operator HWND() const throw();

CWindow::operator =

Assigns an HWND to the CWindow object by setting the m_hWnd member to hWnd.

CWindow& operator= (HWND hWnd) throw();

CWindow::PostMessage

Places a message in the message queue associated with the thread that created the window.

BOOL PostMessage(
    UINT message,
    WPARAM wParam = 0,
    LPARAM lParam = 0) throw();

Remarks

See PostMessage in the Windows SDK.

Returns without waiting for the thread to process the message.

Example

//The following example attaches an HWND to the CWindow object and 
//posts a WM_PAINT message to the Window wrapped by the CWindow object 
//using CWindow::PostMessage() with the default values of WPARAM and 
//LPARAM

CWindow myWindow;
myWindow.Attach(hWnd);
myWindow.PostMessage(WM_PAINT);

CWindow::PrevDlgCtrl

Sets the keyboard focus to the previous control in the dialog box.

void PrevDlgCtrl() const throw();

Remarks

See WM_NEXTDLGCTL in the Windows SDK.

CWindow::Print

Sends a WM_PRINT message to the window to request that it draw itself in the specified device context.

void Print(HDC hDC, DWORD dwFlags) const throw();

Parameters

hDC
[in] The handle to a device context.

dwFlags
[in] Specifies the drawing options. You can combine one or more of the following flags:

  • PRF_CHECKVISIBLE Draw the window only if it's visible.

  • PRF_CHILDREN Draw all visible child windows.

  • PRF_CLIENT Draw the client area of the window.

  • PRF_ERASEBKGND Erase the background before drawing the window.

  • PRF_NONCLIENT Draw the non-client area of the window.

  • PRF_OWNED Draw all owned windows.

CWindow::PrintClient

Sends a WM_PRINTCLIENT message to the window to request that it draw its client area in the specified device context.

void PrintClient(HDC hDC, DWORD dwFlags) const throw();

Parameters

hDC
[in] The handle to a device context.

dwFlags
[in] Specifies drawing options. You can combine one or more of the following flags:

  • PRF_CHECKVISIBLE Draw the window only if it's visible.

  • PRF_CHILDREN Draw all visible child windows.

  • PRF_CLIENT Draw the client area of the window.

  • PRF_ERASEBKGND Erase the background before drawing the window.

  • PRF_NONCLIENT Draw the non-client area of the window.

  • PRF_OWNED Draw all owned windows.

CWindow::rcDefault

Contains default window dimensions.

static RECT rcDefault;

CWindow::RedrawWindow

Updates a specified rectangle or region in the client area.

BOOL RedrawWindow(
    LPCRECT lpRectUpdate = NULL,
    HRGN hRgnUpdate = NULL,
    UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);

throw()

Remarks

See RedrawWindow in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::RedrawWindow() to update the entire window using the 
//default arguments

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bRedrawn = myWindow.RedrawWindow();

CWindow::ReleaseDC

Releases a device context.

int ReleaseDC(HDC hDC);

Remarks

See ReleaseDC in the Windows SDK.

Example

// The following example attaches a HWND to the CWindow object,
// calls CWindow::GetDC to retrieve the DC of the client
// area of the window wrapped by CWindow Object, and calls
// CWindow::ReleaseDC to release the DC. 

CWindow myWindow;
myWindow.Attach(hWnd);   
HDC hDC = myWindow.GetDC();

// Use the DC

myWindow.ReleaseDC(hDC);
hDC = NULL;

CWindow::ResizeClient

Resizes the window to the specified client area size.

BOOL ResizeClient(
    int nWidth,
    int nHeight,
    BOOL bRedraw = FALSE) throw();

Parameters

nWidth
New width of the window in pixels.

nHeight
New height of the window in pixels.

bRedraw
A flag indicating whether to redraw changes. Default is FALSE, indicating the window doesn't redraw changes.

CWindow::ScreenToClient

Converts screen coordinates to client coordinates.

BOOL ScreenToClient(LPPOINT lpPoint) const throw();
BOOL ScreenToClient(LPRECT lpRect) const throw();

Remarks

See ScreenToClient in the Windows SDK.

The second version of this method allows you to convert the coordinates of a RECT structure.

CWindow::ScrollWindow

Scrolls the specified client area.

BOOL ScrollWindow(
    int xAmount,
    int yAmount,
    LPCRECT lpRect = NULL,
    LPCRECT lpClipRect = NULL) throw();

Remarks

See ScrollWindow in the Windows SDK.

CWindow::ScrollWindowEx

Scrolls the specified client area with additional features.

int ScrollWindowEx(
    int dx,
    int dy,
    LPCRECT lpRectScroll,
    LPCRECT lpRectClip,
    HRGN hRgnUpdate,
    LPRECT lpRectUpdate,
    UINT flags) throw();

Remarks

See ScrollWindowEx in the Windows SDK.

CWindow::SendDlgItemMessage

Sends a message to a control.

LRESULT SendDlgItemMessage(
    int nID,
    UINT message,
    WPARAM wParam = 0,
    LPARAM lParam = 0) throw();

Remarks

See SendDlgItemMessage in the Windows SDK.

CWindow::SendMessage

Sends a message to the window and doesn't return until the window procedure has processed the message.

LRESULT SendMessage(
    UINT message,
    WPARAM wParam = 0,
    LPARAM lParam = 0) throw();

static LRESULT SendMessage(
    HWND hWnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam) throw();

Remarks

See SendMessage in the Windows SDK.

Example

// The following example attaches a HWND to the CWindow
// object and sends a WM_PAINT message to the window
// wrapped by CWindow object using CWindow::SendMessage.

CWindow myWindow;
myWindow.Attach(hWnd);   
myWindow.SendMessage(WM_PAINT, 0L, 0L);

CWindow::SendMessageToDescendants

Sends the specified message to all immediate children of the CWindow object.

void SendMessageToDescendants(
    UINT message,
    WPARAM wParam = 0,
    LPARAM lParam = 0,
    BOOL bDeep = TRUE) throw();

Parameters

message
[in] The message to be sent.

wParam
[in] Additional message-specific information.

lParam
[in] Additional message-specific information.

bDeep
[in] If TRUE (the default value), the message will be sent to all descendant windows; otherwise, it will be sent only to the immediate child windows.

Remarks

If bDeep is TRUE, the message is additionally sent to all other descendant windows.

CWindow::SendNotifyMessage

Sends a message to the window.

BOOL SendNotifyMessage(
    UINT message,
    WPARAM wParam = 0,
    LPARAM lParam = 0) throw();

Remarks

See SendNotifyMessage in the Windows SDK.

If the window was created by the calling thread, SendNotifyMessage doesn't return until the window procedure has processed the message. Otherwise, it returns immediately.

CWindow::SetActiveWindow

Activates the window.

HWND SetActiveWindow() throw();

Remarks

See SetActiveWindow in the Windows SDK.

Example

// The following example attaches a HWND to the CWindow object
// and sets the window as an active window by calling 
// CWindow::SetActiveWindow which returns the HWND of the
// previously active window.

CWindow myWindow;
myWindow.Attach(hWnd);   
HWND hWndPrev = myWindow.SetActiveWindow();

CWindow::SetCapture

Sends all subsequent mouse input to the window.

HWND SetCapture() throw();

Remarks

See SetCapture in the Windows SDK.

CWindow::SetClipboardViewer

Adds the window to the Clipboard viewer chain.

HWND SetClipboardViewer() throw();

Remarks

See SetClipboardViewer in the Windows SDK.

CWindow::SetDlgCtrlID

Sets the identifier of the window to the specified value.

int SetDlgCtrlID(int nID) throw();

Parameters

nID
[in] The new value to set for the window's identifier.

Return Value

If successful, the previous identifier of the window; otherwise 0.

CWindow::SetDlgItemInt

Changes a control's text to the string representation of an integer value.

BOOL SetDlgItemInt(
    int nID,
    UINT nValue,
    BOOL bSigned = TRUE) throw();

Remarks

See SetDlgItemInt in the Windows SDK.

CWindow::SetDlgItemText

Changes a control's text.

BOOL SetDlgItemText(int nID, LPCTSTR lpszString) throw();

Remarks

See SetDlgItemText in the Windows SDK.

CWindow::SetFocus

Sets the input focus to the window.

HWND SetFocus() throw();

Remarks

See SetFocus in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::SetFocus() to set the input focus

CWindow myWindow;
myWindow.Attach(hWnd);
HWND hWndLeftFocus = myWindow.SetFocus();

CWindow::SetFont

Changes the window's current font by sending a WM_SETFONT message to the window.

void SetFont(HFONT hFont, BOOL bRedraw = TRUE) throw();

Parameters

hFont
[in] The handle to the new font.

bRedraw
[in] If TRUE (the default value), the window is redrawn. Otherwise, it isn't.

CWindow::SetHotKey

Associates a hot key with the window by sending a WM_SETHOTKEY message.

int SetHotKey(WORD wVirtualKeyCode, WORD wModifiers) throw();

Parameters

wVirtualKeyCode
[in] The virtual key code of the hot key. For a list of standard virtual key codes, see Winuser.h.

wModifiers
[in] The modifiers of the hot key. For a list of possible values, see WM_SETHOTKEY in the Windows SDK.

Return Value

For a list of possible return values, see WM_SETHOTKEY in the Windows SDK.

CWindow::SetIcon

Sets the window's large or small icon to the icon identified by hIcon.

HICON SetIcon(HICON hIcon, BOOL bBigIcon = TRUE) throw();

Parameters

hIcon
[in] The handle to a new icon.

bBigIcon
[in] If TRUE (the default value), the method sets a large icon. Otherwise, it sets a small icon.

Return Value

The handle to the previous icon.

Remarks

SetIcon sends a WM_SETICON message to the window.

CWindow::SetMenu

Changes the window's current menu.

BOOL SetMenu(HMENU hMenu) throw();

Remarks

See SetMenu in the Windows SDK.

CWindow::SetParent

Changes the parent window.

HWND SetParent(HWND hWndNewParent) throw();

Remarks

See SetParent in the Windows SDK.

Example

// The following example attaches a HWND to the CWindow object
// and sets the hWndParent as the parent window of the 
// window wrapped by CWindow object using CWindow::SetParent.

CWindow myWindow;
myWindow.Attach(hWndChild);
HWND hWndPrevParent = myWindow.SetParent(hWndParent);

CWindow::SetRedraw

Sets or clears the redraw flag by sending a WM_SETREDRAW message to the window.

void SetRedraw(BOOL bRedraw = TRUE) throw();

Parameters

bRedraw
[in] Specifies the state of the redraw flag. If TRUE (the default value), the redraw flag is set; if FALSE, the flag is cleared.

Remarks

Call SetRedraw to allow changes to be redrawn or to prevent changes from being redrawn.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::SetRedraw() to set and reset the redraw flag

CWindow myWindow;
myWindow.Attach(hWnd);
myWindow.SetRedraw();      //sets the redraw flag to TRUE
//
//
myWindow.SetRedraw(FALSE); //sets the redraw flag to FALSE

CWindow::SetScrollInfo

Sets the parameters of a scroll bar.

int SetScrollInfo(
    int nBar,
    LPSCROLLINFO lpScrollInfo,
    BOOL bRedraw = TRUE) throw();

Remarks

See SetScrollInfo in the Windows SDK.

CWindow::SetScrollPos

Changes the position of the scroll box.

int SetScrollPos(
    int nBar,
    int nPos,
    BOOL bRedraw = TRUE) throw();

Remarks

See SetScrollPos in the Windows SDK.

CWindow::SetScrollRange

Changes the scroll bar range.

BOOL SetScrollRange(
    int nBar,
    int nMinPos,
    int nMaxPos,
    BOOL bRedraw = TRUE) throw();

Remarks

See SetScrollRange in the Windows SDK.

CWindow::SetTimer

Creates a timer event.

UINT SetTimer(
    UINT nIDEvent,
    UINT nElapse,
    void (CALLBACK* lpfnTimer)(HWND, UINT, UINT, DWORD) = NULL) throw();

Remarks

See SetTimer in the Windows SDK.

CWindow::SetWindowContextHelpId

Sets the window's help context identifier.

BOOL SetWindowContextHelpId(DWORD dwContextHelpId) throw();

Remarks

See SetWindowContextHelpId in the Windows SDK.

CWindow::SetWindowLong

Sets a 32-bit value at a specified offset into the extra window memory.

LONG SetWindowLong(int nIndex, LONG dwNewLong) throw();

Remarks

See SetWindowLong in the Windows SDK.

Note

To write code that is compatible with both 32-bit and 64-bit versions of Windows, use CWindow::SetWindowLongPtr.

CWindow::SetWindowLongPtr

Changes an attribute of the specified window, and also sets a value at the specified offset in the extra window memory.

LONG_PTR SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong) throw();

Remarks

See SetWindowLongPtr in the Windows SDK.

This function supersedes the CWindow::SetWindowLong method. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use CWindow::SetWindowLongPtr.

CWindow::SetWindowPlacement

Sets the show state and positions.

BOOL SetWindowPlacement(const WINDOWPLACEMENT FAR* lpwndpl);

Remarks

See SetWindowPlacement in the Windows SDK.

CWindow::SetWindowPos

Sets the size, position, and Z order.

BOOL SetWindowPos(
    HWND hWndInsertAfter,
    int x,
    int y,
    int cx,
    int cy,
    UINT nFlags) throw();

BOOL SetWindowPos(
    HWND hWndInsertAfter,
    LPCRECT lpRect,
    UINT nFlags) throw();

Remarks

See SetWindowPos in the Windows SDK.

The second version of this method uses a RECT structure to set the window's new position, width, and height.

CWindow::SetWindowRgn

Sets the window region of a window.

int SetWindowRgn(HRGN hRgn, BOOL bRedraw = FALSE) throw();

Remarks

See SetWindowRgn in the Windows SDK.

CWindow::SetWindowText

Changes the window's text.

BOOL SetWindowText(LPCTSTR lpszString) throw();

Remarks

See SetWindowText in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::SetWindowText() to set the new title-text of the 
//window

CWindow myWindow;
myWindow.Attach(hWnd);
myWindow.SetWindowText(_T("Hello ATL"));

CWindow::SetWindowWord

Sets a 16-bit value at a specified offset into the extra window memory.

WORD SetWindowWord(int nIndex, WORD wNewWord) throw();

Remarks

See SetWindowLong in the Windows SDK.

CWindow::ShowCaret

Displays the system caret.

BOOL ShowCaret() throw();

Remarks

See ShowCaret in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::ShowCaret() to show the caret

CWindow myWindow;
myWindow.Attach(hWnd);
myWindow.ShowCaret();

CWindow::ShowOwnedPopups

Shows or hides the pop-up windows owned by the window.

BOOL ShowOwnedPopups(BOOL bShow = TRUE) throw();

Remarks

See ShowOwnedPopups in the Windows SDK.

CWindow::ShowScrollBar

Shows or hides a scroll bar.

BOOL ShowScrollBar(UINT nBar, BOOL bShow = TRUE) throw();

Remarks

See ShowScrollBar in the Windows SDK.

CWindow::ShowWindow

Sets the window's show state.

BOOL ShowWindow(int nCmdShow) throw();

Remarks

See ShowWindow in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::ShowWindow() to show the window in its maximized state

CWindow myWindow;
myWindow.Attach(hWnd);
myWindow.ShowWindow(SW_SHOWMAXIMIZED);

CWindow::ShowWindowAsync

Sets the show state of a window created by a different thread.

BOOL ShowWindowAsync(int nCmdShow) throw();

Remarks

See ShowWindowAsync in the Windows SDK.

CWindow::UpdateWindow

Updates the client area.

BOOL UpdateWindow() throw();

Remarks

See UpdateWindow in the Windows SDK.

Example

//The following example attaches an HWND to the CWindow object and 
//calls CWindow::UpdateWindow() to update the window

CWindow myWindow;
myWindow.Attach(hWnd);
BOOL bUpdated = myWindow.UpdateWindow();

CWindow::ValidateRect

Validates the client area within the specified rectangle.

BOOL ValidateRect(LPCRECT lpRect) throw();

Remarks

See ValidateRect in the Windows SDK.

CWindow::ValidateRgn

Validates the client area within the specified region.

BOOL ValidateRgn(HRGN hRgn) throw();

Remarks

See ValidateRgn in the Windows SDK.

CWindow::WinHelp

Starts Windows Help.

BOOL WinHelp(
    LPCTSTR lpszHelp,
    UINT nCmd = HELP_CONTEXT,
    DWORD dwData = 0) throw();

Remarks

See WinHelp in the Windows SDK.

See also

Class Overview