CWindow Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

This class provides methods for manipulating a window.

System_CAPS_ICON_important.jpg Important

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

class CWindow

Public Constructors

NameDescription
CWindow::CWindowConstructor.

Public Methods

NameDescription
CWindow::ArrangeIconicWindowsArranges all minimized child windows.
CWindow::AttachAttaches a window to the CWindow object.
CWindow::BeginPaintPrepares the window for painting.
CWindow::BringWindowToTopBrings the window to the top of the Z order.
CWindow::CenterWindowCenters the window against a given window.
CWindow::ChangeClipboardChainRemoves the window from the chain of Clipboard viewers.
CWindow::CheckDlgButtonChanges the check state of the specified button.
CWindow::CheckRadioButtonChecks the specified radio button.
CWindow::ChildWindowFromPointRetrieves the child window containing the specified point.
CWindow::ChildWindowFromPointExRetrieves a particular type of child window containing the specified point.
CWindow::ClientToScreenConverts client coordinates to screen coordinates.
CWindow::CreateCreates a window.
CWindow::CreateCaretCreates a new shape for the system caret.
CWindow::CreateGrayCaretCreates a gray rectangle for the system caret.
CWindow::CreateSolidCaretCreates a solid rectangle for the system caret.
CWindow::DeferWindowPosUpdates the specified multiple-window-position structure for the specified window.
CWindow::DestroyWindowDestroys the window associated with the CWindow object.
CWindow::DetachDetaches the window from the CWindow object.
CWindow::DlgDirListFills a list box with the names of all files matching a specified path or file name.
CWindow::DlgDirListComboBoxFills a combo box with the names of all files matching a specified path or file name.
CWindow::DlgDirSelectRetrieves the current selection from a list box.
CWindow::DlgDirSelectComboBoxRetrieves the current selection from a combo box.
CWindow::DragAcceptFilesRegisters whether the window accepts dragged files.
CWindow::DrawMenuBarRedraws the window's menu bar.
CWindow::EnableScrollBarEnables or disables the scroll bar arrows.
CWindow::EnableWindowEnables or disables input.
CWindow::EndPaintMarks the end of painting.
CWindow::FlashWindowFlashes the window once.
CWindow::GetClientRectRetrieves the coordinates of the client area.
CWindow::GetDCRetrieves a device context for the client area.
CWindow::GetDCExRetrieves a device context for the client area and allows clipping options.
CWindow::GetDescendantWindowRetrieves the specified descendant window.
CWindow::GetDlgControlRetrieves an interface on the specified control.
CWindow::GetDlgCtrlIDRetrieves the window's identifier (for child windows only).
CWindow::GetDlgHostRetrieves a pointer to an interface to the ATL Control hosting container.
CWindow::GetDlgItemRetrieves the specified child window.
CWindow::GetDlgItemIntTranslates a control's text to an integer.
CWindow::GetDlgItemTextRetrieves a control's text.
CWindow::GetExStyleRetrieves the extended window styles.
CWindow::GetFontRetrieves the window's current font.
CWindow::GetHotKeyDetermines the hot key associated with the window.
CWindow::GetIconRetrieves the window's large or small icon.
CWindow::GetLastActivePopupRetrieves the most recently active pop-up window.
CWindow::GetMenuRetrieves the window's menu.
CWindow::GetNextDlgGroupItemRetrieves the previous or next control within a group of controls.
CWindow::GetNextDlgTabItemRetrieves the previous or next control having the WS_TABSTOP style.
CWindow::GetParentRetrieves the immediate parent window.
CWindow::GetScrollInfoRetrieves the parameters of a scroll bar.
CWindow::GetScrollPosRetrieves the position of the scroll box.
CWindow::GetScrollRangeRetrieves the scroll bar range.
CWindow::GetStyleRetrieves the window styles.
CWindow::GetSystemMenuCreates a copy of the system menu for modification.
CWindow::GetTopLevelParentRetrieves the top-level parent or owner window.
CWindow::GetTopLevelWindowRetrieves the top-level owner window.
CWindow::GetTopWindowRetrieves the top-level child window.
CWindow::GetUpdateRectRetrieves the coordinates of the smallest rectangle that completely encloses the update region.
CWindow::GetUpdateRgnRetrieves the update region and copies it into a specified region.
CWindow::GetWindowRetrieves the specified window.
CWindow::GetWindowContextHelpIdRetrieves the window's help context identifier.
CWindow::GetWindowDCRetrieves a device context for the entire window.
CWindow::GetWindowLongRetrieves a 32-bit value at a specified offset into the extra window memory.
CWindow::GetWindowLongPtrRetrieves information about the specified window, including a value at a specified offset into the extra window memory.
CWindow::GetWindowPlacementRetrieves the show state and positions.
CWindow::GetWindowProcessIDRetrieves the identifier of the process that created the window.
CWindow::GetWindowRectRetrieves the window's bounding dimensions.
CWindow::GetWindowRgnObtains a copy of the window region of a window.
CWindow::GetWindowTextRetrieves the window's text.
CWindow::GetWindowTextLengthRetrieves the length of the window's text.
CWindow::GetWindowThreadIDRetrieves the identifier of the thread that created the specified window.
CWindow::GetWindowWordRetrieves a 16-bit value at a specified offset into the extra window memory.
CWindow::GotoDlgCtrlSets the keyboard focus to a control in the dialog box.
CWindow::HideCaretHides the system caret.
CWindow::HiliteMenuItemHighlights or removes the highlight from a top-level menu item.
CWindow::InvalidateInvalidates the entire client area.
CWindow::InvalidateRectInvalidates the client area within the specified rectangle.
CWindow::InvalidateRgnInvalidates the client area within the specified region.
CWindow::IsChildDetermines whether the specified window is a child window.
CWindow::IsDialogMessageDetermines whether a message is intended for the specified dialog box.
CWindow::IsDlgButtonCheckedDetermines the check state of the button.
CWindow::IsIconicDetermines whether the window is minimized.
CWindow::IsParentDialogDetermines if the parent window of a control is a dialog window.
CWindow::IsWindowDetermines whether the specified window handle identifies an existing window.
CWindow::IsWindowEnabledDetermines whether the window is enabled for input.
CWindow::IsWindowUnicodeDetermines whether the specified window is a native Unicode window.
CWindow::IsWindowVisibleDetermines the window's visibility state.
CWindow::IsZoomedDetermines whether the window is maximized.
CWindow::KillTimerDestroys a timer event.
CWindow::LockWindowUpdateDisables or enables drawing in the window.
CWindow::MapWindowPointsConverts a set of points from the window's coordinate space to the coordinate space of another window.
CWindow::MessageBoxDisplays a message box.
CWindow::ModifyStyleModifies the window styles.
CWindow::ModifyStyleExModifies the extended window styles.
CWindow::MoveWindowChanges the window's size and position.
CWindow::NextDlgCtrlSets the keyboard focus to the next control in the dialog box.
CWindow::OpenClipboardOpens the Clipboard.
CWindow::PostMessagePlaces 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::PrevDlgCtrlSets the keyboard focus to the previous control in the dialog box.
CWindow::PrintRequests that the window be drawn in a specified device context.
CWindow::PrintClientRequests that the window's client area be drawn in a specified device context.
CWindow::RedrawWindowUpdates a specified rectangle or region in the client area.
CWindow::ReleaseDCReleases a device context.
CWindow::ResizeClientResizes the window.
CWindow::ScreenToClientConverts screen coordinates to client coordinates.
CWindow::ScrollWindowScrolls the specified client area.
CWindow::ScrollWindowExScrolls the specified client area with additional features.
CWindow::SendDlgItemMessageSends a message to a control.
CWindow::SendMessageSends a message to the window and does not return until the window procedure has processed the message.
CWindow::SendMessageToDescendantsSends a message to the specified descendant windows.
CWindow::SendNotifyMessageSends a message to the window. If the window was created by the calling thread, SendNotifyMessage does not return until the window procedure has processed the message. Otherwise, it returns immediately.
CWindow::SetActiveWindowActivates the window.
CWindow::SetCaptureSends all subsequent mouse input to the window.
CWindow::SetClipboardViewerAdds the window to the Clipboard viewer chain.
CWindow::SetDlgCtrlIDChanges the window's identifier.
CWindow::SetDlgItemIntChanges a control's text to the string representation of an integer value.
CWindow::SetDlgItemTextChanges a control's text.
CWindow::SetFocusSets the input focus to the window.
CWindow::SetFontChanges the window's current font.
CWindow::SetHotKeyAssociates a hot key with the window.
CWindow::SetIconChanges the window's large or small icon.
CWindow::SetMenuChanges the window's current menu.
CWindow::SetParentChanges the parent window.
CWindow::SetRedrawSets or clears the redraw flag.
CWindow::SetScrollInfoSets the parameters of a scroll bar.
CWindow::SetScrollPosChanges the position of the scroll box.
CWindow::SetScrollRangeChanges the scroll bar range.
CWindow::SetTimerCreates a timer event.
CWindow::SetWindowContextHelpIdSets the window's help context identifier.
CWindow::SetWindowLongSets a 32-bit value at a specified offset into the extra window memory.
CWindow::SetWindowLongPtrChanges an attribute of the specified window, and also sets a value at the specified offset in the extra window memory.
CWindow::SetWindowPlacementSets the show state and positions.
CWindow::SetWindowPosSets the size, position, and Z order.
CWindow::SetWindowRgnSets the window region of a window.
CWindow::SetWindowTextChanges the window's text.
CWindow::SetWindowWordSets a 16-bit value at a specified offset into the extra window memory.
CWindow::ShowCaretDisplays the system caret.
CWindow::ShowOwnedPopupsShows or hides the pop-up windows owned by the window.
CWindow::ShowScrollBarShows or hides a scroll bar.
CWindow::ShowWindowSets the window's show state.
CWindow::ShowWindowAsyncSets the show state of a window created by a different thread.
CWindow::UpdateWindowUpdates the client area.
CWindow::ValidateRectValidates the client area within the specified rectangle.
CWindow::ValidateRgnValidates the client area within the specified region.
CWindow::WinHelpStarts Windows Help.

