initial commit

This commit is contained in:
2025-09-01 20:47:58 +08:00
commit 12c51b5ddb
843 changed files with 475321 additions and 0 deletions
+1225
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+667
View File
@@ -0,0 +1,667 @@
// Windows Template Library - WTL version 10.0
// Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#ifndef __ATLDDX_H__
#define __ATLDDX_H__
#pragma once
#ifndef __ATLAPP_H__
#error atlddx.h requires atlapp.h to be included first
#endif
#include <float.h>
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CWinDataExchange<T>
namespace WTL
{
// Constants
#define DDX_LOAD FALSE
#define DDX_SAVE TRUE
// DDX map macros
#define BEGIN_DDX_MAP(thisClass) \
BOOL DoDataExchange(BOOL bSaveAndValidate = FALSE, UINT nCtlID = (UINT)-1) \
{ \
(bSaveAndValidate); \
(nCtlID);
#define DDX_TEXT(nID, var) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Text(nID, var, sizeof(var), bSaveAndValidate)) \
return FALSE; \
}
#define DDX_TEXT_LEN(nID, var, len) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Text(nID, var, sizeof(var), bSaveAndValidate, TRUE, len)) \
return FALSE; \
}
#define DDX_INT(nID, var) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Int(nID, var, TRUE, bSaveAndValidate)) \
return FALSE; \
}
#define DDX_INT_RANGE(nID, var, min, max) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Int(nID, var, TRUE, bSaveAndValidate, TRUE, min, max)) \
return FALSE; \
}
#define DDX_UINT(nID, var) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Int(nID, var, FALSE, bSaveAndValidate)) \
return FALSE; \
}
#define DDX_UINT_RANGE(nID, var, min, max) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Int(nID, var, FALSE, bSaveAndValidate, TRUE, min, max)) \
return FALSE; \
}
#define DDX_FLOAT(nID, var) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Float(nID, var, bSaveAndValidate)) \
return FALSE; \
}
#define DDX_FLOAT_RANGE(nID, var, min, max) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Float(nID, var, bSaveAndValidate, TRUE, min, max)) \
return FALSE; \
}
#define DDX_FLOAT_P(nID, var, precision) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Float(nID, var, bSaveAndValidate, FALSE, 0, 0, precision)) \
return FALSE; \
}
#define DDX_FLOAT_P_RANGE(nID, var, min, max, precision) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
{ \
if(!DDX_Float(nID, var, bSaveAndValidate, TRUE, min, max, precision)) \
return FALSE; \
}
#define DDX_CONTROL(nID, obj) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
DDX_Control(nID, obj, bSaveAndValidate);
#define DDX_CONTROL_HANDLE(nID, obj) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
DDX_Control_Handle(nID, obj, bSaveAndValidate);
#define DDX_CHECK(nID, var) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
DDX_Check(nID, var, bSaveAndValidate);
#define DDX_RADIO(nID, var) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
DDX_Radio(nID, var, bSaveAndValidate);
#define END_DDX_MAP() \
return TRUE; \
}
// DDX support for Tab, Combo, ListBox and ListView selection index
// Note: Specialized versions require atlctrls.h to be included first
#define DDX_INDEX(CtrlClass, nID, var) \
if((nCtlID == (UINT)-1) || (nCtlID == nID)) \
DDX_Index<CtrlClass>(nID, var, bSaveAndValidate);
#ifdef __ATLCTRLS_H__
#define DDX_TAB_INDEX(nID, var) DDX_INDEX(WTL::CTabCtrl, nID, var)
#define DDX_COMBO_INDEX(nID, var) DDX_INDEX(WTL::CComboBox, nID, var)
#define DDX_LISTBOX_INDEX(nID, var) DDX_INDEX(WTL::CListBox, nID, var)
#define DDX_LISTVIEW_INDEX(nID, var) DDX_INDEX(WTL::CListViewCtrl, nID, var)
#endif // __ATLCTRLS_H__
///////////////////////////////////////////////////////////////////////////////
// CWinDataExchange - provides support for DDX
template <class T>
class CWinDataExchange
{
public:
// Data exchange method - override in your derived class
BOOL DoDataExchange(BOOL /*bSaveAndValidate*/ = FALSE, UINT /*nCtlID*/ = (UINT)-1)
{
// this one should never be called, override it in
// your derived class by implementing DDX map
ATLASSERT(FALSE);
return FALSE;
}
// Helpers for validation error reporting
enum _XDataType
{
ddxDataNull = 0,
ddxDataText = 1,
ddxDataInt = 2,
ddxDataFloat = 3,
ddxDataDouble = 4
};
struct _XTextData
{
int nLength;
int nMaxLength;
};
struct _XIntData
{
long nVal;
long nMin;
long nMax;
};
struct _XFloatData
{
double nVal;
double nMin;
double nMax;
};
struct _XData
{
_XDataType nDataType;
union
{
_XTextData textData;
_XIntData intData;
_XFloatData floatData;
};
};
// Text exchange
BOOL DDX_Text(UINT nID, LPTSTR lpstrText, int cbSize, BOOL bSave, BOOL bValidate = FALSE, int nLength = 0)
{
T* pT = static_cast<T*>(this);
BOOL bSuccess = TRUE;
if(bSave)
{
HWND hWndCtrl = pT->GetDlgItem(nID);
int nRetLen = ::GetWindowText(hWndCtrl, lpstrText, cbSize / sizeof(TCHAR));
if(nRetLen < ::GetWindowTextLength(hWndCtrl))
bSuccess = FALSE;
}
else
{
ATLASSERT(!bValidate || (lstrlen(lpstrText) <= nLength));
bSuccess = pT->SetDlgItemText(nID, lpstrText);
}
if(!bSuccess)
{
pT->OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nLength > 0);
if(lstrlen(lpstrText) > nLength)
{
_XData data = { ddxDataText };
data.textData.nLength = lstrlen(lpstrText);
data.textData.nMaxLength = nLength;
pT->OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
BOOL DDX_Text(UINT nID, BSTR& bstrText, int /*cbSize*/, BOOL bSave, BOOL bValidate = FALSE, int nLength = 0)
{
T* pT = static_cast<T*>(this);
BOOL bSuccess = TRUE;
if(bSave)
{
bSuccess = pT->GetDlgItemText(nID, bstrText);
}
else
{
USES_CONVERSION;
LPTSTR lpstrText = OLE2T(bstrText);
ATLASSERT(!bValidate || (lstrlen(lpstrText) <= nLength));
bSuccess = pT->SetDlgItemText(nID, lpstrText);
}
if(!bSuccess)
{
pT->OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nLength > 0);
if((int)::SysStringLen(bstrText) > nLength)
{
_XData data = { ddxDataText };
data.textData.nLength = (int)::SysStringLen(bstrText);
data.textData.nMaxLength = nLength;
pT->OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
BOOL DDX_Text(UINT nID, ATL::CComBSTR& bstrText, int /*cbSize*/, BOOL bSave, BOOL bValidate = FALSE, int nLength = 0)
{
T* pT = static_cast<T*>(this);
BOOL bSuccess = TRUE;
if(bSave)
{
bSuccess = pT->GetDlgItemText(nID, (BSTR&)bstrText);
}
else
{
USES_CONVERSION;
LPTSTR lpstrText = OLE2T(bstrText);
ATLASSERT(!bValidate || (lstrlen(lpstrText) <= nLength));
bSuccess = pT->SetDlgItemText(nID, lpstrText);
}
if(!bSuccess)
{
pT->OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nLength > 0);
if((int)bstrText.Length() > nLength)
{
_XData data = { ddxDataText };
data.textData.nLength = (int)bstrText.Length();
data.textData.nMaxLength = nLength;
pT->OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
#ifdef __ATLSTR_H__
BOOL DDX_Text(UINT nID, ATL::CString& strText, int /*cbSize*/, BOOL bSave, BOOL bValidate = FALSE, int nLength = 0)
{
T* pT = static_cast<T*>(this);
BOOL bSuccess = TRUE;
if(bSave)
{
HWND hWndCtrl = pT->GetDlgItem(nID);
int nLen = ::GetWindowTextLength(hWndCtrl);
int nRetLen = -1;
LPTSTR lpstr = strText.GetBufferSetLength(nLen);
if(lpstr != NULL)
{
nRetLen = ::GetWindowText(hWndCtrl, lpstr, nLen + 1);
strText.ReleaseBuffer();
}
if(nRetLen < nLen)
bSuccess = FALSE;
}
else
{
bSuccess = pT->SetDlgItemText(nID, strText);
}
if(!bSuccess)
{
pT->OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nLength > 0);
if(strText.GetLength() > nLength)
{
_XData data = { ddxDataText };
data.textData.nLength = strText.GetLength();
data.textData.nMaxLength = nLength;
pT->OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
#endif // __ATLSTR_H__
// Numeric exchange
template <class Type>
BOOL DDX_Int(UINT nID, Type& nVal, BOOL bSigned, BOOL bSave, BOOL bValidate = FALSE, Type nMin = 0, Type nMax = 0)
{
T* pT = static_cast<T*>(this);
BOOL bSuccess = TRUE;
if(bSave)
{
nVal = (Type)pT->GetDlgItemInt(nID, &bSuccess, bSigned);
}
else
{
ATLASSERT(!bValidate || ((nVal >= nMin) && (nVal <= nMax)));
bSuccess = pT->SetDlgItemInt(nID, nVal, bSigned);
}
if(!bSuccess)
{
pT->OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nMin != nMax);
if((nVal < nMin) || (nVal > nMax))
{
_XData data = { ddxDataInt };
data.intData.nVal = (long)nVal;
data.intData.nMin = (long)nMin;
data.intData.nMax = (long)nMax;
pT->OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
// Float exchange
static BOOL _AtlSimpleFloatParse(LPCTSTR lpszText, double& d)
{
ATLASSERT(lpszText != NULL);
while ((*lpszText == _T(' ')) || (*lpszText == _T('\t')))
lpszText++;
TCHAR chFirst = lpszText[0];
d = _tcstod(lpszText, (LPTSTR*)&lpszText);
if ((d == 0.0) && (chFirst != _T('0')))
return FALSE; // could not convert
while ((*lpszText == _T(' ')) || (*lpszText == _T('\t')))
lpszText++;
if (*lpszText != _T('\0'))
return FALSE; // not terminated properly
return TRUE;
}
BOOL DDX_Float(UINT nID, float& nVal, BOOL bSave, BOOL bValidate = FALSE, float nMin = 0.F, float nMax = 0.F, int nPrecision = FLT_DIG)
{
T* pT = static_cast<T*>(this);
BOOL bSuccess = TRUE;
const int cchBuff = 32;
TCHAR szBuff[cchBuff] = {};
if(bSave)
{
pT->GetDlgItemText(nID, szBuff, cchBuff);
double d = 0;
if(_AtlSimpleFloatParse(szBuff, d))
nVal = (float)d;
else
bSuccess = FALSE;
}
else
{
ATLASSERT(!bValidate || ((nVal >= nMin) && (nVal <= nMax)));
_stprintf_s(szBuff, cchBuff, _T("%.*g"), nPrecision, nVal);
bSuccess = pT->SetDlgItemText(nID, szBuff);
}
if(!bSuccess)
{
pT->OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nMin != nMax);
if((nVal < nMin) || (nVal > nMax))
{
_XData data = { ddxDataFloat };
data.floatData.nVal = (double)nVal;
data.floatData.nMin = (double)nMin;
data.floatData.nMax = (double)nMax;
pT->OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
BOOL DDX_Float(UINT nID, double& nVal, BOOL bSave, BOOL bValidate = FALSE, double nMin = 0., double nMax = 0., int nPrecision = DBL_DIG)
{
T* pT = static_cast<T*>(this);
BOOL bSuccess = TRUE;
const int cchBuff = 32;
TCHAR szBuff[cchBuff] = {};
if(bSave)
{
pT->GetDlgItemText(nID, szBuff, cchBuff);
double d = 0;
if(_AtlSimpleFloatParse(szBuff, d))
nVal = d;
else
bSuccess = FALSE;
}
else
{
ATLASSERT(!bValidate || ((nVal >= nMin) && (nVal <= nMax)));
_stprintf_s(szBuff, cchBuff, _T("%.*g"), nPrecision, nVal);
bSuccess = pT->SetDlgItemText(nID, szBuff);
}
if(!bSuccess)
{
pT->OnDataExchangeError(nID, bSave);
}
else if(bSave && bValidate) // validation
{
ATLASSERT(nMin != nMax);
if((nVal < nMin) || (nVal > nMax))
{
_XData data = { ddxDataFloat };
data.floatData.nVal = nVal;
data.floatData.nMin = nMin;
data.floatData.nMax = nMax;
pT->OnDataValidateError(nID, bSave, data);
bSuccess = FALSE;
}
}
return bSuccess;
}
// Full control subclassing (for CWindowImpl derived controls)
template <class TControl>
void DDX_Control(UINT nID, TControl& ctrl, BOOL bSave)
{
if(!bSave && (ctrl.m_hWnd == NULL))
{
T* pT = static_cast<T*>(this);
ctrl.SubclassWindow(pT->GetDlgItem(nID));
}
}
// Simple control attaching (for HWND wrapper controls)
template <class TControl>
void DDX_Control_Handle(UINT nID, TControl& ctrl, BOOL bSave)
{
if(!bSave && (ctrl.m_hWnd == NULL))
{
T* pT = static_cast<T*>(this);
ctrl = pT->GetDlgItem(nID);
}
}
// Control state
void DDX_Check(UINT nID, int& nValue, BOOL bSave)
{
T* pT = static_cast<T*>(this);
HWND hWndCtrl = pT->GetDlgItem(nID);
if(bSave)
{
nValue = (int)::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L);
ATLASSERT((nValue >= 0) && (nValue <= 2));
}
else
{
if((nValue < 0) || (nValue > 2))
{
ATLTRACE2(atlTraceUI, 0, _T("ATL: Warning - dialog data checkbox value (%d) out of range.\n"), nValue);
nValue = 0; // default to off
}
::SendMessage(hWndCtrl, BM_SETCHECK, nValue, 0L);
}
}
// variant that supports bool (checked/not-checked, no intermediate state)
void DDX_Check(UINT nID, bool& bCheck, BOOL bSave)
{
int nValue = bCheck ? 1 : 0;
DDX_Check(nID, nValue, bSave);
if(bSave)
{
if(nValue == 2)
ATLTRACE2(atlTraceUI, 0, _T("ATL: Warning - checkbox state (%d) out of supported range.\n"), nValue);
bCheck = (nValue == 1);
}
}
void DDX_Radio(UINT nID, int& nValue, BOOL bSave)
{
T* pT = static_cast<T*>(this);
HWND hWndCtrl = pT->GetDlgItem(nID);
ATLASSERT(hWndCtrl != NULL);
// must be first in a group of auto radio buttons
ATLASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP);
ATLASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON);
if(bSave)
nValue = -1; // value if none found
// walk all children in group
int nButton = 0;
do
{
if(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON)
{
// control in group is a radio button
if(bSave)
{
if(::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0)
{
ATLASSERT(nValue == -1); // only set once
nValue = nButton;
}
}
else
{
// select button
::SendMessage(hWndCtrl, BM_SETCHECK, (nButton == nValue), 0L);
}
nButton++;
}
else
{
ATLTRACE2(atlTraceUI, 0, _T("ATL: Warning - skipping non-radio button in group.\n"));
}
hWndCtrl = ::GetWindow(hWndCtrl, GW_HWNDNEXT);
}
while ((hWndCtrl != NULL) && !(GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP));
}
// DDX support for Tab, Combo, ListBox and ListView selection index
template <class TCtrl>
INT _getSel(TCtrl& tCtrl)
{
return tCtrl.GetCurSel();
}
template <class TCtrl>
void _setSel(TCtrl& tCtrl, INT iSel)
{
if(iSel < 0)
tCtrl.SetCurSel(-1);
else
tCtrl.SetCurSel(iSel);
}
#ifdef __ATLCTRLS_H__
// ListViewCtrl specialization
template <>
INT _getSel(WTL::CListViewCtrl& tCtrl)
{
return tCtrl.GetSelectedIndex();
}
template <>
void _setSel(WTL::CListViewCtrl& tCtrl, INT iSel)
{
if(iSel < 0)
tCtrl.SelectItem(-1);
else
tCtrl.SelectItem(iSel);
}
#endif // __ATLCTRLS_H__
template <class TCtrl>
void DDX_Index(UINT nID, INT& nVal, BOOL bSave)
{
T* pT = static_cast<T*>(this);
TCtrl ctrl(pT->GetDlgItem(nID));
if(bSave)
nVal = _getSel(ctrl);
else
_setSel(ctrl, nVal);
}
// Overrideables
void OnDataExchangeError(UINT nCtrlID, BOOL /*bSave*/)
{
// Override to display an error message
::MessageBeep((UINT)-1);
T* pT = static_cast<T*>(this);
::SetFocus(pT->GetDlgItem(nCtrlID));
}
void OnDataValidateError(UINT nCtrlID, BOOL /*bSave*/, _XData& /*data*/)
{
// Override to display an error message
::MessageBeep((UINT)-1);
T* pT = static_cast<T*>(this);
::SetFocus(pT->GetDlgItem(nCtrlID));
}
};
} // namespace WTL
#endif // __ATLDDX_H__
File diff suppressed because it is too large Load Diff
+498
View File
@@ -0,0 +1,498 @@
// Windows Template Library - WTL version 10.0
// Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#ifndef __ATLDWM_H__
#define __ATLDWM_H__
#pragma once
#ifndef __ATLAPP_H__
#error atldwm.h requires atlapp.h to be included first
#endif
#ifndef __ATLWIN_H__
#error atldwm.h requires atlwin.h to be included first
#endif
#if (_WIN32_WINNT < 0x0600)
#error atldwm.h requires _WIN32_WINNT >= 0x0600
#endif
#ifndef _DWMAPI_H_
#include <dwmapi.h>
#endif
#pragma comment(lib, "dwmapi.lib")
// Note: To create an application that also runs on older versions of Windows,
// use delay load of dwmapi.dll and ensure that no calls to the DWM API are
// Delay load is NOT AUTOMATIC for VC++ 7, you have to link to delayimp.lib,
// and add dwmapi.dll in the Linker.Input.Delay Loaded DLLs section of the
// project properties.
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CDwm
// CDwmImpl<T, TBase>
// CDwmWindowT<TBase> - CDwmWindow
// CDwmThumbnailT<t_bManaged, TBase>
// CDwmThumbnail
// CDwmThumbnailHandle
// CAeroControlImpl
namespace WTL
{
///////////////////////////////////////////////////////////////////////////////
// CDwm - wrapper for DWM handle
class CDwm
{
public:
// Data members
static int m_nIsDwmSupported;
// Constructor
CDwm()
{
IsDwmSupported();
}
// Dwm support helper
static bool IsDwmSupported()
{
if(m_nIsDwmSupported == -1)
{
CStaticDataInitCriticalSectionLock lock;
if(FAILED(lock.Lock()))
{
ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CDwm::IsDwmSupported.\n"));
ATLASSERT(FALSE);
return false;
}
if(m_nIsDwmSupported == -1)
{
HMODULE hDwmDLL = ::LoadLibrary(_T("dwmapi.dll"));
m_nIsDwmSupported = (hDwmDLL != NULL) ? 1 : 0;
if(hDwmDLL != NULL)
::FreeLibrary(hDwmDLL);
}
lock.Unlock();
}
ATLASSERT(m_nIsDwmSupported != -1);
return (m_nIsDwmSupported == 1);
}
// Operations
BOOL DwmIsCompositionEnabled() const
{
if(!IsDwmSupported())
return FALSE;
BOOL bRes = FALSE;
return (SUCCEEDED(::DwmIsCompositionEnabled(&bRes)) && bRes) ? TRUE : FALSE;
}
BOOL DwmEnableComposition(UINT fEnable)
{
if(!IsDwmSupported())
return FALSE;
return SUCCEEDED(::DwmEnableComposition(fEnable)) ? TRUE : FALSE;
}
BOOL DwmEnableMMCSS(BOOL fEnableMMCSS)
{
if(!IsDwmSupported())
return FALSE;
return SUCCEEDED(::DwmEnableMMCSS(fEnableMMCSS)) ? TRUE : FALSE;
}
HRESULT DwmGetColorizationColor(DWORD* pcrColorization, BOOL* pfOpaqueBlend)
{
if(!IsDwmSupported())
return E_NOTIMPL;
return ::DwmGetColorizationColor(pcrColorization, pfOpaqueBlend);
}
HRESULT DwmFlush()
{
if(!IsDwmSupported())
return E_NOTIMPL;
return ::DwmFlush();
}
};
__declspec(selectany) int CDwm::m_nIsDwmSupported = -1;
///////////////////////////////////////////////////////////////////////////////
// CDwmImpl - DWM window support
template <class T, class TBase = CDwm>
class CDwmImpl : public TBase
{
public:
HRESULT DwmEnableBlurBehindWindow(const DWM_BLURBEHIND* pBB)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmEnableBlurBehindWindow(pT->m_hWnd, pBB);
}
HRESULT DwmExtendFrameIntoClientArea(const MARGINS* pMargins)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmExtendFrameIntoClientArea(pT->m_hWnd, pMargins);
}
HRESULT DwmExtendFrameIntoEntireClientArea()
{
MARGINS margins = { -1 };
return DwmExtendFrameIntoClientArea(&margins);
}
HRESULT DwmGetCompositionTimingInfo(DWM_TIMING_INFO* pTimingInfo)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmGetCompositionTimingInfo(pT->m_hWnd, pTimingInfo);
}
HRESULT DwmGetWindowAttribute(DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmGetWindowAttribute(pT->m_hWnd, dwAttribute, pvAttribute, cbAttribute);
}
HRESULT DwmModifyPreviousDxFrameDuration(INT cRefreshes, BOOL fRelative)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmModifyPreviousDxFrameDuration(pT->m_hWnd, cRefreshes, fRelative);
}
HRESULT DwmSetDxFrameDuration(INT cRefreshes)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmSetDxFrameDuration(pT->m_hWnd, cRefreshes);
}
HRESULT DwmSetPresentParameters(DWM_PRESENT_PARAMETERS* pPresentParams)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmSetPresentParameters(pT->m_hWnd, pPresentParams);
}
HRESULT DwmSetWindowAttribute(DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmSetWindowAttribute(pT->m_hWnd, dwAttribute, pvAttribute, cbAttribute);
}
HRESULT DwmAttachMilContent()
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmAttachMilContent(pT->m_hWnd);
}
HRESULT DwmDetachMilContent()
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));
return ::DwmDetachMilContent(pT->m_hWnd);
}
};
template <class TBase>
class CDwmWindowT : public TBase, public CDwmImpl<CDwmWindowT< TBase > >
{
public:
CDwmWindowT(HWND hWnd = NULL) : TBase(hWnd)
{ }
CDwmWindowT< TBase >& operator =(HWND hWnd)
{
this->m_hWnd = hWnd;
return *this;
}
};
typedef CDwmWindowT<ATL::CWindow> CDwmWindow;
///////////////////////////////////////////////////////////////////////////////
// CDwmThumbnail - provides DWM thumbnail support
template <bool t_bManaged, class TBase = CDwm>
class CDwmThumbnailT : public TBase
{
public:
// Data members
HTHUMBNAIL m_hThumbnail;
// Constructor
CDwmThumbnailT(HTHUMBNAIL hThumbnail = NULL) : m_hThumbnail(hThumbnail)
{ }
~CDwmThumbnailT()
{
if(t_bManaged && (m_hThumbnail != NULL))
Unregister();
}
// Operations
CDwmThumbnailT<t_bManaged, TBase>& operator =(HTHUMBNAIL hThumbnail)
{
Attach(hThumbnail);
return *this;
}
void Attach(HTHUMBNAIL hThumbnailNew)
{
if(t_bManaged && (m_hThumbnail != NULL) && (m_hThumbnail != hThumbnailNew))
Unregister();
m_hThumbnail = hThumbnailNew;
}
HTHUMBNAIL Detach()
{
HTHUMBNAIL hThumbnail = m_hThumbnail;
m_hThumbnail = NULL;
return hThumbnail;
}
HRESULT Register(HWND hwndDestination, HWND hwndSource)
{
ATLASSERT(::IsWindow(hwndDestination));
ATLASSERT(::IsWindow(hwndSource));
ATLASSERT(m_hThumbnail==NULL);
if(!this->IsDwmSupported())
return E_NOTIMPL;
return ::DwmRegisterThumbnail(hwndDestination, hwndSource, &m_hThumbnail);
}
HRESULT Unregister()
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
if(m_hThumbnail == NULL)
return S_FALSE;
HRESULT Hr = ::DwmUnregisterThumbnail(m_hThumbnail);
if(SUCCEEDED(Hr))
m_hThumbnail = NULL;
return Hr;
}
operator HTHUMBNAIL() const { return m_hThumbnail; }
bool IsNull() const { return (m_hThumbnail == NULL); }
HRESULT UpdateProperties(const DWM_THUMBNAIL_PROPERTIES* ptnProperties)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
ATLASSERT(m_hThumbnail != NULL);
return ::DwmUpdateThumbnailProperties(m_hThumbnail, ptnProperties);
}
// Attributes
HRESULT QuerySourceSize(PSIZE pSize)
{
if(!this->IsDwmSupported())
return E_NOTIMPL;
ATLASSERT(m_hThumbnail != NULL);
return ::DwmQueryThumbnailSourceSize(m_hThumbnail, pSize);
}
};
typedef CDwmThumbnailT<true, CDwm> CDwmThumbnail;
typedef CDwmThumbnailT<false, CDwm> CDwmThumbnailHandle;
#ifdef __ATLTHEME_H__
///////////////////////////////////////////////////////////////////////////////
// CAeroControlImpl - Base class for controls on Glass
template <class T, class TBase = ATL::CWindow, class TWinTraits = ATL::CControlWinTraits>
class CAeroControlImpl : public CThemeImpl<T>,
public CBufferedPaintImpl<T>,
public ATL::CWindowImpl<T, TBase, TWinTraits>
{
public:
typedef CThemeImpl<T> _themeClass;
typedef CBufferedPaintImpl<T> _baseClass;
typedef ATL::CWindowImpl<T, TBase, TWinTraits> _windowClass;
CAeroControlImpl()
{
this->m_PaintParams.dwFlags = BPPF_ERASE;
}
static LPCWSTR GetThemeName()
{
#ifdef _UNICODE
return TBase::GetWndClassName();
#else
ATLASSERT(!_T("Return UNICODE string of window classname / theme class"));
return NULL;
#endif // _UNICODE
}
// Message map and handlers
BEGIN_MSG_MAP(CAeroControlImpl)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_ACTIVATE, OnActivate)
CHAIN_MSG_MAP(_themeClass)
CHAIN_MSG_MAP(_baseClass)
END_MSG_MAP()
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
pT->Init();
bHandled = FALSE;
return 0;
}
LRESULT OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
if(this->IsThemingSupported())
this->Invalidate(FALSE);
bHandled = FALSE;
return 0;
}
// Operations
BOOL SubclassWindow(HWND hWnd)
{
ATLASSERT(this->m_hWnd == NULL);
ATLASSERT(::IsWindow(hWnd));
BOOL bRet = _windowClass::SubclassWindow(hWnd);
if(bRet)
{
T* pT = static_cast<T*>(this);
pT->Init();
}
return bRet;
}
// Implementation
LRESULT DefWindowProc()
{
const ATL::_ATL_MSG* pMsg = this->m_pCurrentMsg;
LRESULT lRes = 0;
if(pMsg != NULL)
lRes = DefWindowProc(pMsg->message, pMsg->wParam, pMsg->lParam);
return lRes;
}
LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
T* pT = static_cast<T*>(this);
LRESULT lRes = 0;
if(::DwmDefWindowProc(pT->m_hWnd, uMsg, wParam, lParam, &lRes) != FALSE)
return lRes;
return _windowClass::DefWindowProc(uMsg, wParam, lParam);
}
void DoBufferedPaint(HDC hDC, RECT& rcPaint)
{
T* pT = static_cast<T*>(this);
HDC hDCPaint = NULL;
RECT rcClient = {};
this->GetClientRect(&rcClient);
this->m_BufferedPaint.Begin(hDC, &rcClient, this->m_dwFormat, &this->m_PaintParams, &hDCPaint);
ATLASSERT(hDCPaint != NULL);
pT->DoAeroPaint(hDCPaint, rcClient, rcPaint);
this->m_BufferedPaint.End();
}
void DoPaint(HDC /*hdc*/, RECT& /*rcClient*/)
{
DefWindowProc();
}
// Overridables
void Init()
{
T* pT = static_cast<T*>(this);
(void)pT; // avoid level 4 warning
this->SetThemeClassList(pT->GetThemeName());
if(this->m_lpstrThemeClassList != NULL)
this->OpenThemeData();
}
void DoAeroPaint(HDC hDC, RECT& /*rcClient*/, RECT& rcPaint)
{
DefWindowProc(WM_PAINT, (WPARAM) hDC, 0L);
this->m_BufferedPaint.MakeOpaque(&rcPaint);
}
};
#endif // __ATLTHEME_H__
} // namespace WTL
#endif // __ATLDWM_H__
+885
View File
@@ -0,0 +1,885 @@
// Windows Template Library - WTL version 10.0
// Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#ifndef __ATLFIND_H__
#define __ATLFIND_H__
#pragma once
#ifndef __ATLCTRLS_H__
#error atlfind.h requires atlctrls.h to be included first
#endif
#ifndef __ATLDLGS_H__
#error atlfind.h requires atldlgs.h to be included first
#endif
#ifndef __ATLSTR_H__
#error atlfind.h requires CString
#endif
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CEditFindReplaceImplBase<T, TFindReplaceDialog>
// CEditFindReplaceImpl<T, TFindReplaceDialog>
// CRichEditFindReplaceImpl<T, TFindReplaceDialog>
namespace WTL
{
///////////////////////////////////////////////////////////////////////////////
// CEditFindReplaceImplBase - Base class for mixin classes that
// help implement Find/Replace for CEdit or CRichEditCtrl based window classes.
template <class T, class TFindReplaceDialog = CFindReplaceDialog>
class CEditFindReplaceImplBase
{
protected:
// Typedefs
typedef CEditFindReplaceImplBase<T, TFindReplaceDialog> thisClass;
// Enumerations
enum TranslationTextItem
{
eText_OnReplaceAllMessage = 0,
eText_OnReplaceAllTitle = 1,
eText_OnTextNotFoundMessage = 2,
eText_OnTextNotFoundTitle = 3
};
public:
// Data members
TFindReplaceDialog* m_pFindReplaceDialog;
ATL::CString m_sFindNext, m_sReplaceWith;
BOOL m_bFindOnly, m_bFirstSearch, m_bMatchCase, m_bWholeWord, m_bFindDown;
LONG m_nInitialSearchPos;
HCURSOR m_hOldCursor;
// Constructors
CEditFindReplaceImplBase() :
m_pFindReplaceDialog(NULL),
m_bFindOnly(TRUE),
m_bFirstSearch(TRUE),
m_bMatchCase(FALSE),
m_bWholeWord(FALSE),
m_bFindDown(TRUE),
m_nInitialSearchPos(0),
m_hOldCursor(NULL)
{
}
// Message Handlers
BEGIN_MSG_MAP(thisClass)
ALT_MSG_MAP(1)
MESSAGE_HANDLER(TFindReplaceDialog::GetFindReplaceMsg(), OnFindReplaceCmd)
COMMAND_ID_HANDLER(ID_EDIT_FIND, OnEditFind)
COMMAND_ID_HANDLER(ID_EDIT_REPEAT, OnEditRepeat)
COMMAND_ID_HANDLER(ID_EDIT_REPLACE, OnEditReplace)
END_MSG_MAP()
LRESULT OnFindReplaceCmd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
TFindReplaceDialog* pDialog = TFindReplaceDialog::GetNotifier(lParam);
if(pDialog == NULL)
{
ATLASSERT(FALSE);
::MessageBeep(MB_ICONERROR);
return 1;
}
ATLASSERT(pDialog == m_pFindReplaceDialog);
LPFINDREPLACE findReplace = (LPFINDREPLACE)lParam;
if((m_pFindReplaceDialog != NULL) && (findReplace != NULL))
{
if(pDialog->FindNext())
{
pT->OnFindNext(pDialog->GetFindString(), pDialog->SearchDown(),
pDialog->MatchCase(), pDialog->MatchWholeWord());
}
else if(pDialog->ReplaceCurrent())
{
pT->OnReplaceSel(pDialog->GetFindString(),
pDialog->SearchDown(), pDialog->MatchCase(), pDialog->MatchWholeWord(),
pDialog->GetReplaceString());
}
else if(pDialog->ReplaceAll())
{
pT->OnReplaceAll(pDialog->GetFindString(), pDialog->GetReplaceString(),
pDialog->MatchCase(), pDialog->MatchWholeWord());
}
else if(pDialog->IsTerminating())
{
// Dialog is going away (but hasn't gone away yet)
// OnFinalMessage will "delete this"
pT->OnTerminatingFindReplaceDialog(m_pFindReplaceDialog);
m_pFindReplaceDialog = NULL;
}
}
return 0;
}
LRESULT OnEditFind(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
pT->FindReplace(TRUE);
return 0;
}
LRESULT OnEditRepeat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
// If the user is holding down SHIFT when hitting F3, we'll
// search in reverse. Otherwise, we'll search forward.
// (be sure to have an accelerator mapped to ID_EDIT_REPEAT
// for both F3 and Shift+F3)
m_bFindDown = !((::GetKeyState(VK_SHIFT) & 0x8000) == 0x8000);
if(m_sFindNext.IsEmpty())
{
pT->FindReplace(TRUE);
}
else
{
if(!pT->FindTextSimple(m_sFindNext, m_bMatchCase, m_bWholeWord, m_bFindDown))
pT->TextNotFound(m_sFindNext);
}
return 0;
}
LRESULT OnEditReplace(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
DWORD style = pT->GetStyle();
if((style & ES_READONLY) != ES_READONLY)
{
pT->FindReplace(FALSE);
}
else
{
// Don't allow replace when the edit control is read only
bHandled = FALSE;
}
return 0;
}
// Operations (overrideable)
TFindReplaceDialog* CreateFindReplaceDialog(BOOL bFindOnly, // TRUE for Find, FALSE for FindReplace
LPCTSTR lpszFindWhat,
LPCTSTR lpszReplaceWith = NULL,
DWORD dwFlags = FR_DOWN,
HWND hWndParent = NULL)
{
// You can override all of this in a derived class
TFindReplaceDialog* findReplaceDialog = NULL;
ATLTRY(findReplaceDialog = new TFindReplaceDialog());
if(findReplaceDialog == NULL)
{
::MessageBeep(MB_ICONHAND);
}
else
{
HWND hWndFindReplace = findReplaceDialog->Create(bFindOnly,
lpszFindWhat, lpszReplaceWith, dwFlags, hWndParent);
if(hWndFindReplace == NULL)
{
delete findReplaceDialog;
findReplaceDialog = NULL;
}
else
{
findReplaceDialog->SetActiveWindow();
findReplaceDialog->ShowWindow(SW_SHOW);
}
}
return findReplaceDialog;
}
void AdjustDialogPosition(HWND hWndDialog)
{
ATLASSERT((hWndDialog != NULL) && ::IsWindow(hWndDialog));
T* pT = static_cast<T*>(this);
LONG nStartChar = 0, nEndChar = 0;
// Send EM_GETSEL so we can use both Edit and RichEdit
// (CEdit::GetSel uses int&, and CRichEditCtrlT::GetSel uses LONG&)
::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
POINT point = pT->PosFromChar(nStartChar);
pT->ClientToScreen(&point);
RECT rect = {};
::GetWindowRect(hWndDialog, &rect);
if(::PtInRect(&rect, point) != FALSE)
{
if(point.y > (rect.bottom - rect.top))
{
::OffsetRect(&rect, 0, point.y - rect.bottom - 20);
}
else
{
int nVertExt = GetSystemMetrics(SM_CYSCREEN);
if((point.y + (rect.bottom - rect.top)) < nVertExt)
::OffsetRect(&rect, 0, 40 + point.y - rect.top);
}
::MoveWindow(hWndDialog, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
}
}
DWORD GetFindReplaceDialogFlags() const
{
DWORD dwFlags = 0;
if(m_bFindDown)
dwFlags |= FR_DOWN;
if(m_bMatchCase)
dwFlags |= FR_MATCHCASE;
if(m_bWholeWord)
dwFlags |= FR_WHOLEWORD;
return dwFlags;
}
void FindReplace(BOOL bFindOnly)
{
T* pT = static_cast<T*>(this);
m_bFirstSearch = TRUE;
if(m_pFindReplaceDialog != NULL)
{
if(m_bFindOnly == bFindOnly)
{
m_pFindReplaceDialog->SetActiveWindow();
m_pFindReplaceDialog->ShowWindow(SW_SHOW);
return;
}
else
{
m_pFindReplaceDialog->SendMessage(WM_CLOSE);
ATLASSERT(m_pFindReplaceDialog == NULL);
}
}
ATLASSERT(m_pFindReplaceDialog == NULL);
ATL::CString findNext;
pT->GetSelText(findNext);
// if selection is empty or spans multiple lines use old find text
if(findNext.IsEmpty() || (findNext.FindOneOf(_T("\n\r")) != -1))
findNext = m_sFindNext;
ATL::CString replaceWith = m_sReplaceWith;
DWORD dwFlags = pT->GetFindReplaceDialogFlags();
m_pFindReplaceDialog = pT->CreateFindReplaceDialog(bFindOnly,
findNext, replaceWith, dwFlags, pT->operator HWND());
ATLASSERT(m_pFindReplaceDialog != NULL);
if(m_pFindReplaceDialog != NULL)
m_bFindOnly = bFindOnly;
}
BOOL SameAsSelected(LPCTSTR lpszCompare, BOOL bMatchCase, BOOL /*bWholeWord*/)
{
T* pT = static_cast<T*>(this);
// check length first
size_t nLen = lstrlen(lpszCompare);
LONG nStartChar = 0, nEndChar = 0;
// Send EM_GETSEL so we can use both Edit and RichEdit
// (CEdit::GetSel uses int&, and CRichEditCtrlT::GetSel uses LONG&)
::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
if(nLen != (size_t)(nEndChar - nStartChar))
return FALSE;
// length is the same, check contents
ATL::CString selectedText;
pT->GetSelText(selectedText);
return (bMatchCase && (selectedText.Compare(lpszCompare) == 0)) ||
(!bMatchCase && (selectedText.CompareNoCase(lpszCompare) == 0));
}
void TextNotFound(LPCTSTR lpszFind)
{
T* pT = static_cast<T*>(this);
m_bFirstSearch = TRUE;
pT->OnTextNotFound(lpszFind);
}
ATL::CString GetTranslationText(enum TranslationTextItem eItem) const
{
ATL::CString text;
switch(eItem)
{
case eText_OnReplaceAllMessage:
text = _T("Replaced %d occurances of \"%s\" with \"%s\"");
break;
case eText_OnReplaceAllTitle:
text = _T("Replace All");
break;
case eText_OnTextNotFoundMessage:
text = _T("Unable to find the text \"%s\"");
break;
case eText_OnTextNotFoundTitle:
text = _T("Text not found");
break;
}
return text;
}
// Overrideable Handlers
void OnFindNext(LPCTSTR lpszFind, BOOL bFindDown, BOOL bMatchCase, BOOL bWholeWord)
{
T* pT = static_cast<T*>(this);
m_sFindNext = lpszFind;
m_bMatchCase = bMatchCase;
m_bWholeWord = bWholeWord;
m_bFindDown = bFindDown;
if(!pT->FindTextSimple(m_sFindNext, m_bMatchCase, m_bWholeWord, m_bFindDown))
pT->TextNotFound(m_sFindNext);
else
pT->AdjustDialogPosition(m_pFindReplaceDialog->operator HWND());
}
void OnReplaceSel(LPCTSTR lpszFind, BOOL bFindDown, BOOL bMatchCase, BOOL bWholeWord, LPCTSTR lpszReplace)
{
T* pT = static_cast<T*>(this);
m_sFindNext = lpszFind;
m_sReplaceWith = lpszReplace;
m_bMatchCase = bMatchCase;
m_bWholeWord = bWholeWord;
m_bFindDown = bFindDown;
if(pT->SameAsSelected(m_sFindNext, m_bMatchCase, m_bWholeWord))
pT->ReplaceSel(m_sReplaceWith);
if(!pT->FindTextSimple(m_sFindNext, m_bMatchCase, m_bWholeWord, m_bFindDown))
pT->TextNotFound(m_sFindNext);
else
pT->AdjustDialogPosition(m_pFindReplaceDialog->operator HWND());
}
void OnReplaceAll(LPCTSTR lpszFind, LPCTSTR lpszReplace, BOOL bMatchCase, BOOL bWholeWord)
{
T* pT = static_cast<T*>(this);
m_sFindNext = lpszFind;
m_sReplaceWith = lpszReplace;
m_bMatchCase = bMatchCase;
m_bWholeWord = bWholeWord;
m_bFindDown = TRUE;
// no selection or different than what looking for
if(!pT->SameAsSelected(m_sFindNext, m_bMatchCase, m_bWholeWord))
{
if(!pT->FindTextSimple(m_sFindNext, m_bMatchCase, m_bWholeWord, m_bFindDown))
{
pT->TextNotFound(m_sFindNext);
return;
}
}
pT->OnReplaceAllCoreBegin();
int replaceCount=0;
do
{
++replaceCount;
pT->ReplaceSel(m_sReplaceWith);
} while(pT->FindTextSimple(m_sFindNext, m_bMatchCase, m_bWholeWord, m_bFindDown));
pT->OnReplaceAllCoreEnd(replaceCount);
}
void OnReplaceAllCoreBegin()
{
T* pT = static_cast<T*>(this);
m_hOldCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
pT->HideSelection(TRUE, FALSE);
}
void OnReplaceAllCoreEnd(int replaceCount)
{
T* pT = static_cast<T*>(this);
pT->HideSelection(FALSE, FALSE);
::SetCursor(m_hOldCursor);
ATL::CString message = pT->GetTranslationText(eText_OnReplaceAllMessage);
if(message.GetLength() > 0)
{
ATL::CString formattedMessage;
formattedMessage.Format(message, replaceCount, (LPCTSTR)m_sFindNext, (LPCTSTR)m_sReplaceWith);
if(m_pFindReplaceDialog != NULL)
{
m_pFindReplaceDialog->MessageBox(formattedMessage,
pT->GetTranslationText(eText_OnReplaceAllTitle),
MB_OK | MB_ICONINFORMATION | MB_APPLMODAL);
}
else
{
pT->MessageBox(formattedMessage,
pT->GetTranslationText(eText_OnReplaceAllTitle),
MB_OK | MB_ICONINFORMATION | MB_APPLMODAL);
}
}
}
void OnTextNotFound(LPCTSTR lpszFind)
{
T* pT = static_cast<T*>(this);
ATL::CString message = pT->GetTranslationText(eText_OnTextNotFoundMessage);
if(message.GetLength() > 0)
{
ATL::CString formattedMessage;
formattedMessage.Format(message, lpszFind);
if(m_pFindReplaceDialog != NULL)
{
m_pFindReplaceDialog->MessageBox(formattedMessage,
pT->GetTranslationText(eText_OnTextNotFoundTitle),
MB_OK | MB_ICONINFORMATION | MB_APPLMODAL);
}
else
{
pT->MessageBox(formattedMessage,
pT->GetTranslationText(eText_OnTextNotFoundTitle),
MB_OK | MB_ICONINFORMATION | MB_APPLMODAL);
}
}
else
{
::MessageBeep(MB_ICONHAND);
}
}
void OnTerminatingFindReplaceDialog(TFindReplaceDialog*& /*findReplaceDialog*/)
{
}
};
///////////////////////////////////////////////////////////////////////////////
// CEditFindReplaceImpl - Mixin class for implementing Find/Replace for CEdit
// based window classes.
// Chain to CEditFindReplaceImpl message map. Your class must also derive from CEdit.
// Example:
// class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
// public CEditFindReplaceImpl<CMyEdit>
// {
// public:
// BEGIN_MSG_MAP(CMyEdit)
// // your handlers...
// CHAIN_MSG_MAP_ALT(CEditFindReplaceImpl<CMyEdit>, 1)
// END_MSG_MAP()
// // other stuff...
// };
template <class T, class TFindReplaceDialog = CFindReplaceDialog>
class CEditFindReplaceImpl : public CEditFindReplaceImplBase<T, TFindReplaceDialog>
{
protected:
typedef CEditFindReplaceImpl<T, TFindReplaceDialog> thisClass;
typedef CEditFindReplaceImplBase<T, TFindReplaceDialog> baseClass;
public:
// Message Handlers
BEGIN_MSG_MAP(thisClass)
ALT_MSG_MAP(1)
CHAIN_MSG_MAP_ALT(baseClass, 1)
END_MSG_MAP()
// Operations
// Supported only for RichEdit, so this does nothing for Edit
void HideSelection(BOOL /*bHide*/ = TRUE, BOOL /*bChangeStyle*/ = FALSE)
{
}
// Operations (overrideable)
BOOL FindTextSimple(LPCTSTR lpszFind, BOOL bMatchCase, BOOL bWholeWord, BOOL bFindDown = TRUE)
{
T* pT = static_cast<T*>(this);
ATLASSERT(lpszFind != NULL);
ATLASSERT(*lpszFind != _T('\0'));
UINT nLen = pT->GetBufferLength();
int nStartChar = 0, nEndChar = 0;
pT->GetSel(nStartChar, nEndChar);
UINT nStart = nStartChar;
int iDir = bFindDown ? +1 : -1;
// can't find a match before the first character
if((nStart == 0) && (iDir < 0))
return FALSE;
LPCTSTR lpszText = pT->LockBuffer();
bool isDBCS = false;
#ifdef _MBCS
CPINFO info = {};
::GetCPInfo(::GetOEMCP(), &info);
isDBCS = (info.MaxCharSize > 1);
#endif
if(iDir < 0)
{
// always go back one for search backwards
nStart -= int((lpszText + nStart) - ::CharPrev(lpszText, lpszText + nStart));
}
else if((nStartChar != nEndChar) && (pT->SameAsSelected(lpszFind, bMatchCase, bWholeWord)))
{
// easy to go backward/forward with SBCS
#ifndef _UNICODE
if(::IsDBCSLeadByte(lpszText[nStart]))
nStart++;
#endif
nStart += iDir;
}
// handle search with nStart past end of buffer
UINT nLenFind = ::lstrlen(lpszFind);
if((nStart + nLenFind - 1) >= nLen)
{
if((iDir < 0) && (nLen >= nLenFind))
{
if(isDBCS)
{
// walk back to previous character n times
nStart = nLen;
int n = nLenFind;
while(n--)
{
nStart -= int((lpszText + nStart) - ::CharPrev(lpszText, lpszText + nStart));
}
}
else
{
// single-byte character set is easy and fast
nStart = nLen - nLenFind;
}
ATLASSERT((nStart + nLenFind - 1) <= nLen);
}
else
{
pT->UnlockBuffer();
return FALSE;
}
}
// start the search at nStart
LPCTSTR lpsz = lpszText + nStart;
typedef int (WINAPI* CompareProc)(LPCTSTR str1, LPCTSTR str2);
CompareProc pfnCompare = bMatchCase ? lstrcmp : lstrcmpi;
if(isDBCS)
{
// double-byte string search
LPCTSTR lpszStop = NULL;
if(iDir > 0)
{
// start at current and find _first_ occurrance
lpszStop = lpszText + nLen - nLenFind + 1;
}
else
{
// start at top and find _last_ occurrance
lpszStop = lpsz;
lpsz = lpszText;
}
LPCTSTR lpszFound = NULL;
while(lpsz <= lpszStop)
{
#ifndef _UNICODE
if(!bMatchCase || ((*lpsz == *lpszFind) && (!::IsDBCSLeadByte(*lpsz) || (lpsz[1] == lpszFind[1]))))
#else
if(!bMatchCase || ((*lpsz == *lpszFind) && (lpsz[1] == lpszFind[1])))
#endif
{
LPTSTR lpch = (LPTSTR)(lpsz + nLenFind);
TCHAR chSave = *lpch;
*lpch = _T('\0');
int nResult = (*pfnCompare)(lpsz, lpszFind);
*lpch = chSave;
if(nResult == 0)
{
lpszFound = lpsz;
if(iDir > 0)
break;
}
}
lpsz = ::CharNext(lpsz);
}
pT->UnlockBuffer();
if(lpszFound != NULL)
{
int n = (int)(lpszFound - lpszText);
pT->SetSel(n, n + nLenFind);
return TRUE;
}
}
else
{
// single-byte string search
UINT nCompare = 0;
if(iDir < 0)
nCompare = (UINT)(lpsz - lpszText) + 1;
else
nCompare = nLen - (UINT)(lpsz - lpszText) - nLenFind + 1;
while(nCompare > 0)
{
ATLASSERT(lpsz >= lpszText);
ATLASSERT((lpsz + nLenFind - 1) <= (lpszText + nLen - 1));
LPSTR lpch = (LPSTR)(lpsz + nLenFind);
char chSave = *lpch;
*lpch = '\0';
int nResult = (*pfnCompare)(lpsz, lpszFind);
*lpch = chSave;
if(nResult == 0)
{
pT->UnlockBuffer();
int n = (int)(lpsz - lpszText);
pT->SetSel(n, n + nLenFind);
return TRUE;
}
// restore character at end of search
*lpch = chSave;
// move on to next substring
nCompare--;
lpsz += iDir;
}
pT->UnlockBuffer();
}
return FALSE;
}
LPCTSTR LockBuffer() const
{
const T* pT = static_cast<const T*>(this);
ATLASSERT(pT->m_hWnd != NULL);
#ifndef _UNICODE
// If common controls version 6 is in use (such as via theming), then EM_GETHANDLE
// will always return a UNICODE string. You're really not supposed to superclass
// or subclass common controls with an ANSI windows procedure.
DWORD dwMajor = 0, dwMinor = 0;
HRESULT hRet = ATL::AtlGetCommCtrlVersion(&dwMajor, &dwMinor);
if(SUCCEEDED(hRet) && (dwMajor >= 6))
{
ATLTRACE2(atlTraceUI, 0, _T("AtlFind Warning: You have compiled for MBCS/ANSI but are using common controls version 6 or later which are always Unicode.\r\n"));
ATLASSERT(FALSE);
}
#endif // !_UNICODE
HLOCAL hLocal = pT->GetHandle();
ATLASSERT(hLocal != NULL);
LPCTSTR lpszText = (LPCTSTR)::LocalLock(hLocal);
ATLASSERT(lpszText != NULL);
return lpszText;
}
void UnlockBuffer() const
{
const T* pT = static_cast<const T*>(this);
ATLASSERT(pT->m_hWnd != NULL);
HLOCAL hLocal = pT->GetHandle();
ATLASSERT(hLocal != NULL);
::LocalUnlock(hLocal);
}
UINT GetBufferLength() const
{
const T* pT = static_cast<const T*>(this);
ATLASSERT(pT->m_hWnd != NULL);
UINT nLen = 0;
LPCTSTR lpszText = pT->LockBuffer();
if(lpszText != NULL)
nLen = ::lstrlen(lpszText);
pT->UnlockBuffer();
return nLen;
}
LONG EndOfLine(LPCTSTR lpszText, UINT nLen, UINT nIndex) const
{
LPCTSTR lpsz = lpszText + nIndex;
LPCTSTR lpszStop = lpszText + nLen;
while((lpsz < lpszStop) && (*lpsz != _T('\r')))
++lpsz;
return LONG(lpsz - lpszText);
}
LONG GetSelText(ATL::CString& strText) const
{
const T* pT = static_cast<const T*>(this);
int nStartChar = 0, nEndChar = 0;
pT->GetSel(nStartChar, nEndChar);
ATLASSERT((UINT)nEndChar <= pT->GetBufferLength());
LPCTSTR lpszText = pT->LockBuffer();
LONG nLen = pT->EndOfLine(lpszText, nEndChar, nStartChar) - nStartChar;
ATL::Checked::memcpy_s(strText.GetBuffer(nLen), nLen * sizeof(TCHAR), lpszText + nStartChar, nLen * sizeof(TCHAR));
strText.ReleaseBuffer(nLen);
pT->UnlockBuffer();
return nLen;
}
};
///////////////////////////////////////////////////////////////////////////////
// CRichEditFindReplaceImpl - Mixin class for implementing Find/Replace for CRichEditCtrl
// based window classes.
// Chain to CRichEditFindReplaceImpl message map. Your class must also derive from CRichEditCtrl.
// Example:
// class CMyRichEdit : public CWindowImpl<CMyRichEdit, CRichEditCtrl>,
// public CRichEditFindReplaceImpl<CMyRichEdit>
// {
// public:
// BEGIN_MSG_MAP(CMyRichEdit)
// // your handlers...
// CHAIN_MSG_MAP_ALT(CRichEditFindReplaceImpl<CMyRichEdit>, 1)
// END_MSG_MAP()
// // other stuff...
// };
template <class T, class TFindReplaceDialog = CFindReplaceDialog>
class CRichEditFindReplaceImpl : public CEditFindReplaceImplBase<T, TFindReplaceDialog>
{
protected:
typedef CRichEditFindReplaceImpl<T, TFindReplaceDialog> thisClass;
typedef CEditFindReplaceImplBase<T, TFindReplaceDialog> baseClass;
public:
BEGIN_MSG_MAP(thisClass)
ALT_MSG_MAP(1)
CHAIN_MSG_MAP_ALT(baseClass, 1)
END_MSG_MAP()
// Operations (overrideable)
BOOL FindTextSimple(LPCTSTR lpszFind, BOOL bMatchCase, BOOL bWholeWord, BOOL bFindDown = TRUE)
{
T* pT = static_cast<T*>(this);
ATLASSERT(lpszFind != NULL);
FINDTEXTEX ft = {};
pT->GetSel(ft.chrg);
if(this->m_bFirstSearch)
{
if(bFindDown)
this->m_nInitialSearchPos = ft.chrg.cpMin;
else
this->m_nInitialSearchPos = ft.chrg.cpMax;
this->m_bFirstSearch = FALSE;
}
ft.lpstrText = (LPTSTR)lpszFind;
if(ft.chrg.cpMin != ft.chrg.cpMax) // i.e. there is a selection
{
if(bFindDown)
{
ft.chrg.cpMin++;
}
else
{
// won't wraparound backwards
ft.chrg.cpMin = __max(ft.chrg.cpMin, 0);
}
}
DWORD dwFlags = bMatchCase ? FR_MATCHCASE : 0;
dwFlags |= bWholeWord ? FR_WHOLEWORD : 0;
ft.chrg.cpMax = pT->GetTextLength() + this->m_nInitialSearchPos;
if(bFindDown)
{
if(this->m_nInitialSearchPos >= 0)
ft.chrg.cpMax = pT->GetTextLength();
dwFlags |= FR_DOWN;
ATLASSERT(ft.chrg.cpMax >= ft.chrg.cpMin);
}
else
{
if(this->m_nInitialSearchPos >= 0)
ft.chrg.cpMax = 0;
dwFlags &= ~FR_DOWN;
ATLASSERT(ft.chrg.cpMax <= ft.chrg.cpMin);
}
BOOL bRet = FALSE;
if(pT->FindAndSelect(dwFlags, ft) != -1)
{
bRet = TRUE; // we found the text
}
else if(this->m_nInitialSearchPos > 0)
{
// if the original starting point was not the beginning
// of the buffer and we haven't already been here
if(bFindDown)
{
ft.chrg.cpMin = 0;
ft.chrg.cpMax = this->m_nInitialSearchPos;
}
else
{
ft.chrg.cpMin = pT->GetTextLength();
ft.chrg.cpMax = this->m_nInitialSearchPos;
}
this->m_nInitialSearchPos = this->m_nInitialSearchPos - pT->GetTextLength();
bRet = (pT->FindAndSelect(dwFlags, ft) != -1) ? TRUE : FALSE;
}
return bRet;
}
long FindAndSelect(DWORD dwFlags, FINDTEXTEX& ft)
{
T* pT = static_cast<T*>(this);
LONG index = pT->FindText(dwFlags, ft);
if(index != -1) // i.e. we found something
pT->SetSel(ft.chrgText);
return index;
}
};
} // namespace WTL
#endif // __ATLFIND_H__
File diff suppressed because it is too large Load Diff
+3445
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+259
View File
@@ -0,0 +1,259 @@
// Windows Template Library - WTL version 10.0
// Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#ifndef __ATLRES_H__
#define __ATLRES_H__
#pragma once
#ifdef RC_INVOKED
#ifndef _INC_WINDOWS
#define _INC_WINDOWS
#define VS_VERSION_INFO 1
#ifdef APSTUDIO_INVOKED
#define APSTUDIO_HIDDEN_SYMBOLS // Ignore following symbols
#endif // APSTUDIO_INVOKED
#ifndef WINVER
#define WINVER 0x0500
#endif // !WINVER
#include <winresrc.h>
// operation messages sent to DLGINIT
#define LB_ADDSTRING (WM_USER+1)
#define CB_ADDSTRING (WM_USER+3)
#ifdef APSTUDIO_INVOKED
#undef APSTUDIO_HIDDEN_SYMBOLS
#endif // APSTUDIO_INVOKED
#ifdef IDC_STATIC
#undef IDC_STATIC
#endif // IDC_STATIC
#define IDC_STATIC (-1)
#endif // !_INC_WINDOWS
#endif // RC_INVOKED
#ifdef APSTUDIO_INVOKED
#define APSTUDIO_HIDDEN_SYMBOLS
#endif // APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////////
// ATL resource types
#ifndef RC_INVOKED
#define RT_DLGINIT MAKEINTRESOURCE(240)
#define RT_TOOLBAR MAKEINTRESOURCE(241)
#endif // RC_INVOKED
///////////////////////////////////////////////////////////////////////////////
#ifdef APSTUDIO_INVOKED
#undef APSTUDIO_HIDDEN_SYMBOLS
#endif // APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////////
// Standard window components
#define ID_SEPARATOR 0 // special separator value
#define ID_DEFAULT_PANE 0 // default status bar pane
#ifndef RC_INVOKED // code only
// standard control bars (IDW = window ID)
#define ATL_IDW_TOOLBAR 0xE800 // main Toolbar for window
#define ATL_IDW_STATUS_BAR 0xE801 // Status bar window
#define ATL_IDW_COMMAND_BAR 0xE802 // Command bar window
// parts of a frame window
#define ATL_IDW_CLIENT 0xE900
#define ATL_IDW_PANE_FIRST 0xE900 // first pane (256 max)
#define ATL_IDW_PANE_LAST 0xE9FF
#define ATL_IDW_HSCROLL_FIRST 0xEA00 // first Horz scrollbar (16 max)
#define ATL_IDW_VSCROLL_FIRST 0xEA10 // first Vert scrollbar (16 max)
#define ATL_IDW_SIZE_BOX 0xEA20 // size box for splitters
#define ATL_IDW_PANE_SAVE 0xEA21 // to shift ATL_IDW_PANE_FIRST
// bands for a rebar
#define ATL_IDW_BAND_FIRST 0xEB00
#define ATL_IDW_BAND_LAST 0xEBFF
#endif // !RC_INVOKED
///////////////////////////////////////////////////////////////////////////////
// Standard Commands
// File commands
#define ID_FILE_NEW 0xE100
#define ID_FILE_OPEN 0xE101
#define ID_FILE_CLOSE 0xE102
#define ID_FILE_SAVE 0xE103
#define ID_FILE_SAVE_AS 0xE104
#define ID_FILE_PAGE_SETUP 0xE105
#define ID_FILE_PRINT_SETUP 0xE106
#define ID_FILE_PRINT 0xE107
#define ID_FILE_PRINT_DIRECT 0xE108
#define ID_FILE_PRINT_PREVIEW 0xE109
#define ID_FILE_UPDATE 0xE10A
#define ID_FILE_SAVE_COPY_AS 0xE10B
#define ID_FILE_SEND_MAIL 0xE10C
#define ID_FILE_MRU_FIRST 0xE110
#define ID_FILE_MRU_FILE1 0xE110 // range - 16 max
#define ID_FILE_MRU_FILE2 0xE111
#define ID_FILE_MRU_FILE3 0xE112
#define ID_FILE_MRU_FILE4 0xE113
#define ID_FILE_MRU_FILE5 0xE114
#define ID_FILE_MRU_FILE6 0xE115
#define ID_FILE_MRU_FILE7 0xE116
#define ID_FILE_MRU_FILE8 0xE117
#define ID_FILE_MRU_FILE9 0xE118
#define ID_FILE_MRU_FILE10 0xE119
#define ID_FILE_MRU_FILE11 0xE11A
#define ID_FILE_MRU_FILE12 0xE11B
#define ID_FILE_MRU_FILE13 0xE11C
#define ID_FILE_MRU_FILE14 0xE11D
#define ID_FILE_MRU_FILE15 0xE11E
#define ID_FILE_MRU_FILE16 0xE11F
#define ID_FILE_MRU_LAST 0xE11F
// Edit commands
#define ID_EDIT_CLEAR 0xE120
#define ID_EDIT_CLEAR_ALL 0xE121
#define ID_EDIT_COPY 0xE122
#define ID_EDIT_CUT 0xE123
#define ID_EDIT_FIND 0xE124
#define ID_EDIT_PASTE 0xE125
#define ID_EDIT_PASTE_LINK 0xE126
#define ID_EDIT_PASTE_SPECIAL 0xE127
#define ID_EDIT_REPEAT 0xE128
#define ID_EDIT_REPLACE 0xE129
#define ID_EDIT_SELECT_ALL 0xE12A
#define ID_EDIT_UNDO 0xE12B
#define ID_EDIT_REDO 0xE12C
#define ID_EDIT_DELETE ID_EDIT_CLEAR
#define ID_EDIT_FIND_NEXT ID_EDIT_REPEAT
#define ID_EDIT_FIND_PREVIOUS 0xE12D
// Window commands
#define ID_WINDOW_NEW 0xE130
#define ID_WINDOW_ARRANGE 0xE131
#define ID_WINDOW_CASCADE 0xE132
#define ID_WINDOW_TILE_HORZ 0xE133
#define ID_WINDOW_TILE_VERT 0xE134
#define ID_WINDOW_SPLIT 0xE135
#ifndef RC_INVOKED // code only
#define ATL_IDM_WINDOW_FIRST 0xE130
#define ATL_IDM_WINDOW_LAST 0xE13F
#define ATL_IDM_FIRST_MDICHILD 0xFF00 // window list starts here
#define ATL_IDM_LAST_MDICHILD 0xFFFD
#endif // !RC_INVOKED
// TabView
#define ID_WINDOW_TABFIRST 0xFF00 // = ATL_IDM_FIRST_MDICHILD
#define ID_WINDOW_TABLAST 0xFFFD
#define ID_WINDOW_SHOWTABLIST 0xFFFE
// Help and App commands
#define ID_APP_ABOUT 0xE140
#define ID_APP_EXIT 0xE141
#define ID_HELP_INDEX 0xE142
#define ID_HELP_FINDER 0xE143
#define ID_HELP_USING 0xE144
#define ID_CONTEXT_HELP 0xE145 // shift-F1
// special commands for processing help
#define ID_HELP 0xE146 // first attempt for F1
#define ID_DEFAULT_HELP 0xE147 // last attempt
// Misc
#define ID_NEXT_PANE 0xE150
#define ID_PREV_PANE 0xE151
#define ID_PANE_CLOSE 0xE152
#define ID_PANE_NEXT ID_NEXT_PANE
#define ID_PANE_PREVIOUS ID_PREV_PANE
// Format
#define ID_FORMAT_FONT 0xE160
// Scroll
#define ID_SCROLL_UP 0xE170
#define ID_SCROLL_DOWN 0xE171
#define ID_SCROLL_PAGE_UP 0xE172
#define ID_SCROLL_PAGE_DOWN 0xE173
#define ID_SCROLL_TOP 0xE174
#define ID_SCROLL_BOTTOM 0xE175
#define ID_SCROLL_LEFT 0xE176
#define ID_SCROLL_RIGHT 0xE177
#define ID_SCROLL_PAGE_LEFT 0xE178
#define ID_SCROLL_PAGE_RIGHT 0xE179
#define ID_SCROLL_ALL_LEFT 0xE17A
#define ID_SCROLL_ALL_RIGHT 0xE17B
// OLE commands
#define ID_OLE_INSERT_NEW 0xE200
#define ID_OLE_EDIT_LINKS 0xE201
#define ID_OLE_EDIT_CONVERT 0xE202
#define ID_OLE_EDIT_CHANGE_ICON 0xE203
#define ID_OLE_EDIT_PROPERTIES 0xE204
#define ID_OLE_VERB_FIRST 0xE210 // range - 16 max
#ifndef RC_INVOKED // code only
#define ID_OLE_VERB_LAST 0xE21F
#endif // !RC_INVOKED
// View commands (same number used as IDW used for toolbar and status bar)
#define ID_VIEW_TOOLBAR 0xE800
#define ID_VIEW_STATUS_BAR 0xE801
#define ID_VIEW_REFRESH 0xE803
#define ID_VIEW_RIBBON 0xE804
///////////////////////////////////////////////////////////////////////////////
// Standard control IDs
#ifdef IDC_STATIC
#undef IDC_STATIC
#endif // IDC_STATIC
#define IDC_STATIC (-1) // all static controls
///////////////////////////////////////////////////////////////////////////////
// Standard string error/warnings
// idle status bar message
#define ATL_IDS_IDLEMESSAGE 0xE001
#ifndef RC_INVOKED // code only
#define ATL_IDS_SCFIRST 0xEF00
#endif // !RC_INVOKED
#define ATL_IDS_SCSIZE 0xEF00
#define ATL_IDS_SCMOVE 0xEF01
#define ATL_IDS_SCMINIMIZE 0xEF02
#define ATL_IDS_SCMAXIMIZE 0xEF03
#define ATL_IDS_SCNEXTWINDOW 0xEF04
#define ATL_IDS_SCPREVWINDOW 0xEF05
#define ATL_IDS_SCCLOSE 0xEF06
#define ATL_IDS_SCRESTORE 0xEF12
#define ATL_IDS_SCTASKLIST 0xEF13
#define ATL_IDS_MDICHILD 0xEF1F
#define ATL_IDS_MRU_FILE 0xEFDA
///////////////////////////////////////////////////////////////////////////////
// Misc. control IDs
// Property Sheet control id's (determined with Spy++)
#define ID_APPLY_NOW 0x3021
#define ID_WIZBACK 0x3023
#define ID_WIZNEXT 0x3024
#define ID_WIZFINISH 0x3025
#define ATL_IDC_TAB_CONTROL 0x3020
#endif // __ATLRES_H__
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+623
View File
@@ -0,0 +1,623 @@
// Windows Template Library - WTL version 10.0
// Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#ifndef __ATLWINX_H__
#define __ATLWINX_H__
#pragma once
#ifndef __ATLAPP_H__
#error atlwinx.h requires atlapp.h to be included first
#endif
#include <atlwin.h>
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CWindowEx
/////////////////////////////////////////////////////////////////////////////
// Additional macros needed for template classes
#ifndef DECLARE_WND_CLASS_EX2
#define DECLARE_WND_CLASS_EX2(WndClassName, EnclosingClass, style, bkgnd) \
static ATL::CWndClassInfo& GetWndClassInfo() \
{ \
static ATL::CWndClassInfo wc = \
{ \
{ sizeof(WNDCLASSEX), style, EnclosingClass::StartWindowProc, \
0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName, NULL }, \
NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
}; \
return wc; \
}
#endif // DECLARE_WND_CLASS_EX2
#ifndef DECLARE_WND_SUPERCLASS2
#define DECLARE_WND_SUPERCLASS2(WndClassName, EnclosingClass, OrigWndClassName) \
static ATL::CWndClassInfo& GetWndClassInfo() \
{ \
static ATL::CWndClassInfo wc = \
{ \
{ sizeof(WNDCLASSEX), 0, EnclosingClass::StartWindowProc, \
0, 0, NULL, NULL, NULL, NULL, NULL, WndClassName, NULL }, \
OrigWndClassName, NULL, NULL, TRUE, 0, _T("") \
}; \
return wc; \
}
#endif // DECLARE_WND_SUPERCLASS2
///////////////////////////////////////////////////////////////////////////////
// Command Chaining Macros
#define CHAIN_COMMANDS(theChainClass) \
if(uMsg == WM_COMMAND) \
CHAIN_MSG_MAP(theChainClass)
#define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
if(uMsg == WM_COMMAND) \
CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
#define CHAIN_COMMANDS_MEMBER(theChainMember) \
if(uMsg == WM_COMMAND) \
CHAIN_MSG_MAP_MEMBER(theChainMember)
#define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
if(uMsg == WM_COMMAND) \
CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
///////////////////////////////////////////////////////////////////////////////
// Macros for parent message map to selectively reflect control messages
// NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
// (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
// Since we can't modify ATL, we'll provide the needed additions
// in a separate function (that is not a member of CWindowImplRoot)
namespace WTL
{
inline LRESULT WtlReflectNotificationsFiltered(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,
UINT uMsgFilter = WM_NULL, UINT_PTR idFromFilter = 0, HWND hWndChildFilter = NULL)
{
if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
{
// The notification message doesn't match the filter.
bHandled = FALSE;
return 1;
}
HWND hWndChild = NULL;
UINT_PTR idFrom = 0;
switch(uMsg)
{
case WM_COMMAND:
if(lParam != NULL) // not from a menu
{
hWndChild = (HWND)lParam;
idFrom = (UINT_PTR)LOWORD(wParam);
}
break;
case WM_NOTIFY:
hWndChild = ((LPNMHDR)lParam)->hwndFrom;
idFrom = ((LPNMHDR)lParam)->idFrom;
break;
case WM_PARENTNOTIFY:
switch(LOWORD(wParam))
{
case WM_CREATE:
case WM_DESTROY:
hWndChild = (HWND)lParam;
idFrom = (UINT_PTR)HIWORD(wParam);
break;
default:
hWndChild = ::GetDlgItem(hWndParent, HIWORD(wParam));
idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
break;
}
break;
case WM_DRAWITEM:
if(wParam) // not from a menu
{
hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
idFrom = (UINT_PTR)wParam;
}
break;
case WM_MEASUREITEM:
if(wParam) // not from a menu
{
hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
idFrom = (UINT_PTR)wParam;
}
break;
case WM_COMPAREITEM:
if(wParam) // not from a menu
{
hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
idFrom = (UINT_PTR)wParam;
}
break;
case WM_DELETEITEM:
if(wParam) // not from a menu
{
hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
idFrom = (UINT_PTR)wParam;
}
break;
case WM_VKEYTOITEM:
case WM_CHARTOITEM:
case WM_HSCROLL:
case WM_VSCROLL:
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORMSGBOX:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORSTATIC:
hWndChild = (HWND)lParam;
idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
break;
default:
break;
}
if((hWndChild == NULL) ||
((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
{
// Either hWndChild isn't valid, or
// hWndChild doesn't match the filter.
bHandled = FALSE;
return 1;
}
if((idFromFilter != 0) && (idFromFilter != idFrom))
{
// The dialog control id doesn't match the filter.
bHandled = FALSE;
return 1;
}
ATLASSERT(::IsWindow(hWndChild));
LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
{
// Try to prevent problems with WM_CTLCOLOR* messages when
// the message wasn't really handled
bHandled = FALSE;
}
return lResult;
}
} // namespace WTL
// Try to prevent problems with WM_CTLCOLOR* messages when
// the message wasn't really handled
#define REFLECT_NOTIFICATIONS_EX() \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
bHandled = FALSE; \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
{ \
bHandled = TRUE; \
lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
{ \
bHandled = TRUE; \
lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
{ \
bHandled = TRUE; \
lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
{ \
bHandled = TRUE; \
lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
{ \
bHandled = TRUE; \
lResult = WTL::WtlReflectNotificationsFiltered(this->m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_COMMAND(id, code) \
if((uMsg == WM_COMMAND) && (id == LOWORD(wParam)) && (code == HIWORD(wParam))) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_COMMAND_ID(id) \
if((uMsg == WM_COMMAND) && (id == LOWORD(wParam))) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_COMMAND_CODE(code) \
if((uMsg == WM_COMMAND) && (code == HIWORD(wParam))) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_COMMAND_RANGE(idFirst, idLast) \
if((uMsg == WM_COMMAND) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
if((uMsg == WM_COMMAND) && (code == HIWORD(wParam)) && (LOWORD(wParam) >= idFirst) && (LOWORD(wParam) <= idLast)) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFY(id, cd) \
if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom) && (cd == ((LPNMHDR)lParam)->code)) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFY_ID(id) \
if((uMsg == WM_NOTIFY) && (id == ((LPNMHDR)lParam)->idFrom)) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFY_CODE(cd) \
if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code)) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
if((uMsg == WM_NOTIFY) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
#define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
if((uMsg == WM_NOTIFY) && (cd == ((LPNMHDR)lParam)->code) && (((LPNMHDR)lParam)->idFrom >= idFirst) && (((LPNMHDR)lParam)->idFrom <= idLast)) \
{ \
bHandled = TRUE; \
lResult = this->ReflectNotifications(uMsg, wParam, lParam, bHandled); \
if(bHandled) \
return TRUE; \
}
///////////////////////////////////////////////////////////////////////////////
// GetClassLong/SetClassLong redefinition to avoid problems with class members
#ifdef SetClassLongPtrA
#undef SetClassLongPtrA
inline LONG_PTR SetClassLongPtrA(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
{
return ::SetClassLongA(hWnd, nIndex, LONG(dwNewLong));
}
#endif
#ifdef SetClassLongPtrW
#undef SetClassLongPtrW
inline LONG_PTR SetClassLongPtrW(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
{
return ::SetClassLongW(hWnd, nIndex, LONG(dwNewLong));
}
#endif
#ifdef GetClassLongPtrA
#undef GetClassLongPtrA
inline LONG_PTR GetClassLongPtrA(HWND hWnd, int nIndex)
{
return ::GetClassLongA(hWnd, nIndex);
}
#endif
#ifdef GetClassLongPtrW
#undef GetClassLongPtrW
inline LONG_PTR GetClassLongPtrW(HWND hWnd, int nIndex)
{
return ::GetClassLongW(hWnd, nIndex);
}
#endif
///////////////////////////////////////////////////////////////////////////////
// CWindowEx - extension of ATL::CWindow
namespace WTL
{
class CWindowEx : public ATL::CWindow
{
public:
CWindowEx(HWND hWnd = NULL) : ATL::CWindow(hWnd)
{ }
CWindowEx& operator =(HWND hWnd)
{
m_hWnd = hWnd;
return *this;
}
operator HWND() const
{
return m_hWnd;
}
// Methods
BOOL PrintWindow(HDC hDC, UINT uFlags = 0)
{
ATLASSERT(::IsWindow(m_hWnd));
return ::PrintWindow(m_hWnd, hDC, uFlags);
}
BOOL DragDetect(POINT pt)
{
ATLASSERT(::IsWindow(m_hWnd));
return ::DragDetect(m_hWnd, pt);
}
BOOL DragDetect()
{
ATLASSERT(::IsWindow(m_hWnd));
POINT pt = {};
::GetCursorPos(&pt);
return ::DragDetect(m_hWnd, pt);
}
CWindowEx GetAncestor(UINT uFlags) const
{
ATLASSERT(::IsWindow(m_hWnd));
return CWindowEx(::GetAncestor(m_hWnd, uFlags));
}
// Note: Does not work properly on Vista Aero and above
BOOL AnimateWindow(DWORD dwFlags, DWORD dwTime = 200)
{
ATLASSERT(::IsWindow(m_hWnd));
return ::AnimateWindow(m_hWnd, dwTime, dwFlags);
}
BOOL FlashWindowEx(DWORD dwFlags, UINT uCount, DWORD dwTimeout = 0)
{
ATLASSERT(::IsWindow(m_hWnd));
FLASHWINFO fi = { sizeof(FLASHWINFO) };
fi.hwnd = m_hWnd;
fi.dwFlags = dwFlags;
fi.uCount = uCount;
fi.dwTimeout = dwTimeout;
return ::FlashWindowEx(&fi);
}
BOOL StopFlashWindowEx()
{
ATLASSERT(::IsWindow(m_hWnd));
FLASHWINFO fi = { sizeof(FLASHWINFO) };
fi.hwnd = m_hWnd;
fi.dwFlags = FLASHW_STOP;
return ::FlashWindowEx(&fi);
}
// Class long properties
DWORD GetClassLong(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return ::GetClassLong(m_hWnd, nIndex);
}
DWORD SetClassLong(int nIndex, LONG dwNewLong)
{
ATLASSERT(::IsWindow(m_hWnd));
return ::SetClassLong(m_hWnd, nIndex, dwNewLong);
}
ULONG_PTR GetClassLongPtr(int nIndex) const
{
ATLASSERT(::IsWindow(m_hWnd));
return ::GetClassLongPtr(m_hWnd, nIndex);
}
ULONG_PTR SetClassLongPtr(int nIndex, LONG_PTR dwNewLong)
{
ATLASSERT(::IsWindow(m_hWnd));
return ::SetClassLongPtr(m_hWnd, nIndex, dwNewLong);
}
// Layered windows
BOOL SetLayeredWindowAttributes(COLORREF crlKey, BYTE byteAlpha, DWORD dwFlags)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
return ::SetLayeredWindowAttributes(m_hWnd, crlKey, byteAlpha, dwFlags);
}
BOOL UpdateLayeredWindow(HDC hdcDst, LPPOINT pptDst, LPSIZE psize, HDC hdcSrc, LPPOINT pptSrc, COLORREF crlKey, BLENDFUNCTION* pblend, DWORD dwFlags)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
return ::UpdateLayeredWindow(m_hWnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crlKey, pblend, dwFlags);
}
BOOL UpdateLayeredWindow(LPPOINT pptDst = NULL)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
return ::UpdateLayeredWindow(m_hWnd, NULL, pptDst, NULL, NULL, NULL, CLR_NONE, NULL, 0);
}
BOOL GetLayeredWindowAttributes(COLORREF* pcrlKey, BYTE* pbyteAlpha, DWORD* pdwFlags) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetExStyle() & WS_EX_LAYERED) != 0);
return ::GetLayeredWindowAttributes(m_hWnd, pcrlKey, pbyteAlpha, pdwFlags);
}
// Mouse tracking
BOOL StartTrackMouseLeave()
{
ATLASSERT(::IsWindow(m_hWnd));
TRACKMOUSEEVENT tme = {};
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = m_hWnd;
return ::TrackMouseEvent(&tme);
}
BOOL StartTrackMouse(DWORD dwFlags, DWORD dwHoverTime = HOVER_DEFAULT)
{
ATLASSERT(::IsWindow(m_hWnd));
TRACKMOUSEEVENT tme = {};
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = dwFlags;
tme.hwndTrack = m_hWnd;
tme.dwHoverTime = dwHoverTime;
return ::TrackMouseEvent(&tme);
}
BOOL CancelTrackMouse(DWORD dwType)
{
ATLASSERT(::IsWindow(m_hWnd));
TRACKMOUSEEVENT tme = {};
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_CANCEL | dwType;
tme.hwndTrack = m_hWnd;
return ::TrackMouseEvent(&tme);
}
// CString support
#ifdef __ATLSTR_H__
int GetWindowText(ATL::CString& strText) const
{
int nLength = GetWindowTextLength();
LPTSTR pszText = strText.GetBuffer(nLength + 1);
nLength = ::GetWindowText(m_hWnd, pszText, nLength + 1);
strText.ReleaseBuffer(nLength);
return nLength;
}
UINT GetDlgItemText(int nID, ATL::CString& strText) const
{
ATLASSERT(::IsWindow(m_hWnd));
HWND hItem = GetDlgItem(nID);
if(hItem != NULL)
{
int nLength = ::GetWindowTextLength(hItem);
LPTSTR pszText = strText.GetBuffer(nLength + 1);
nLength = ::GetWindowText(hItem, pszText, nLength + 1);
strText.ReleaseBuffer(nLength);
return nLength;
}
else
{
strText.Empty();
return 0;
}
}
#endif // __ATLSTR_H__
// Dialog window only
UINT DlgGetDefID() const
{
ATLASSERT(::IsWindow(m_hWnd));
LRESULT lRet = ::SendMessage(m_hWnd, DM_GETDEFID, 0, 0L);
UINT uID = 0U;
if(HIWORD(lRet) == DC_HASDEFID)
uID = LOWORD(lRet);
return uID;
}
void DlgSetDefID(UINT uID)
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, DM_SETDEFID, uID, 0L);
}
void DlgReposition()
{
ATLASSERT(::IsWindow(m_hWnd));
::SendMessage(m_hWnd, DM_REPOSITION, 0, 0L);
}
};
} // namespace WTL
#endif // __ATLWINX_H__