class CWindow

来源:互联网 发布:js input 显示隐藏 编辑:程序博客网 时间:2024/06/06 08:28
/////////////////////////////////////////////////////////////////////////////// CWindow - client side for a Windows windowclass CWindow{public:static RECT rcDefault;HWND m_hWnd;CWindow(HWND hWnd = NULL) throw() :m_hWnd(hWnd){}CWindow& operator=(HWND hWnd) throw(){m_hWnd = hWnd;return *this;}static LPCTSTR GetWndClassName() throw(){return NULL;}void Attach(HWND hWndNew) throw(){ATLASSUME(m_hWnd == NULL);ATLASSERT((hWndNew == NULL) || ::IsWindow(hWndNew));m_hWnd = hWndNew;}HWND Detach() throw(){HWND hWnd = m_hWnd;m_hWnd = NULL;return hWnd;}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(){ATLASSUME(m_hWnd == NULL);if(rect.m_lpRect == NULL)rect.m_lpRect = &rcDefault;m_hWnd = ::CreateWindowEx(dwExStyle, lpstrWndClass, szWindowName,dwStyle, rect.m_lpRect->left, rect.m_lpRect->top, rect.m_lpRect->right - rect.m_lpRect->left,rect.m_lpRect->bottom - rect.m_lpRect->top, hWndParent, MenuOrID.m_hMenu,_AtlBaseModule.GetModuleInstance(), lpCreateParam);return m_hWnd;}BOOL DestroyWindow() throw(){ATLASSERT(::IsWindow(m_hWnd));if(!::DestroyWindow(m_hWnd))return FALSE;m_hWnd = NULL;return TRUE;}// Attributesoperator HWND() const throw(){ return m_hWnd; }DWORD GetStyle() const throw(){ATLASSERT(::IsWindow(m_hWnd));return (DWORD)::GetWindowLong(m_hWnd, GWL_STYLE);}DWORD GetExStyle() const throw(){ATLASSERT(::IsWindow(m_hWnd));return (DWORD)::GetWindowLong(m_hWnd, GWL_EXSTYLE);}LONG GetWindowLong(int nIndex) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowLong(m_hWnd, nIndex);}LONG_PTR GetWindowLongPtr(int nIndex) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowLongPtr(m_hWnd, nIndex);}LONG SetWindowLong(int nIndex, LONG dwNewLong) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowLong(m_hWnd, nIndex, dwNewLong);}LONG_PTR SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowLongPtr(m_hWnd, nIndex, dwNewLong);}WORD GetWindowWord(int nIndex) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowWord(m_hWnd, nIndex);}WORD SetWindowWord(int nIndex, WORD wNewWord) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowWord(m_hWnd, nIndex, wNewWord);}// Message FunctionsLRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SendMessage(m_hWnd,message,wParam,lParam);}BOOL PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::PostMessage(m_hWnd,message,wParam,lParam);}BOOL SendNotifyMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SendNotifyMessage(m_hWnd, message, wParam, lParam);}// support for C style macrosstatic LRESULT SendMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) throw(){ATLASSERT(::IsWindow(hWnd));return ::SendMessage(hWnd, message, wParam, lParam);}// Window Text FunctionsBOOL SetWindowText(LPCTSTR lpszString) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowText(m_hWnd, lpszString);}int GetWindowText(_Out_z_cap_post_count_(nMaxCount, return + 1) LPTSTR lpszStringBuf, _In_ int nMaxCount) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowText(m_hWnd, lpszStringBuf, nMaxCount);}int GetWindowText(CSimpleString& strText) const{int nLength;LPTSTR pszText;nLength = GetWindowTextLength();pszText = strText.GetBuffer(nLength+1);nLength = GetWindowText(pszText, nLength+1);strText.ReleaseBuffer(nLength);return nLength;}int GetWindowTextLength() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowTextLength(m_hWnd);}// Font Functionsvoid SetFont(HFONT hFont, BOOL bRedraw = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));::SendMessage(m_hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));}HFONT GetFont() const throw(){ATLASSERT(::IsWindow(m_hWnd));return (HFONT)::SendMessage(m_hWnd, WM_GETFONT, 0, 0);}// Menu Functions (non-child windows only)HMENU GetMenu() const throw(){ATLASSERT(::IsWindow(m_hWnd));return (HMENU)::GetMenu(m_hWnd);}BOOL SetMenu(HMENU hMenu) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetMenu(m_hWnd, hMenu);}BOOL DrawMenuBar() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::DrawMenuBar(m_hWnd);}HMENU GetSystemMenu(BOOL bRevert) const throw(){ATLASSERT(::IsWindow(m_hWnd));return (HMENU)::GetSystemMenu(m_hWnd, bRevert);}BOOL HiliteMenuItem(HMENU hMenu, UINT uItemHilite, UINT uHilite) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::HiliteMenuItem(m_hWnd, hMenu, uItemHilite, uHilite);}// Window Size and Position FunctionsBOOL IsIconic() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsIconic(m_hWnd);}BOOL IsZoomed() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsZoomed(m_hWnd);}BOOL MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);}BOOL MoveWindow(LPCRECT lpRect, BOOL bRepaint = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::MoveWindow(m_hWnd, lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, bRepaint);}BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowPos(m_hWnd, hWndInsertAfter, x, y, cx, cy, nFlags);}BOOL SetWindowPos(HWND hWndInsertAfter, LPCRECT lpRect, UINT nFlags) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowPos(m_hWnd, hWndInsertAfter, lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, nFlags);}UINT ArrangeIconicWindows() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ArrangeIconicWindows(m_hWnd);}BOOL BringWindowToTop() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::BringWindowToTop(m_hWnd);}BOOL GetWindowRect(LPRECT lpRect) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowRect(m_hWnd, lpRect);}BOOL GetClientRect(LPRECT lpRect) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetClientRect(m_hWnd, lpRect);}BOOL GetWindowPlacement(WINDOWPLACEMENT FAR* lpwndpl) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowPlacement(m_hWnd, lpwndpl);}BOOL SetWindowPlacement(const WINDOWPLACEMENT FAR* lpwndpl) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowPlacement(m_hWnd, lpwndpl);}// Coordinate Mapping FunctionsBOOL ClientToScreen(LPPOINT lpPoint) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ClientToScreen(m_hWnd, lpPoint);}BOOL ClientToScreen(LPRECT lpRect) const throw(){ATLASSERT(::IsWindow(m_hWnd));if(!::ClientToScreen(m_hWnd, (LPPOINT)lpRect))return FALSE;return ::ClientToScreen(m_hWnd, ((LPPOINT)lpRect)+1);}BOOL ScreenToClient(LPPOINT lpPoint) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ScreenToClient(m_hWnd, lpPoint);}BOOL ScreenToClient(LPRECT lpRect) const throw(){ATLASSERT(::IsWindow(m_hWnd));if(!::ScreenToClient(m_hWnd, (LPPOINT)lpRect))return FALSE;return ::ScreenToClient(m_hWnd, ((LPPOINT)lpRect)+1);}int MapWindowPoints(HWND hWndTo, LPPOINT lpPoint, UINT nCount) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::MapWindowPoints(m_hWnd, hWndTo, lpPoint, nCount);}int MapWindowPoints(HWND hWndTo, LPRECT lpRect) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::MapWindowPoints(m_hWnd, hWndTo, (LPPOINT)lpRect, 2);}// Update and Painting FunctionsHDC BeginPaint(LPPAINTSTRUCT lpPaint) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::BeginPaint(m_hWnd, lpPaint);}void EndPaint(LPPAINTSTRUCT lpPaint) throw(){ATLASSERT(::IsWindow(m_hWnd));::EndPaint(m_hWnd, lpPaint);}HDC GetDC() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetDC(m_hWnd);}HDC GetWindowDC() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowDC(m_hWnd);}int ReleaseDC(HDC hDC) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ReleaseDC(m_hWnd, hDC);}void Print(HDC hDC, DWORD dwFlags) const throw(){ATLASSERT(::IsWindow(m_hWnd));::SendMessage(m_hWnd, WM_PRINT, (WPARAM)hDC, dwFlags);}void PrintClient(HDC hDC, DWORD dwFlags) const throw(){ATLASSERT(::IsWindow(m_hWnd));::SendMessage(m_hWnd, WM_PRINTCLIENT, (WPARAM)hDC, dwFlags);}BOOL UpdateWindow() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::UpdateWindow(m_hWnd);}void SetRedraw(BOOL bRedraw = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));::SendMessage(m_hWnd, WM_SETREDRAW, (WPARAM)bRedraw, 0);}BOOL GetUpdateRect(LPRECT lpRect, BOOL bErase = FALSE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetUpdateRect(m_hWnd, lpRect, bErase);}int GetUpdateRgn(HRGN hRgn, BOOL bErase = FALSE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetUpdateRgn(m_hWnd, hRgn, bErase);}BOOL Invalidate(BOOL bErase = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::InvalidateRect(m_hWnd, NULL, bErase);}BOOL InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::InvalidateRect(m_hWnd, lpRect, bErase);}BOOL ValidateRect(LPCRECT lpRect) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ValidateRect(m_hWnd, lpRect);}void InvalidateRgn(HRGN hRgn, BOOL bErase = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));::InvalidateRgn(m_hWnd, hRgn, bErase);}BOOL ValidateRgn(HRGN hRgn) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ValidateRgn(m_hWnd, hRgn);}BOOL ShowWindow(int nCmdShow) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ShowWindow(m_hWnd, nCmdShow);}BOOL IsWindowVisible() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsWindowVisible(m_hWnd);}BOOL ShowOwnedPopups(BOOL bShow = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ShowOwnedPopups(m_hWnd, bShow);}HDC GetDCEx(HRGN hRgnClip, DWORD flags) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetDCEx(m_hWnd, hRgnClip, flags);}BOOL LockWindowUpdate(BOOL bLock = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::LockWindowUpdate(bLock ? m_hWnd : NULL);}BOOL RedrawWindow(LPCRECT lpRectUpdate = NULL, HRGN hRgnUpdate = NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::RedrawWindow(m_hWnd, lpRectUpdate, hRgnUpdate, flags);}// Timer FunctionsUINT_PTR SetTimer(UINT_PTR nIDEvent, UINT nElapse, void (CALLBACK* lpfnTimer)(HWND, UINT, UINT_PTR, DWORD) = NULL) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetTimer(m_hWnd, nIDEvent, nElapse, (TIMERPROC)lpfnTimer);}BOOL KillTimer(UINT_PTR nIDEvent) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::KillTimer(m_hWnd, nIDEvent);}// Window State FunctionsBOOL IsWindowEnabled() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsWindowEnabled(m_hWnd);}BOOL EnableWindow(BOOL bEnable = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::EnableWindow(m_hWnd, bEnable);}HWND SetActiveWindow() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetActiveWindow(m_hWnd);}HWND SetCapture() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetCapture(m_hWnd);}HWND SetFocus() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetFocus(m_hWnd);}// Dialog-Box Item FunctionsBOOL CheckDlgButton(int nIDButton, UINT nCheck) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::CheckDlgButton(m_hWnd, nIDButton, nCheck);}BOOL CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::CheckRadioButton(m_hWnd, nIDFirstButton, nIDLastButton, nIDCheckButton);}int DlgDirList(_Inout_z_ LPTSTR lpPathSpec, _In_ int nIDListBox, _In_ int nIDStaticPath, _In_ UINT nFileType) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::DlgDirList(m_hWnd, lpPathSpec, nIDListBox, nIDStaticPath, nFileType);}int DlgDirListComboBox(_Inout_z_ LPTSTR lpPathSpec, _In_ int nIDComboBox, _In_ int nIDStaticPath, _In_ UINT nFileType) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::DlgDirListComboBox(m_hWnd, lpPathSpec, nIDComboBox, nIDStaticPath, nFileType);}BOOL DlgDirSelect(_Out_z_cap_(nCount) LPTSTR lpString, _In_ int nCount, _In_ int nIDListBox) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::DlgDirSelectEx(m_hWnd, lpString, nCount, nIDListBox);}BOOL DlgDirSelectComboBox(_Out_z_cap_(nCount) LPTSTR lpString, _In_ int nCount, _In_ int nIDComboBox) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::DlgDirSelectComboBoxEx(m_hWnd, lpString, nCount, nIDComboBox);}UINT GetDlgItemInt(int nID, BOOL* lpTrans = NULL, BOOL bSigned = TRUE) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetDlgItemInt(m_hWnd, nID, lpTrans, bSigned);}UINT GetDlgItemText(_In_ int nID, _Out_z_cap_post_count_(nMaxCount, return + 1) LPTSTR lpStr, _In_ int nMaxCount) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetDlgItemText(m_hWnd, nID, lpStr, nMaxCount);}UINT GetDlgItemText(int nID, CSimpleString& strText) const{HWND hItem;ATLASSERT(::IsWindow(m_hWnd));hItem = GetDlgItem(nID);if (hItem != NULL){int nLength;LPTSTR pszText;nLength = ::GetWindowTextLength(hItem);pszText = strText.GetBuffer(nLength+1);nLength = ::GetWindowText(hItem, pszText, nLength+1);strText.ReleaseBuffer(nLength);return nLength;}else{strText.Empty();return 0;}}#ifdef _OLEAUTO_H_BOOL GetDlgItemText(int nID, BSTR& bstrText) const throw(){ATLASSERT(::IsWindow(m_hWnd));HWND hWndCtl = GetDlgItem(nID);if(hWndCtl == NULL)return FALSE;return CWindow(hWndCtl).GetWindowText(bstrText);}#endif // _OLEAUTO_H_CWindow GetNextDlgGroupItem(HWND hWndCtl, BOOL bPrevious = FALSE) const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::GetNextDlgGroupItem(m_hWnd, hWndCtl, bPrevious));}CWindow GetNextDlgTabItem(HWND hWndCtl, BOOL bPrevious = FALSE) const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::GetNextDlgTabItem(m_hWnd, hWndCtl, bPrevious));}UINT IsDlgButtonChecked(int nIDButton) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsDlgButtonChecked(m_hWnd, nIDButton);}LRESULT SendDlgItemMessage(int nID, UINT message, WPARAM wParam = 0, LPARAM lParam = 0) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SendDlgItemMessage(m_hWnd, nID, message, wParam, lParam);}BOOL SetDlgItemInt(int nID, UINT nValue, BOOL bSigned = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetDlgItemInt(m_hWnd, nID, nValue, bSigned);}BOOL SetDlgItemText(int nID, LPCTSTR lpszString) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetDlgItemText(m_hWnd, nID, lpszString);}#ifndef _ATL_NO_HOSTINGHRESULT GetDlgControl(int nID, REFIID iid, void** ppCtrl) throw(){ATLASSERT(::IsWindow(m_hWnd));ATLASSERT(ppCtrl != NULL);if (ppCtrl == NULL)return E_POINTER;*ppCtrl = NULL;HRESULT hr = HRESULT_FROM_WIN32(ERROR_CONTROL_ID_NOT_FOUND);HWND hWndCtrl = GetDlgItem(nID);if (hWndCtrl != NULL){*ppCtrl = NULL;CComPtr<IUnknown> spUnk;hr = AtlAxGetControl(hWndCtrl, &spUnk);if (SUCCEEDED(hr))hr = spUnk->QueryInterface(iid, ppCtrl);}return hr;}HRESULT GetDlgHost(int nID, REFIID iid, void** ppHost) throw(){ATLASSERT(::IsWindow(m_hWnd));ATLASSERT(ppHost != NULL);if (ppHost == NULL)return E_POINTER;*ppHost = NULL;HRESULT hr = HRESULT_FROM_WIN32(ERROR_CONTROL_ID_NOT_FOUND);HWND hWndCtrl = GetDlgItem(nID);if (hWndCtrl != NULL){CComPtr<IUnknown> spUnk;hr = AtlAxGetHost(hWndCtrl, &spUnk);if (SUCCEEDED(hr))hr = spUnk->QueryInterface(iid, ppHost);}return hr;}#endif //!_ATL_NO_HOSTING// Scrolling Functionsint GetScrollPos(int nBar) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetScrollPos(m_hWnd, nBar);}BOOL GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetScrollRange(m_hWnd, nBar, lpMinPos, lpMaxPos);}BOOL ScrollWindow(int xAmount, int yAmount, LPCRECT lpRect = NULL, LPCRECT lpClipRect = NULL) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ScrollWindow(m_hWnd, xAmount, yAmount, lpRect, lpClipRect);}int ScrollWindowEx(int dx, int dy, LPCRECT lpRectScroll, LPCRECT lpRectClip, HRGN hRgnUpdate, LPRECT lpRectUpdate, UINT uFlags) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ScrollWindowEx(m_hWnd, dx, dy, lpRectScroll, lpRectClip, hRgnUpdate, lpRectUpdate, uFlags);}int ScrollWindowEx(int dx, int dy, UINT uFlags, LPCRECT lpRectScroll = NULL, LPCRECT lpRectClip = NULL, HRGN hRgnUpdate = NULL, LPRECT lpRectUpdate = NULL) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ScrollWindowEx(m_hWnd, dx, dy, lpRectScroll, lpRectClip, hRgnUpdate, lpRectUpdate, uFlags);}int SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetScrollPos(m_hWnd, nBar, nPos, bRedraw);}BOOL SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetScrollRange(m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);}BOOL ShowScrollBar(UINT nBar, BOOL bShow = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ShowScrollBar(m_hWnd, nBar, bShow);}BOOL EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::EnableScrollBar(m_hWnd, uSBFlags, uArrowFlags);}// Window Access FunctionsCWindow ChildWindowFromPoint(POINT point) const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::ChildWindowFromPoint(m_hWnd, point));}CWindow ChildWindowFromPointEx(POINT point, UINT uFlags) const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::ChildWindowFromPointEx(m_hWnd, point, uFlags));}CWindow GetTopWindow() const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::GetTopWindow(m_hWnd));}CWindow GetWindow(UINT nCmd) const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::GetWindow(m_hWnd, nCmd));}CWindow GetLastActivePopup() const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::GetLastActivePopup(m_hWnd));}BOOL IsChild(HWND hWnd) const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsChild(m_hWnd, hWnd);}CWindow GetParent() const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::GetParent(m_hWnd));}CWindow SetParent(HWND hWndNewParent) throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::SetParent(m_hWnd, hWndNewParent));}// Window Tree Accessint GetDlgCtrlID() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetDlgCtrlID(m_hWnd);}int SetDlgCtrlID(int nID) throw(){ATLASSERT(::IsWindow(m_hWnd));return (int)::SetWindowLong(m_hWnd, GWL_ID, nID);}CWindow GetDlgItem(int nID) const throw(){ATLASSERT(::IsWindow(m_hWnd));return CWindow(::GetDlgItem(m_hWnd, nID));}// Alert FunctionsBOOL FlashWindow(BOOL bInvert) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::FlashWindow(m_hWnd, bInvert);}int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption = _T(""), UINT nType = MB_OK) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::MessageBox(m_hWnd, lpszText, lpszCaption, nType);}// Clipboard FunctionsBOOL ChangeClipboardChain(HWND hWndNewNext) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ChangeClipboardChain(m_hWnd, hWndNewNext);}HWND SetClipboardViewer() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetClipboardViewer(m_hWnd);}BOOL OpenClipboard() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::OpenClipboard(m_hWnd);}// Caret FunctionsBOOL CreateCaret(HBITMAP hBitmap) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::CreateCaret(m_hWnd, hBitmap, 0, 0);}BOOL CreateSolidCaret(int nWidth, int nHeight) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::CreateCaret(m_hWnd, (HBITMAP)0, nWidth, nHeight);}BOOL CreateGrayCaret(int nWidth, int nHeight) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::CreateCaret(m_hWnd, (HBITMAP)1, nWidth, nHeight);}BOOL HideCaret() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::HideCaret(m_hWnd);}BOOL ShowCaret() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ShowCaret(m_hWnd);}#ifdef _INC_SHELLAPI// Drag-Drop Functionsvoid DragAcceptFiles(BOOL bAccept = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd)); ::DragAcceptFiles(m_hWnd, bAccept);}#endif// Icon FunctionsHICON SetIcon(HICON hIcon, BOOL bBigIcon = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return (HICON)::SendMessage(m_hWnd, WM_SETICON, bBigIcon, (LPARAM)hIcon);}HICON GetIcon(BOOL bBigIcon = TRUE) const throw(){ATLASSERT(::IsWindow(m_hWnd));return (HICON)::SendMessage(m_hWnd, WM_GETICON, bBigIcon, 0);}// Help FunctionsBOOL WinHelp(LPCTSTR lpszHelp, UINT nCmd = HELP_CONTEXT, DWORD dwData = 0) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::WinHelp(m_hWnd, lpszHelp, nCmd, dwData);}BOOL SetWindowContextHelpId(DWORD dwContextHelpId) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowContextHelpId(m_hWnd, dwContextHelpId);}DWORD GetWindowContextHelpId() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowContextHelpId(m_hWnd);}// Hot Key Functionsint SetHotKey(WORD wVirtualKeyCode, WORD wModifiers) throw(){ATLASSERT(::IsWindow(m_hWnd));return (int)::SendMessage(m_hWnd, WM_SETHOTKEY, MAKEWORD(wVirtualKeyCode, wModifiers), 0);}DWORD GetHotKey() const throw(){ATLASSERT(::IsWindow(m_hWnd));return (DWORD)::SendMessage(m_hWnd, WM_GETHOTKEY, 0, 0);}// Misc. Operations//N newBOOL GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetScrollInfo(m_hWnd, nBar, lpScrollInfo);}int SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetScrollInfo(m_hWnd, nBar, lpScrollInfo, bRedraw);}BOOL IsDialogMessage(LPMSG lpMsg) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsDialogMessage(m_hWnd, lpMsg);}void NextDlgCtrl() const throw(){ATLASSERT(::IsWindow(m_hWnd));::SendMessage(m_hWnd, WM_NEXTDLGCTL, 0, 0L);}void PrevDlgCtrl() const throw(){ATLASSERT(::IsWindow(m_hWnd));::SendMessage(m_hWnd, WM_NEXTDLGCTL, 1, 0L);}void GotoDlgCtrl(HWND hWndCtrl) const throw(){ATLASSERT(::IsWindow(m_hWnd));::SendMessage(m_hWnd, WM_NEXTDLGCTL, (WPARAM)hWndCtrl, 1L);}BOOL ResizeClient(int nWidth, int nHeight, BOOL bRedraw = TRUE) throw(){ATLASSERT(::IsWindow(m_hWnd));RECT rcWnd;if(!GetClientRect(&rcWnd))return FALSE;if(nWidth != -1)rcWnd.right = nWidth;if(nHeight != -1)rcWnd.bottom = nHeight;if(!::AdjustWindowRectEx(&rcWnd, GetStyle(), (!(GetStyle() & WS_CHILD) && (GetMenu() != NULL)), GetExStyle()))return FALSE;UINT uFlags = SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE;if(!bRedraw)uFlags |= SWP_NOREDRAW;return SetWindowPos(NULL, 0, 0, rcWnd.right - rcWnd.left, rcWnd.bottom - rcWnd.top, uFlags);}int GetWindowRgn(HRGN hRgn) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowRgn(m_hWnd, hRgn);}int SetWindowRgn(HRGN hRgn, BOOL bRedraw = FALSE) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::SetWindowRgn(m_hWnd, hRgn, bRedraw);}HDWP DeferWindowPos(HDWP hWinPosInfo, HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT uFlags) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::DeferWindowPos(hWinPosInfo, m_hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);}DWORD GetWindowThreadID() throw(){ATLASSERT(::IsWindow(m_hWnd));return ::GetWindowThreadProcessId(m_hWnd, NULL);}DWORD GetWindowProcessID() throw(){ATLASSERT(::IsWindow(m_hWnd));DWORD dwProcessID;::GetWindowThreadProcessId(m_hWnd, &dwProcessID);return dwProcessID;}BOOL IsWindow() const throw(){return ::IsWindow(m_hWnd);}BOOL IsWindowUnicode() const throw(){ATLASSERT(::IsWindow(m_hWnd));return ::IsWindowUnicode(m_hWnd);}BOOL IsParentDialog() throw(){ATLASSERT(::IsWindow(m_hWnd));TCHAR szBuf[8]; // "#32770" + NUL characterif (GetClassName(GetParent(), szBuf, sizeof(szBuf)/sizeof(szBuf[0])) == 0)return FALSE;return lstrcmp(szBuf, _T("#32770")) == 0;}BOOL ShowWindowAsync(int nCmdShow) throw(){ATLASSERT(::IsWindow(m_hWnd));return ::ShowWindowAsync(m_hWnd, nCmdShow);}CWindow GetDescendantWindow(int nID) const throw(){ATLASSERT(::IsWindow(m_hWnd));// GetDlgItem recursive (return first found)// breadth-first for 1 level, then depth-first for next level// use GetDlgItem since it is a fast USER functionHWND hWndChild, hWndTmp;if((hWndChild = ::GetDlgItem(m_hWnd, nID)) != NULL){if(::GetTopWindow(hWndChild) != NULL){// children with the same ID as their parent have priorityCWindow wnd(hWndChild);hWndTmp = wnd.GetDescendantWindow(nID);if(hWndTmp != NULL)return CWindow(hWndTmp);}return CWindow(hWndChild);}// walk each childfor(hWndChild = ::GetTopWindow(m_hWnd); hWndChild != NULL;hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT)){CWindow wnd(hWndChild);hWndTmp = wnd.GetDescendantWindow(nID);if(hWndTmp != NULL)return CWindow(hWndTmp);}return CWindow(NULL);    // not found}void SendMessageToDescendants(UINT message, WPARAM wParam = 0, LPARAM lParam = 0, BOOL bDeep = TRUE) throw(){for(HWND hWndChild = ::GetTopWindow(m_hWnd); hWndChild != NULL;hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT)){::SendMessage(hWndChild, message, wParam, lParam);if(bDeep && ::GetTopWindow(hWndChild) != NULL){// send to child windows after parentCWindow wnd(hWndChild);wnd.SendMessageToDescendants(message, wParam, lParam, bDeep);}}}BOOL CenterWindow(HWND hWndCenter = NULL) throw(){ATLASSERT(::IsWindow(m_hWnd));// determine owner window to center againstDWORD dwStyle = GetStyle();if(hWndCenter == NULL){if(dwStyle & WS_CHILD)hWndCenter = ::GetParent(m_hWnd);elsehWndCenter = ::GetWindow(m_hWnd, GW_OWNER);}// get coordinates of the window relative to its parentRECT rcDlg;::GetWindowRect(m_hWnd, &rcDlg);RECT rcArea;RECT rcCenter;HWND hWndParent;if(!(dwStyle & WS_CHILD)){// don't center against invisible or minimized windowsif(hWndCenter != NULL){DWORD dwStyleCenter = ::GetWindowLong(hWndCenter, GWL_STYLE);if(!(dwStyleCenter & WS_VISIBLE) || (dwStyleCenter & WS_MINIMIZE))hWndCenter = NULL;}// center within screen coordinates#if WINVER < 0x0500::SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL);#elseHMONITOR hMonitor = NULL;if(hWndCenter != NULL){hMonitor = ::MonitorFromWindow(hWndCenter, MONITOR_DEFAULTTONEAREST);}else{hMonitor = ::MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);}ATLENSURE_RETURN_VAL(hMonitor != NULL, FALSE);MONITORINFO minfo;minfo.cbSize = sizeof(MONITORINFO);BOOL bResult = ::GetMonitorInfo(hMonitor, &minfo);ATLENSURE_RETURN_VAL(bResult, FALSE);rcArea = minfo.rcWork;#endifif(hWndCenter == NULL)rcCenter = rcArea;else::GetWindowRect(hWndCenter, &rcCenter);}else{// center within parent client coordinateshWndParent = ::GetParent(m_hWnd);ATLASSERT(::IsWindow(hWndParent));::GetClientRect(hWndParent, &rcArea);ATLASSERT(::IsWindow(hWndCenter));::GetClientRect(hWndCenter, &rcCenter);::MapWindowPoints(hWndCenter, hWndParent, (POINT*)&rcCenter, 2);}int DlgWidth = rcDlg.right - rcDlg.left;int DlgHeight = rcDlg.bottom - rcDlg.top;// find dialog's upper left based on rcCenterint xLeft = (rcCenter.left + rcCenter.right) / 2 - DlgWidth / 2;int yTop = (rcCenter.top + rcCenter.bottom) / 2 - DlgHeight / 2;// if the dialog is outside the screen, move it insideif(xLeft + DlgWidth > rcArea.right)xLeft = rcArea.right - DlgWidth;if(xLeft < rcArea.left)xLeft = rcArea.left;if(yTop + DlgHeight > rcArea.bottom)yTop = rcArea.bottom - DlgHeight;if(yTop < rcArea.top)yTop = rcArea.top;// map screen coordinates to child coordinatesreturn ::SetWindowPos(m_hWnd, NULL, xLeft, yTop, -1, -1,SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);}BOOL ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0) throw(){ATLASSERT(::IsWindow(m_hWnd));DWORD dwStyle = ::GetWindowLong(m_hWnd, GWL_STYLE);DWORD dwNewStyle = (dwStyle & ~dwRemove) | dwAdd;if(dwStyle == dwNewStyle)return FALSE;::SetWindowLong(m_hWnd, GWL_STYLE, dwNewStyle);if(nFlags != 0){::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0,SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | nFlags);}return TRUE;}BOOL ModifyStyleEx(DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0) throw(){ATLASSERT(::IsWindow(m_hWnd));DWORD dwStyle = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);DWORD dwNewStyle = (dwStyle & ~dwRemove) | dwAdd;if(dwStyle == dwNewStyle)return FALSE;::SetWindowLong(m_hWnd, GWL_EXSTYLE, dwNewStyle);if(nFlags != 0){::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0,SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | nFlags);}return TRUE;}#ifdef _OLEAUTO_H_BOOL GetWindowText(BSTR* pbstrText) throw(){return GetWindowText(*pbstrText);}BOOL GetWindowText(BSTR& bstrText) throw(){USES_CONVERSION_EX;ATLASSERT(::IsWindow(m_hWnd));::SysFreeString(bstrText);bstrText = NULL;int nLen = ::GetWindowTextLength(m_hWnd);CTempBuffer<TCHAR> lpszText;if(nLen>0){ATLTRY(lpszText.Allocate(nLen+1));if (lpszText == NULL){return FALSE;}if(!::GetWindowText(m_hWnd, lpszText, nLen+1)){return FALSE;}}bstrText = ::SysAllocString(T2OLE_EX_DEF(lpszText));#pragma warning(push)#pragma warning(disable:4068)#pragma prefast(push)#pragma prefast(disable:325, "We are deliberately checking if this has already been allocated")return nLen==0 ? TRUE : ((bstrText != NULL) ? TRUE : FALSE);#pragma prefast(pop)#pragma warning(pop)}#endif // _OLEAUTO_H_CWindow GetTopLevelParent() const throw(){ATLASSERT(::IsWindow(m_hWnd));HWND hWndParent = m_hWnd;HWND hWndTmp;while((hWndTmp = ::GetParent(hWndParent)) != NULL)hWndParent = hWndTmp;return CWindow(hWndParent);}CWindow GetTopLevelWindow() const throw(){ATLASSERT(::IsWindow(m_hWnd));HWND hWndParent;HWND hWndTmp = m_hWnd;do{hWndParent = hWndTmp;hWndTmp = (::GetWindowLong(hWndParent, GWL_STYLE) & WS_CHILD) ? ::GetParent(hWndParent) : ::GetWindow(hWndParent, GW_OWNER);}while(hWndTmp != NULL);return CWindow(hWndParent);}};


原创粉丝点击