Public Operators

NameDescription
CWindow::operator HWNDConverts the CWindow object to an HWND.
CWindow::operator =Assigns an HWND to the CWindow object.

Public Data Members

NameDescription
CWindow::m_hWndThe handle to the window associated with the CWindow object.
CWindow::rcDefaultContains default window dimensions.

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

System_CAPS_ICON_note.jpg 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.

Header: atlwin.h

Arranges all minimized child windows.

UINT ArrangeIconicWindows() throw();

Remarks

See ArrangeIconicWindows in the Windows SDK.

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

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;
}

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
   }

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 is 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

Removes the window from the chain of Clipboard viewers.

BOOL ChangeClipboardChain(HWND hWndNewNext) throw();

Remarks

See ChangeClipboardChain in the Windows SDK.

Changes the check state of the specified button.

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

Remarks

See CheckDlgButton in the Windows SDK.

Checks the specified radio button.

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

Remarks

See CheckRadioButton in the Windows SDK.

Retrieves the child window containing the specified point.

HWND ChildWindowFromPoint(POINT point) const throw();

Remarks

See ChildWindowFromPoint in the Windows SDK.

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.

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.

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.

Creates a new shape for the system caret.

BOOL CreateCaret(HBITMAP pBitmap) throw();

Remarks

See CreateCaret in the Windows SDK.

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.

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.

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.

