CWindow

xiaoxiao2021-02-28  93

class CWindow { public: static RECT rcDefault; HWND m_hWnd; CWindow(_In_opt_ HWND hWnd = NULL) throw() : m_hWnd(hWnd) { } CWindow& operator=(_In_opt_ HWND hWnd) throw() { m_hWnd = hWnd; return *this; } static LPCTSTR GetWndClassName() throw() { return NULL; } void Attach(_In_opt_ 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( _In_opt_z_ LPCTSTR lpstrWndClass, _In_opt_ HWND hWndParent, _In_ _U_RECT rect = NULL, _In_opt_z_ LPCTSTR szWindowName = NULL, _In_ DWORD dwStyle = 0, _In_ DWORD dwExStyle = 0, _In_ _U_MENUorID MenuOrID = 0U, _In_opt_ 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; } // Attributes operator 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(_In_ int nIndex) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetWindowLong(m_hWnd, nIndex); } LONG_PTR GetWindowLongPtr(_In_ int nIndex) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetWindowLongPtr(m_hWnd, nIndex); } LONG SetWindowLong( _In_ int nIndex, _In_ LONG dwNewLong) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetWindowLong(m_hWnd, nIndex, dwNewLong); } LONG_PTR SetWindowLongPtr( _In_ int nIndex, _In_ LONG_PTR dwNewLong) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetWindowLongPtr(m_hWnd, nIndex, dwNewLong); } WORD GetWindowWord(_In_ int nIndex) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetWindowWord(m_hWnd, nIndex); } WORD SetWindowWord( _In_ int nIndex, _In_ WORD wNewWord) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetWindowWord(m_hWnd, nIndex, wNewWord); } // Message Functions LRESULT SendMessage( _In_ UINT message, _In_ WPARAM wParam = 0, _In_ LPARAM lParam = 0) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SendMessage(m_hWnd,message,wParam,lParam); } BOOL PostMessage( _In_ UINT message, _In_ WPARAM wParam = 0, _In_ LPARAM lParam = 0) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::PostMessage(m_hWnd,message,wParam,lParam); } BOOL SendNotifyMessage( _In_ UINT message, _In_ WPARAM wParam = 0, _In_ LPARAM lParam = 0) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SendNotifyMessage(m_hWnd, message, wParam, lParam); } // support for C style macros static LRESULT SendMessage( _In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam) throw() { ATLASSERT(::IsWindow(hWnd)); return ::SendMessage(hWnd, message, wParam, lParam); } // Window Text Functions BOOL SetWindowText(_In_z_ 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(_Inout_ 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 Functions void SetFont( _In_ HFONT hFont, _In_ 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(_In_ 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(_In_ BOOL bRevert) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return (HMENU)::GetSystemMenu(m_hWnd, bRevert); } BOOL HiliteMenuItem( _In_ HMENU hMenu, _In_ UINT uItemHilite, _In_ UINT uHilite) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::HiliteMenuItem(m_hWnd, hMenu, uItemHilite, uHilite); } // Window Size and Position Functions BOOL 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( _In_ int x, _In_ int y, _In_ int nWidth, _In_ int nHeight, _In_ BOOL bRepaint = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint); } BOOL MoveWindow( _In_ LPCRECT lpRect, _In_ 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( _In_opt_ HWND hWndInsertAfter, _In_ int x, _In_ int y, _In_ int cx, _In_ int cy, _In_ UINT nFlags) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetWindowPos(m_hWnd, hWndInsertAfter, x, y, cx, cy, nFlags); } BOOL SetWindowPos( _In_opt_ HWND hWndInsertAfter, _In_ LPCRECT lpRect, _In_ 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(_Out_ LPRECT lpRect) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetWindowRect(m_hWnd, lpRect); } BOOL GetClientRect(_Out_ LPRECT lpRect) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetClientRect(m_hWnd, lpRect); } BOOL GetWindowPlacement(_Out_ WINDOWPLACEMENT FAR* lpwndpl) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetWindowPlacement(m_hWnd, lpwndpl); } BOOL SetWindowPlacement(_In_ const WINDOWPLACEMENT FAR* lpwndpl) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetWindowPlacement(m_hWnd, lpwndpl); } // Coordinate Mapping Functions BOOL ClientToScreen(_Inout_ LPPOINT lpPoint) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ClientToScreen(m_hWnd, lpPoint); } BOOL ClientToScreen(_Inout_ 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(_Inout_ LPPOINT lpPoint) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ScreenToClient(m_hWnd, lpPoint); } BOOL ScreenToClient(_Inout_ 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( _In_ HWND hWndTo, _Inout_cap_(nCount) LPPOINT lpPoint, _In_ UINT nCount) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::MapWindowPoints(m_hWnd, hWndTo, lpPoint, nCount); } int MapWindowPoints( _In_ HWND hWndTo, _Inout_ LPRECT lpRect) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::MapWindowPoints(m_hWnd, hWndTo, (LPPOINT)lpRect, 2); } // Update and Painting Functions HDC BeginPaint(_Out_ LPPAINTSTRUCT lpPaint) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::BeginPaint(m_hWnd, lpPaint); } void EndPaint(_In_ 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(_In_ HDC hDC) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ReleaseDC(m_hWnd, hDC); } void Print( _In_ HDC hDC, _In_ DWORD dwFlags) const throw() { ATLASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, WM_PRINT, (WPARAM)hDC, dwFlags); } void PrintClient( _In_ HDC hDC, _In_ 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(_In_ BOOL bRedraw = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, WM_SETREDRAW, (WPARAM)bRedraw, 0); } BOOL GetUpdateRect( _In_opt_ LPRECT lpRect, _In_ BOOL bErase = FALSE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetUpdateRect(m_hWnd, lpRect, bErase); } int GetUpdateRgn( _In_ HRGN hRgn, _In_ BOOL bErase = FALSE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetUpdateRgn(m_hWnd, hRgn, bErase); } BOOL Invalidate(_In_ BOOL bErase = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::InvalidateRect(m_hWnd, NULL, bErase); } BOOL InvalidateRect( _In_opt_ LPCRECT lpRect, _In_ BOOL bErase = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::InvalidateRect(m_hWnd, lpRect, bErase); } BOOL ValidateRect(_In_opt_ LPCRECT lpRect) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ValidateRect(m_hWnd, lpRect); } void InvalidateRgn( _In_ HRGN hRgn, _In_ BOOL bErase = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); ::InvalidateRgn(m_hWnd, hRgn, bErase); } BOOL ValidateRgn(_In_opt_ HRGN hRgn) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ValidateRgn(m_hWnd, hRgn); } BOOL ShowWindow(_In_ 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(_In_ BOOL bShow = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ShowOwnedPopups(m_hWnd, bShow); } HDC GetDCEx( _In_ HRGN hRgnClip, _In_ DWORD flags) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetDCEx(m_hWnd, hRgnClip, flags); } BOOL LockWindowUpdate(_In_ BOOL bLock = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::LockWindowUpdate(bLock ? m_hWnd : NULL); } BOOL RedrawWindow( _In_opt_ LPCRECT lpRectUpdate = NULL, _In_opt_ HRGN hRgnUpdate = NULL, _In_ UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::RedrawWindow(m_hWnd, lpRectUpdate, hRgnUpdate, flags); } // Timer Functions UINT_PTR SetTimer( _In_ UINT_PTR nIDEvent, _In_ UINT nElapse, _In_opt_ void (CALLBACK* lpfnTimer)(HWND, UINT, UINT_PTR, DWORD) = NULL) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetTimer(m_hWnd, nIDEvent, nElapse, (TIMERPROC)lpfnTimer); } BOOL KillTimer(_In_ UINT_PTR nIDEvent) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::KillTimer(m_hWnd, nIDEvent); } // Window State Functions BOOL IsWindowEnabled() const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::IsWindowEnabled(m_hWnd); } BOOL EnableWindow(_In_ 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 Functions BOOL CheckDlgButton( _In_ int nIDButton, _In_ UINT nCheck) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::CheckDlgButton(m_hWnd, nIDButton, nCheck); } BOOL CheckRadioButton( _In_ int nIDFirstButton, _In_ int nIDLastButton, _In_ 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( _In_ int nID, _Out_opt_ BOOL* lpTrans = NULL, _In_ 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( _In_ int nID, _Inout_ CSimpleString& strText) const { ATLASSERT(::IsWindow(m_hWnd)); 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( _In_ int nID, _Inout_ _Deref_post_opt_z_ 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( _In_ HWND hWndCtl, _In_ BOOL bPrevious = FALSE) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return CWindow(::GetNextDlgGroupItem(m_hWnd, hWndCtl, bPrevious)); } CWindow GetNextDlgTabItem( _In_ HWND hWndCtl, _In_ BOOL bPrevious = FALSE) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return CWindow(::GetNextDlgTabItem(m_hWnd, hWndCtl, bPrevious)); } UINT IsDlgButtonChecked(_In_ int nIDButton) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::IsDlgButtonChecked(m_hWnd, nIDButton); } LRESULT SendDlgItemMessage( _In_ int nID, _In_ UINT message, _In_ WPARAM wParam = 0, _In_ LPARAM lParam = 0) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SendDlgItemMessage(m_hWnd, nID, message, wParam, lParam); } BOOL SetDlgItemInt( _In_ int nID, _In_ UINT nValue, _In_ BOOL bSigned = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetDlgItemInt(m_hWnd, nID, nValue, bSigned); } BOOL SetDlgItemText( _In_ int nID, _In_z_ LPCTSTR lpszString) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetDlgItemText(m_hWnd, nID, lpszString); } #ifndef _ATL_NO_HOSTING ATLPREFAST_SUPPRESS(6387) HRESULT GetDlgControl( _In_ int nID, _In_ REFIID iid, _Deref_out_ 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; } ATLPREFAST_UNSUPPRESS() ATLPREFAST_SUPPRESS(6387) HRESULT GetDlgHost( _In_ int nID, _In_ REFIID iid, _Deref_out_ 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; } ATLPREFAST_UNSUPPRESS() #endif //!_ATL_NO_HOSTING // Scrolling Functions int GetScrollPos(_In_ int nBar) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetScrollPos(m_hWnd, nBar); } BOOL GetScrollRange( _In_ int nBar, _Out_ LPINT lpMinPos, _Out_ LPINT lpMaxPos) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetScrollRange(m_hWnd, nBar, lpMinPos, lpMaxPos); } BOOL ScrollWindow( _In_ int xAmount, _In_ int yAmount, _In_opt_ LPCRECT lpRect = NULL, _In_opt_ LPCRECT lpClipRect = NULL) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ScrollWindow(m_hWnd, xAmount, yAmount, lpRect, lpClipRect); } int ScrollWindowEx( _In_ int dx, _In_ int dy, _In_opt_ LPCRECT lpRectScroll, _In_opt_ LPCRECT lpRectClip, _In_opt_ HRGN hRgnUpdate, _In_opt_ LPRECT lpRectUpdate, _In_ UINT uFlags) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ScrollWindowEx(m_hWnd, dx, dy, lpRectScroll, lpRectClip, hRgnUpdate, lpRectUpdate, uFlags); } int ScrollWindowEx( _In_ int dx, _In_ int dy, _In_ UINT uFlags, _In_opt_ LPCRECT lpRectScroll = NULL, _In_opt_ LPCRECT lpRectClip = NULL, _In_opt_ HRGN hRgnUpdate = NULL, _In_opt_ LPRECT lpRectUpdate = NULL) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ScrollWindowEx(m_hWnd, dx, dy, lpRectScroll, lpRectClip, hRgnUpdate, lpRectUpdate, uFlags); } int SetScrollPos( _In_ int nBar, _In_ int nPos, _In_ BOOL bRedraw = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetScrollPos(m_hWnd, nBar, nPos, bRedraw); } BOOL SetScrollRange( _In_ int nBar, _In_ int nMinPos, _In_ int nMaxPos, _In_ BOOL bRedraw = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetScrollRange(m_hWnd, nBar, nMinPos, nMaxPos, bRedraw); } BOOL ShowScrollBar( _In_ UINT nBar, _In_ BOOL bShow = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ShowScrollBar(m_hWnd, nBar, bShow); } BOOL EnableScrollBar( _In_ UINT uSBFlags, _In_ UINT uArrowFlags = ESB_ENABLE_BOTH) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::EnableScrollBar(m_hWnd, uSBFlags, uArrowFlags); } // Window Access Functions CWindow ChildWindowFromPoint(_In_ POINT point) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return CWindow(::ChildWindowFromPoint(m_hWnd, point)); } CWindow ChildWindowFromPointEx( _In_ POINT point, _In_ 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(_In_ 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(_In_ 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(_In_ HWND hWndNewParent) throw() { ATLASSERT(::IsWindow(m_hWnd)); return CWindow(::SetParent(m_hWnd, hWndNewParent)); } // Window Tree Access int GetDlgCtrlID() const throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetDlgCtrlID(m_hWnd); } int SetDlgCtrlID(_In_ int nID) throw() { ATLASSERT(::IsWindow(m_hWnd)); return (int)::SetWindowLong(m_hWnd, GWL_ID, nID); } CWindow GetDlgItem(_In_ int nID) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return CWindow(::GetDlgItem(m_hWnd, nID)); } // Alert Functions BOOL FlashWindow(_In_ BOOL bInvert) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::FlashWindow(m_hWnd, bInvert); } int MessageBox( _In_z_ LPCTSTR lpszText, _In_opt_z_ LPCTSTR lpszCaption = _T(""), _In_ UINT nType = MB_OK) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::MessageBox(m_hWnd, lpszText, lpszCaption, nType); } // Clipboard Functions BOOL ChangeClipboardChain(_In_ 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 Functions BOOL CreateCaret(_In_ HBITMAP hBitmap) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::CreateCaret(m_hWnd, hBitmap, 0, 0); } BOOL CreateSolidCaret(_In_ int nWidth, _In_ int nHeight) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::CreateCaret(m_hWnd, (HBITMAP)0, nWidth, nHeight); } BOOL CreateGrayCaret(_In_ int nWidth, _In_ 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 Functions void DragAcceptFiles(_In_ BOOL bAccept = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); ::DragAcceptFiles(m_hWnd, bAccept); } #endif // Icon Functions HICON SetIcon( _In_ HICON hIcon, _In_ BOOL bBigIcon = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return (HICON)::SendMessage(m_hWnd, WM_SETICON, bBigIcon, (LPARAM)hIcon); } HICON GetIcon(_In_ BOOL bBigIcon = TRUE) const throw() { ATLASSERT(::IsWindow(m_hWnd)); return (HICON)::SendMessage(m_hWnd, WM_GETICON, bBigIcon, 0); } // Help Functions BOOL WinHelp( _In_z_ LPCTSTR lpszHelp, _In_ UINT nCmd = HELP_CONTEXT, _In_ DWORD dwData = 0) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::WinHelp(m_hWnd, lpszHelp, nCmd, dwData); } BOOL SetWindowContextHelpId(_In_ 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 Functions int SetHotKey( _In_ WORD wVirtualKeyCode, _In_ 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 new BOOL GetScrollInfo( _In_ int nBar, _Out_ LPSCROLLINFO lpScrollInfo) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetScrollInfo(m_hWnd, nBar, lpScrollInfo); } int SetScrollInfo( _In_ int nBar, _In_ LPSCROLLINFO lpScrollInfo, _In_ BOOL bRedraw = TRUE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetScrollInfo(m_hWnd, nBar, lpScrollInfo, bRedraw); } BOOL IsDialogMessage(_In_ 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(_In_ HWND hWndCtrl) const throw() { ATLASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, WM_NEXTDLGCTL, (WPARAM)hWndCtrl, 1L); } BOOL ResizeClient( _In_ int nWidth, _In_ int nHeight, _In_ 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(_Out_ HRGN hRgn) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::GetWindowRgn(m_hWnd, hRgn); } int SetWindowRgn( _In_opt_ HRGN hRgn, _In_ BOOL bRedraw = FALSE) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::SetWindowRgn(m_hWnd, hRgn, bRedraw); } HDWP DeferWindowPos( _In_ HDWP hWinPosInfo, _In_ HWND hWndInsertAfter, _In_ int x, _In_ int y, _In_ int cx, _In_ int cy, _In_ 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 character if (GetClassName(GetParent(), szBuf, sizeof(szBuf)/sizeof(szBuf[0])) == 0) return FALSE; return lstrcmp(szBuf, _T("#32770")) == 0; } BOOL ShowWindowAsync(_In_ int nCmdShow) throw() { ATLASSERT(::IsWindow(m_hWnd)); return ::ShowWindowAsync(m_hWnd, nCmdShow); } CWindow GetDescendantWindow(_In_ 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 function HWND hWndChild, hWndTmp; if((hWndChild = ::GetDlgItem(m_hWnd, nID)) != NULL) { if(::GetTopWindow(hWndChild) != NULL) { // children with the same ID as their parent have priority CWindow wnd(hWndChild); hWndTmp = wnd.GetDescendantWindow(nID); if(hWndTmp != NULL) return CWindow(hWndTmp); } return CWindow(hWndChild); } // walk each child for(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( _In_ UINT message, _In_ WPARAM wParam = 0, _In_ LPARAM lParam = 0, _In_ 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 parent CWindow wnd(hWndChild); wnd.SendMessageToDescendants(message, wParam, lParam, bDeep); } } } BOOL CenterWindow(_In_ HWND hWndCenter = NULL) throw() { ATLASSERT(::IsWindow(m_hWnd)); // determine owner window to center against DWORD dwStyle = GetStyle(); if(hWndCenter == NULL) { if(dwStyle & WS_CHILD) hWndCenter = ::GetParent(m_hWnd); else hWndCenter = ::GetWindow(m_hWnd, GW_OWNER); } // get coordinates of the window relative to its parent RECT rcDlg; ::GetWindowRect(m_hWnd, &rcDlg); RECT rcArea; RECT rcCenter; HWND hWndParent; if(!(dwStyle & WS_CHILD)) { // don't center against invisible or minimized windows if(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); #else HMONITOR 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; #endif if(hWndCenter == NULL) rcCenter = rcArea; else ::GetWindowRect(hWndCenter, &rcCenter); } else { // center within parent client coordinates hWndParent = ::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 rcCenter int 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 inside if(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 coordinates return ::SetWindowPos(m_hWnd, NULL, xLeft, yTop, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); } BOOL ModifyStyle( _In_ DWORD dwRemove, _In_ DWORD dwAdd, _In_ 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( _In_ DWORD dwRemove, _In_ DWORD dwAdd, _In_ 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(_Inout_ _Deref_post_opt_z_ BSTR* pbstrText) throw() { return GetWindowText(*pbstrText); } BOOL GetWindowText(_Deref_out_opt_z_ 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)); return nLen==0 ? FALSE : ((bstrText != NULL) ? TRUE : FALSE); } #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); } };
转载请注明原文地址: https://www.6miu.com/read-73316.html

最新回复(0)