System_CAPS_ICON_note.jpg 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.

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.

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 does not 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;

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(); 

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.

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.

Retrieves the current selection from a list box.

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

Remarks

See DlgDirSelectEx in the Windows SDK.

Retrieves the current selection from a combo box.

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

Remarks

See DlgDirSelectComboBoxEx in the Windows SDK.

Registers whether the window accepts dragged files.

void DragAcceptFiles(BOOL bAccept = TRUE);

Remarks

See DragAcceptFiles in the Windows SDK.

Redraws the window's menu bar.

BOOL DrawMenuBar() throw();

Remarks

See DrawMenuBar in the Windows SDK.

Enables or disables the scroll bar arrows.

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

Remarks

See EnableScrollBar in the Windows SDK.

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);
   }

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;
}

Flashes the window once.

BOOL FlashWindow(BOOL bInvert) throw();

Remarks

See FlashWindow in the Windows SDK.

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

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;

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.

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.

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

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

int GetDlgCtrlID() const throw();

Remarks

See GetDlgCtrlID in the Windows SDK.

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 is not a Control Container, or if the interface requested could not be retrieved. If a window with the specified ID could not 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.

Retrieves the specified child window.

HWND GetDlgItem(int nID) const throw();

Remarks

See GetDlgItem in the Windows SDK.

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.

Retrieves a control's text.

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

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

Remarks

See GetDlgItemText in the Windows SDK.

Remarks

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.

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();

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

HFONT GetFont() const throw();

Return Value

A font handle.

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 of standard virtual key codes, see Winuser.h.

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.

Retrieves the most recently active pop-up window.

HWND GetLastActivePopup() const throw();

Remarks

See GetLastActivePopup in the Windows SDK.

Retrieves the window's menu.

HMENU GetMenu() const throw();

Remarks

See GetMenu in the Windows SDK.

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.

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.

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();

Retrieves the parameters of a scroll bar.

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

Remarks

See GetScrollInfo in the Windows SDK.

Retrieves the position of the scroll box.

int GetScrollPos(int nBar) const throw();

Remarks

See GetScrollPos in the Windows SDK.

Retrieves the scroll bar range.

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

Remarks

See GetScrollRange in the Windows SDK.

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();

Creates a copy of the system menu for modification.

HMENU GetSystemMenu(BOOL bRevert) const throw();

Remarks

See GetSystemMenu in the Windows SDK.

Retrieves the window's top-level parent window.

HWND GetTopLevelParent() const throw();

Return Value

The handle to the top-level parent window.

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

HWND GetTopLevelWindow() const throw();

Return Value

The handle to the top-level owner window.

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();

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.

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.

Retrieves the specified window.

HWND GetWindow(UINT nCmd) const throw();

Remarks

See GetWindow in the Windows SDK.

Retrieves the window's help context identifier.

DWORD GetWindowContextHelpId() const throw();

Remarks

See GetWindowContextHelpId in the Windows SDK.

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();

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.

System_CAPS_ICON_note.jpg Note

To write code that is compatible with both 32-bit and 64-bit versions of Windows, use 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

See GetWindowLongPtr in the Windows SDK.

Remarks

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

System_CAPS_ICON_note.jpg 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.

Retrieves the show state and positions.

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

Remarks

See GetWindowPlacement in the Windows SDK.

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();

Retrieves the window's bounding dimensions.

BOOL GetWindowRect(LPRECT lpRect) const throw();

Remarks

See GetWindowRect in the Windows SDK.

Obtains a copy of the window region of a window.

int GetWindowRgn(HRGN hRgn) throw();

Remarks

See GetWindowRgn in the Windows SDK.

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.

Retrieves the length of the window's text.

int GetWindowTextLength() const throw();

Remarks

See GetWindowTextLength in the Windows SDK.

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();

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.

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.

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();

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.

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();

Invalidates the client area within the specified rectangle.

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

Remarks

See InvalidateRect in the Windows SDK.

Invalidates the client area within the specified region.

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

Remarks

See InvalidateRgn in the Windows SDK.

Remarks

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

Determines whether the specified window is a child window.

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

Remarks

See IsChild in the Windows SDK.

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

BOOL IsDialogMessage(LPMSG lpMsg) throw();

Remarks

See IsDialogMessage in the Windows SDK.

Determines the check state of the button.

UINT IsDlgButtonChecked(int nIDButton) const throw();

Remarks

See IsDlgButtonChecked in the Windows SDK.

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();

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.

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();

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();

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();

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();

Determines whether the window is maximized.

BOOL IsZoomed() const throw();

Remarks

See IsZoomed in the Windows SDK.

Destroys a timer event created by CWindow::SetTimer.

BOOL KillTimer(UINT nIDEvent) throw();

Remarks

See KillTimer in the Windows SDK.

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.

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

HWND m_hWnd throw() throw();

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.

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"));

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 Does not 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);

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 SDKfor 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 Does not 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);

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

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

void NextDlgCtrl() const throw();

Remarks

See WM_NEXTDLGCTL in the Windows SDK.

Opens the Clipboard.

BOOL OpenClipboard() throw();

Remarks

See OpenClipboard in the Windows SDK.

Converts a CWindow object to an HWND.

operator HWND() const throw();

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

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

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

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

void PrevDlgCtrl() const throw();

Remarks

See WM_NEXTDLGCTL in the Windows SDK.

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

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

Contains default window dimensions.

static RECT rcDefault;

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();

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;

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 does not redraw changes.

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.

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.

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.

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.

Sends a message to the window and does not 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);

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.

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 does not return until the window procedure has processed the message. Otherwise, it returns immediately.

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();

Sends all subsequent mouse input to the window.

HWND SetCapture() throw();

Remarks

See SetCapture in the Windows SDK.

Adds the window to the Clipboard viewer chain.

HWND SetClipboardViewer() throw();

Remarks

See SetClipboardViewer in the Windows SDK.

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.

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.

Changes a control's text.

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

Remarks

See SetDlgItemText in the Windows SDK.

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();

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 is not.

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

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.

Changes the window's current menu.

BOOL SetMenu(HMENU hMenu) throw();

Remarks

See SetMenu in the Windows SDK.

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

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

Sets the parameters of a scroll bar.

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

Remarks

See SetScrollInfo in the Windows SDK.

Changes the position of the scroll box.

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

Remarks

See SetScrollPos in the Windows SDK.

Changes the scroll bar range.

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

Remarks

See SetScrollRange in the Windows SDK.

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.

Sets the window's help context identifier.

BOOL SetWindowContextHelpId(DWORD dwContextHelpId) throw();

Remarks

See SetWindowContextHelpId in the Windows SDK.

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.

System_CAPS_ICON_note.jpg Note

To write code that is compatible with both 32-bit and 64-bit versions of Windows, use 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.

Sets the show state and positions.

BOOL SetWindowPlacement(const WINDOWPLACEMENT FAR* lpwndpl);

Remarks

See SetWindowPlacement in the Windows SDK.

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.

Sets the window region of a window.

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

Remarks

See SetWindowRgn in the Windows SDK.

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"));

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.

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();

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

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

Remarks

See ShowOwnedPopups in the Windows SDK.

Shows or hides a scroll bar.

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

Remarks

See ShowScrollBar in the Windows SDK.

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

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

BOOL ShowWindowAsync(int nCmdShow) throw();

Remarks

See ShowWindowAsync in the Windows SDK.

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();

Validates the client area within the specified rectangle.

BOOL ValidateRect(LPCRECT lpRect) throw();

Remarks

See ValidateRect in the Windows SDK.

Validates the client area within the specified region.

BOOL ValidateRgn(HRGN hRgn) throw();

Remarks

See ValidateRgn in the Windows SDK.

Starts Windows Help.

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

Remarks

See WinHelp in the Windows SDK.

Class Overview

Show: