blob: 62db9178013cd6e61cf763e11c079f388e20f144 [file] [log] [blame]
// Windows Template Library - WTL version 8.0
// Copyright (C) Microsoft Corporation. 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 Permissive License (Ms-PL) which can be found in the file
// Ms-PL.txt at the root of this distribution.
#ifndef __ATLDLGS_H__
#define __ATLDLGS_H__
#pragma once
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error atldlgs.h requires atlapp.h to be included first
#endif
#ifndef __ATLWIN_H__
#error atldlgs.h requires atlwin.h to be included first
#endif
#include <commdlg.h>
#include <shlobj.h>
#if (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
#include <shobjidl.h>
#endif // (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CFileDialogImpl<T>
// CFileDialog
// CFileDialogEx
// CMultiFileDialogImpl<T>
// CMultiFileDialog
// CShellFileDialogImpl<T>
// CShellFileOpenDialogImpl<T>
// CShellFileOpenDialog
// CShellFileSaveDialogImpl<T>
// CShellFileSaveDialog
// CFolderDialogImpl<T>
// CFolderDialog
// CFontDialogImpl<T>
// CFontDialog
// CRichEditFontDialogImpl<T>
// CRichEditFontDialog
// CColorDialogImpl<T>
// CColorDialog
// CPrintDialogImpl<T>
// CPrintDialog
// CPrintDialogExImpl<T>
// CPrintDialogEx
// CPageSetupDialogImpl<T>
// CPageSetupDialog
// CFindReplaceDialogImpl<T>
// CFindReplaceDialog
//
// CMemDlgTemplate
// CIndirectDialogImpl<T, TDlgTemplate, TBase>
//
// CPropertySheetWindow
// CPropertySheetImpl<T, TBase>
// CPropertySheet
// CPropertyPageWindow
// CPropertyPageImpl<T, TBase>
// CPropertyPage<t_wDlgTemplateID>
// CAxPropertyPageImpl<T, TBase>
// CAxPropertyPage<t_wDlgTemplateID>
//
// CWizard97SheetWindow
// CWizard97SheetImpl<T, TBase>
// CWizard97Sheet
// CWizard97PageWindow
// CWizard97PageImpl<T, TBase>
// CWizard97ExteriorPageImpl<T, TBase>
// CWizard97InteriorPageImpl<T, TBase>
//
// CAeroWizardFrameWindow
// CAeroWizardFrameImpl<T, TBase>
// CAeroWizardFrame
// CAeroWizardPageWindow
// CAeroWizardPageImpl<T, TBase>
// CAeroWizardPage<t_wDlgTemplateID>
// CAeroWizardAxPageImpl<T, TBase>
// CAeroWizardAxPage<t_wDlgTemplateID>
//
// CTaskDialogConfig
// CTaskDialogImpl<T>
// CTaskDialog
//
// Global functions:
// AtlTaskDialog()
namespace WTL
{
///////////////////////////////////////////////////////////////////////////////
// CFileDialogImpl - used for File Open or File Save As
// compatibility with the old (vc6.0) headers
#if (_WIN32_WINNT >= 0x0500) && !defined(OPENFILENAME_SIZE_VERSION_400)
#ifndef CDSIZEOF_STRUCT
#define CDSIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
#endif
#define OPENFILENAME_SIZE_VERSION_400A CDSIZEOF_STRUCT(OPENFILENAMEA,lpTemplateName)
#define OPENFILENAME_SIZE_VERSION_400W CDSIZEOF_STRUCT(OPENFILENAMEW,lpTemplateName)
#ifdef UNICODE
#define OPENFILENAME_SIZE_VERSION_400 OPENFILENAME_SIZE_VERSION_400W
#else
#define OPENFILENAME_SIZE_VERSION_400 OPENFILENAME_SIZE_VERSION_400A
#endif // !UNICODE
#endif // (_WIN32_WINNT >= 0x0500) && !defined(OPENFILENAME_SIZE_VERSION_400)
#if !defined(_WIN32_WCE) && !defined(CDN_INCLUDEITEM)
#define CDN_INCLUDEITEM (CDN_FIRST - 0x0007)
#endif
template <class T>
class ATL_NO_VTABLE CFileDialogImpl : public ATL::CDialogImplBase
{
public:
#if defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
OPENFILENAMEEX m_ofn;
#else
OPENFILENAME m_ofn;
#endif
BOOL m_bOpenFileDialog; // TRUE for file open, FALSE for file save
TCHAR m_szFileTitle[_MAX_FNAME]; // contains file title after return
TCHAR m_szFileName[_MAX_PATH]; // contains full path name after return
CFileDialogImpl(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
HWND hWndParent = NULL)
{
memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
m_szFileName[0] = _T('\0');
m_szFileTitle[0] = _T('\0');
m_bOpenFileDialog = bOpenFileDialog;
m_ofn.lStructSize = sizeof(m_ofn);
#if (_WIN32_WINNT >= 0x0500)
// adjust struct size if running on older version of Windows
if(AtlIsOldWindows())
{
ATLASSERT(sizeof(m_ofn) > OPENFILENAME_SIZE_VERSION_400); // must be
m_ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
}
#endif // (_WIN32_WINNT >= 0x0500)
m_ofn.lpstrFile = m_szFileName;
m_ofn.nMaxFile = _MAX_PATH;
m_ofn.lpstrDefExt = lpszDefExt;
m_ofn.lpstrFileTitle = (LPTSTR)m_szFileTitle;
m_ofn.nMaxFileTitle = _MAX_FNAME;
#ifndef _WIN32_WCE
m_ofn.Flags = dwFlags | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLESIZING;
#else // CE specific
m_ofn.Flags = dwFlags | OFN_EXPLORER | OFN_ENABLEHOOK;
#endif // !_WIN32_WCE
m_ofn.lpstrFilter = lpszFilter;
m_ofn.hInstance = ModuleHelper::GetResourceInstance();
m_ofn.lpfnHook = (LPOFNHOOKPROC)T::StartDialogProc;
m_ofn.hwndOwner = hWndParent;
// setup initial file name
if(lpszFileName != NULL)
SecureHelper::strncpy_x(m_szFileName, _countof(m_szFileName), lpszFileName, _TRUNCATE);
}
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
{
ATLASSERT((m_ofn.Flags & OFN_ENABLEHOOK) != 0);
ATLASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
if(m_ofn.hwndOwner == NULL) // set only if not specified before
m_ofn.hwndOwner = hWndParent;
ATLASSERT(m_hWnd == NULL);
ModuleHelper::AddCreateWndData(&m_thunk.cd, (ATL::CDialogImplBase*)this);
BOOL bRet;
if(m_bOpenFileDialog)
#if defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
bRet = ::GetOpenFileNameEx(&m_ofn);
else
bRet = ::GetSaveFileName((LPOPENFILENAME)&m_ofn);
#else
bRet = ::GetOpenFileName(&m_ofn);
else
bRet = ::GetSaveFileName(&m_ofn);
#endif
m_hWnd = NULL;
return bRet ? IDOK : IDCANCEL;
}
// Attributes
ATL::CWindow GetFileDialogWindow() const
{
ATLASSERT(::IsWindow(m_hWnd));
return ATL::CWindow(GetParent());
}
int GetFilePath(LPTSTR lpstrFilePath, int nLength) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
return (int)GetFileDialogWindow().SendMessage(CDM_GETFILEPATH, nLength, (LPARAM)lpstrFilePath);
}
int GetFolderIDList(LPVOID lpBuff, int nLength) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
return (int)GetFileDialogWindow().SendMessage(CDM_GETFOLDERIDLIST, nLength, (LPARAM)lpBuff);
}
int GetFolderPath(LPTSTR lpstrFolderPath, int nLength) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
return (int)GetFileDialogWindow().SendMessage(CDM_GETFOLDERPATH, nLength, (LPARAM)lpstrFolderPath);
}
int GetSpec(LPTSTR lpstrSpec, int nLength) const
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
return (int)GetFileDialogWindow().SendMessage(CDM_GETSPEC, nLength, (LPARAM)lpstrSpec);
}
void SetControlText(int nCtrlID, LPCTSTR lpstrText)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
GetFileDialogWindow().SendMessage(CDM_SETCONTROLTEXT, nCtrlID, (LPARAM)lpstrText);
}
void SetDefExt(LPCTSTR lpstrExt)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
GetFileDialogWindow().SendMessage(CDM_SETDEFEXT, 0, (LPARAM)lpstrExt);
}
BOOL GetReadOnlyPref() const // return TRUE if readonly checked
{
return ((m_ofn.Flags & OFN_READONLY) != 0) ? TRUE : FALSE;
}
// Operations
void HideControl(int nCtrlID)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
GetFileDialogWindow().SendMessage(CDM_HIDECONTROL, nCtrlID);
}
// Special override for common dialogs
BOOL EndDialog(INT_PTR /*nRetCode*/ = 0)
{
ATLASSERT(::IsWindow(m_hWnd));
GetFileDialogWindow().SendMessage(WM_COMMAND, MAKEWPARAM(IDCANCEL, 0));
return TRUE;
}
// Message map and handlers
BEGIN_MSG_MAP(CFileDialogImpl)
NOTIFY_CODE_HANDLER(CDN_FILEOK, _OnFileOK)
NOTIFY_CODE_HANDLER(CDN_FOLDERCHANGE, _OnFolderChange)
NOTIFY_CODE_HANDLER(CDN_HELP, _OnHelp)
NOTIFY_CODE_HANDLER(CDN_INITDONE, _OnInitDone)
NOTIFY_CODE_HANDLER(CDN_SELCHANGE, _OnSelChange)
NOTIFY_CODE_HANDLER(CDN_SHAREVIOLATION, _OnShareViolation)
NOTIFY_CODE_HANDLER(CDN_TYPECHANGE, _OnTypeChange)
#ifndef _WIN32_WCE
NOTIFY_CODE_HANDLER(CDN_INCLUDEITEM, _OnIncludeItem)
#endif // !_WIN32_WCE
END_MSG_MAP()
LRESULT _OnFileOK(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
return !pT->OnFileOK((LPOFNOTIFY)pnmh);
}
LRESULT _OnFolderChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
pT->OnFolderChange((LPOFNOTIFY)pnmh);
return 0;
}
LRESULT _OnHelp(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
pT->OnHelp((LPOFNOTIFY)pnmh);
return 0;
}
LRESULT _OnInitDone(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
pT->OnInitDone((LPOFNOTIFY)pnmh);
return 0;
}
LRESULT _OnSelChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
pT->OnSelChange((LPOFNOTIFY)pnmh);
return 0;
}
LRESULT _OnShareViolation(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
return pT->OnShareViolation((LPOFNOTIFY)pnmh);
}
LRESULT _OnTypeChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
pT->OnTypeChange((LPOFNOTIFY)pnmh);
return 0;
}
#ifndef _WIN32_WCE
LRESULT _OnIncludeItem(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
ATLASSERT(::IsWindow(m_hWnd));
T* pT = static_cast<T*>(this);
return pT->OnIncludeItem((LPOFNOTIFYEX)pnmh);
}
#endif // !_WIN32_WCE
// Overrideables
BOOL OnFileOK(LPOFNOTIFY /*lpon*/)
{
return TRUE;
}
void OnFolderChange(LPOFNOTIFY /*lpon*/)
{
}
void OnHelp(LPOFNOTIFY /*lpon*/)
{
}
void OnInitDone(LPOFNOTIFY /*lpon*/)
{
}
void OnSelChange(LPOFNOTIFY /*lpon*/)
{
}
int OnShareViolation(LPOFNOTIFY /*lpon*/)
{
return 0;
}
void OnTypeChange(LPOFNOTIFY /*lpon*/)
{
}
#ifndef _WIN32_WCE
BOOL OnIncludeItem(LPOFNOTIFYEX /*lponex*/)
{
return TRUE; // include item
}
#endif // !_WIN32_WCE
};
class CFileDialog : public CFileDialogImpl<CFileDialog>
{
public:
CFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
HWND hWndParent = NULL)
: CFileDialogImpl<CFileDialog>(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent)
{ }
// override base class map and references to handlers
DECLARE_EMPTY_MSG_MAP()
};
#if defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
class CFileDialogEx : public CFileDialogImpl<CFileDialogEx>
{
public:
CFileDialogEx( // Supports only FileOpen
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
OFN_EXFLAG ExFlags = OFN_EXFLAG_THUMBNAILVIEW,
OFN_SORTORDER dwSortOrder = OFN_SORTORDER_AUTO,
LPCTSTR lpszFilter = NULL,
HWND hWndParent = NULL)
: CFileDialogImpl<CFileDialogEx>(TRUE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent)
{
m_ofn.ExFlags = ExFlags;
m_ofn.dwSortOrder = dwSortOrder;
}
// override base class map and references to handlers
DECLARE_EMPTY_MSG_MAP()
};
#endif // defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
///////////////////////////////////////////////////////////////////////////////
// Multi File Dialog - Multi-select File Open dialog
#ifndef _WIN32_WCE
// The class dynamically resizes the buffer as the file selection changes
// (as described in Knowledge Base article 131462). It also expands selected
// shortcut files to take into account the full path of the target file.
// Note that this doesn't work on Win9x for the old style dialogs, as well as
// on NT for non-Unicode builds.
#ifndef _WTL_FIXED_OFN_BUFFER_LENGTH
#define _WTL_FIXED_OFN_BUFFER_LENGTH 0x10000
#endif
template <class T>
class ATL_NO_VTABLE CMultiFileDialogImpl : public CFileDialogImpl< T >
{
public:
mutable LPCTSTR m_pNextFile;
#ifndef _UNICODE
bool m_bIsNT;
#endif
CMultiFileDialogImpl(
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY,
LPCTSTR lpszFilter = NULL,
HWND hWndParent = NULL)
: CFileDialogImpl<T>(TRUE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent),
m_pNextFile(NULL)
{
m_ofn.Flags |= OFN_ALLOWMULTISELECT; // Force multiple selection mode
#ifndef _UNICODE
OSVERSIONINFO ovi = { sizeof(ovi) };
::GetVersionEx(&ovi);
m_bIsNT = (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT);
if (m_bIsNT)
{
// On NT platforms, GetOpenFileNameA thunks to GetOpenFileNameW and there
// is absolutely nothing we can do except to start off with a large buffer.
ATLVERIFY(ResizeFilenameBuffer(_WTL_FIXED_OFN_BUFFER_LENGTH));
}
#endif
}
~CMultiFileDialogImpl()
{
if (m_ofn.lpstrFile != m_szFileName) // Free the buffer if we allocated it
delete[] m_ofn.lpstrFile;
}
// Operations
// Get the directory that the files were chosen from.
// The function returns the number of characters copied, not including the terminating zero.
// If the buffer is NULL, the function returns the required size, in characters, including the terminating zero.
// If the function fails, the return value is zero.
int GetDirectory(LPTSTR pBuffer, int nBufLen) const
{
if (m_ofn.lpstrFile == NULL)
return 0;
LPCTSTR pStr = m_ofn.lpstrFile;
int nLength = lstrlen(pStr);
if (pStr[nLength + 1] == 0)
{
// The OFN buffer contains a single item so extract its path.
LPCTSTR pSep = _strrchr(pStr, _T('\\'));
if (pSep != NULL)
nLength = (int)(DWORD_PTR)(pSep - pStr);
}
int nRet = 0;
if (pBuffer == NULL) // If the buffer is NULL, return the required length
{
nRet = nLength + 1;
}
else if (nBufLen > nLength)
{
SecureHelper::strncpy_x(pBuffer, nBufLen, pStr, nLength);
nRet = nLength;
}
return nRet;
}
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
bool GetDirectory(_CSTRING_NS::CString& strDir) const
{
bool bRet = false;
int nLength = GetDirectory(NULL, 0);
if (nLength > 0)
{
bRet = (GetDirectory(strDir.GetBuffer(nLength), nLength) > 0);
strDir.ReleaseBuffer(nLength - 1);
}
return bRet;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
// Get the first filename as a pointer into the buffer.
LPCTSTR GetFirstFileName() const
{
if (m_ofn.lpstrFile == NULL)
return NULL;
m_pNextFile = NULL; // Reset internal buffer pointer
LPCTSTR pStr = m_ofn.lpstrFile;
int nLength = lstrlen(pStr);
if (pStr[nLength + 1] != 0)
{
// Multiple items were selected. The first string is the directory,
// so skip forwards to the second string.
pStr += nLength + 1;
// Set up m_pNext so it points to the second item (or null).
m_pNextFile = pStr;
GetNextFileName();
}
else
{
// A single item was selected. Skip forward past the path.
LPCTSTR pSep = _strrchr(pStr, _T('\\'));
if (pSep != NULL)
pStr = pSep + 1;
}
return pStr;
}
// Get the next filename as a pointer into the buffer.
LPCTSTR GetNextFileName() const
{
if (m_pNextFile == NULL)
return NULL;
LPCTSTR pStr = m_pNextFile;
// Set "m_pNextFile" to point to the next file name, or null if we
// have reached the last file in the list.
int nLength = lstrlen(pStr);
m_pNextFile = (pStr[nLength + 1] != 0) ? &pStr[nLength + 1] : NULL;
return pStr;
}
// Get the first filename as a full path.
// The function returns the number of characters copied, not including the terminating zero.
// If the buffer is NULL, the function returns the required size, in characters, including the terminating zero.
// If the function fails, the return value is zero.
int GetFirstPathName(LPTSTR pBuffer, int nBufLen) const
{
LPCTSTR pStr = GetFirstFileName();
int nLengthDir = GetDirectory(NULL, 0);
if((pStr == NULL) || (nLengthDir == 0))
return 0;
// Figure out the required length.
int nLengthTotal = nLengthDir + lstrlen(pStr);
int nRet = 0;
if(pBuffer == NULL) // If the buffer is NULL, return the required length
{
nRet = nLengthTotal + 1;
}
else if (nBufLen > nLengthTotal) // If the buffer is big enough, go ahead and construct the path
{
GetDirectory(pBuffer, nBufLen);
SecureHelper::strcat_x(pBuffer, nBufLen, _T("\\"));
SecureHelper::strcat_x(pBuffer, nBufLen, pStr);
nRet = nLengthTotal;
}
return nRet;
}
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
bool GetFirstPathName(_CSTRING_NS::CString& strPath) const
{
bool bRet = false;
int nLength = GetFirstPathName(NULL, 0);
if (nLength > 0)
{
bRet = (GetFirstPathName(strPath.GetBuffer(nLength), nLength) > 0);
strPath.ReleaseBuffer(nLength - 1);
}
return bRet;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
// Get the next filename as a full path.
// The function returns the number of characters copied, not including the terminating zero.
// If the buffer is NULL, the function returns the required size, in characters, including the terminating zero.
// If the function fails, the return value is zero.
// The internal position marker is moved forward only if the function succeeds and the buffer was large enough.
int GetNextPathName(LPTSTR pBuffer, int nBufLen) const
{
if (m_pNextFile == NULL)
return 0;
int nRet = 0;
LPCTSTR pStr = m_pNextFile;
// Does the filename contain a backslash?
if (_strrchr(pStr, _T('\\')) != NULL)
{
// Yes, so we'll assume it's a full path.
int nLength = lstrlen(pStr);
if (pBuffer == NULL) // If the buffer is NULL, return the required length
{
nRet = nLength + 1;
}
else if (nBufLen > nLength) // The buffer is big enough, so go ahead and copy the filename
{
SecureHelper::strcpy_x(pBuffer, nBufLen, GetNextFileName());
nRet = nBufLen;
}
}
else
{
// The filename is relative, so construct the full path.
int nLengthDir = GetDirectory(NULL, 0);
if (nLengthDir > 0)
{
// Calculate the required space.
int nLengthTotal = nLengthDir + lstrlen(pStr);
if(pBuffer == NULL) // If the buffer is NULL, return the required length
{
nRet = nLengthTotal + 1;
}
else if (nBufLen > nLengthTotal) // If the buffer is big enough, go ahead and construct the path
{
GetDirectory(pBuffer, nBufLen);
SecureHelper::strcat_x(pBuffer, nBufLen, _T("\\"));
SecureHelper::strcat_x(pBuffer, nBufLen, GetNextFileName());
nRet = nLengthTotal;
}
}
}
return nRet;
}
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
bool GetNextPathName(_CSTRING_NS::CString& strPath) const
{
bool bRet = false;
int nLength = GetNextPathName(NULL, 0);
if (nLength > 0)
{
bRet = (GetNextPathName(strPath.GetBuffer(nLength), nLength) > 0);
strPath.ReleaseBuffer(nLength - 1);
}
return bRet;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
// Implementation
bool ResizeFilenameBuffer(DWORD dwLength)
{
if (dwLength > m_ofn.nMaxFile)
{
// Free the old buffer.
if (m_ofn.lpstrFile != m_szFileName)
{
delete[] m_ofn.lpstrFile;
m_ofn.lpstrFile = NULL;
m_ofn.nMaxFile = 0;
}
// Allocate the new buffer.
LPTSTR lpstrBuff = NULL;
ATLTRY(lpstrBuff = new TCHAR[dwLength]);
if (lpstrBuff != NULL)
{
m_ofn.lpstrFile = lpstrBuff;
m_ofn.lpstrFile[0] = 0;
m_ofn.nMaxFile = dwLength;
}
}
return (m_ofn.lpstrFile != NULL);
}
void OnSelChange(LPOFNOTIFY /*lpon*/)
{
#ifndef _UNICODE
// There is no point resizing the buffer in ANSI builds running on NT.
if (m_bIsNT)
return;
#endif
// Get the buffer length required to hold the spec.
int nLength = GetSpec(NULL, 0);
if (nLength <= 1)
return; // no files are selected, presumably
// Add room for the directory, and an extra terminating zero.
nLength += GetFolderPath(NULL, 0) + 1;
if (!ResizeFilenameBuffer(nLength))
{
ATLASSERT(FALSE);
return;
}
// If we are not following links then our work is done.
if ((m_ofn.Flags & OFN_NODEREFERENCELINKS) != 0)
return;
// Get the file spec, which is the text in the edit control.
if (GetSpec(m_ofn.lpstrFile, m_ofn.nMaxFile) <= 0)
return;
// Get the ID-list of the current folder.
int nBytes = GetFolderIDList(NULL, 0);
CTempBuffer<ITEMIDLIST> idlist;
idlist.AllocateBytes(nBytes);
if ((nBytes <= 0) || (GetFolderIDList(idlist, nBytes) <= 0))
return;
// First bind to the desktop folder, then to the current folder.
ATL::CComPtr<IShellFolder> pDesktop, pFolder;
if (FAILED(::SHGetDesktopFolder(&pDesktop)))
return;
if (FAILED(pDesktop->BindToObject(idlist, NULL, IID_IShellFolder, (void**)&pFolder)))
return;
// Work through the file spec, looking for quoted filenames. If we find a shortcut file, then
// we need to add enough extra buffer space to hold its target path.
DWORD nExtraChars = 0;
bool bInsideQuotes = false;
LPCTSTR pAnchor = m_ofn.lpstrFile;
LPCTSTR pChar = m_ofn.lpstrFile;
for ( ; *pChar; ++pChar)
{
// Look for quotation marks.
if (*pChar == _T('\"'))
{
// We are either entering or leaving a passage of quoted text.
bInsideQuotes = !bInsideQuotes;
// Is it an opening or closing quote?
if (bInsideQuotes)
{
// We found an opening quote, so set "pAnchor" to the following character.
pAnchor = pChar + 1;
}
else // closing quote
{
// Each quoted entity should be shorter than MAX_PATH.
if (pChar - pAnchor >= MAX_PATH)
return;
// Get the ID-list and attributes of the file.
USES_CONVERSION;
int nFileNameLength = (int)(DWORD_PTR)(pChar - pAnchor);
TCHAR szFileName[MAX_PATH];
SecureHelper::strncpy_x(szFileName, MAX_PATH, pAnchor, nFileNameLength);
LPITEMIDLIST pidl = NULL;
DWORD dwAttrib = SFGAO_LINK;
if (SUCCEEDED(pFolder->ParseDisplayName(NULL, NULL, T2W(szFileName), NULL, &pidl, &dwAttrib)))
{
// Is it a shortcut file?
if (dwAttrib & SFGAO_LINK)
{
// Bind to its IShellLink interface.
ATL::CComPtr<IShellLink> pLink;
if (SUCCEEDED(pFolder->BindToObject(pidl, NULL, IID_IShellLink, (void**)&pLink)))
{
// Get the shortcut's target path.
TCHAR szPath[MAX_PATH];
if (SUCCEEDED(pLink->GetPath(szPath, MAX_PATH, NULL, 0)))
{
// If the target path is longer than the shortcut name, then add on the number
// of extra characters that are required.
int nNewLength = lstrlen(szPath);
if (nNewLength > nFileNameLength)
nExtraChars += nNewLength - nFileNameLength;
}
}
}
// Free the ID-list returned by ParseDisplayName.
::CoTaskMemFree(pidl);
}
}
}
}
// If we need more space for shortcut targets, then reallocate.
if (nExtraChars > 0)
ATLVERIFY(ResizeFilenameBuffer(m_ofn.nMaxFile + nExtraChars));
}
// Helper for _ATM_MIN_CRT
static const TCHAR* _strrchr(const TCHAR* p, TCHAR ch)
{
#ifndef _ATL_MIN_CRT
return _tcsrchr(p, ch);
#else // _ATL_MIN_CRT
const TCHAR* lpsz = NULL;
while (*p != 0)
{
if (*p == ch)
lpsz = p;
p = ::CharNext(p);
}
return lpsz;
#endif // _ATL_MIN_CRT
}
};
class CMultiFileDialog : public CMultiFileDialogImpl<CMultiFileDialog>
{
public:
CMultiFileDialog(
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY,
LPCTSTR lpszFilter = NULL,
HWND hWndParent = NULL)
: CMultiFileDialogImpl<CMultiFileDialog>(lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent)
{ }
BEGIN_MSG_MAP(CMultiFileDialog)
CHAIN_MSG_MAP(CMultiFileDialogImpl<CMultiFileDialog>)
END_MSG_MAP()
};
#endif // !_WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// Shell File Dialog - new Shell File Open and Save dialogs in Vista
// Note: Use GetPtr() to access dialog interface methods.
// Example:
// CShellFileOpenDialog dlg;
// dlg.GetPtr()->SetTitle(L"MyFileOpenDialog");
#if (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
///////////////////////////////////////////////////////////////////////////////
// CShellFileDialogImpl - base class for CShellFileOpenDialogImpl and CShellFileSaveDialogImpl
template <class T>
class ATL_NO_VTABLE CShellFileDialogImpl : public IFileDialogEvents
{
public:
// Operations
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
{
INT_PTR nRet = -1;
T* pT = static_cast<T*>(this);
if(pT->m_spFileDlg == NULL)
{
ATLASSERT(FALSE);
return nRet;
}
DWORD dwCookie = 0;
pT->_Advise(dwCookie);
HRESULT hRet = pT->m_spFileDlg->Show(hWndParent);
if(SUCCEEDED(hRet))
nRet = IDOK;
else if(hRet == HRESULT_FROM_WIN32(ERROR_CANCELLED))
nRet = IDCANCEL;
else
ATLASSERT(FALSE); // error
pT->_Unadvise(dwCookie);
return nRet;
}
bool IsNull() const
{
const T* pT = static_cast<const T*>(this);
return (pT->m_spFileDlg == NULL);
}
// Operations - get file path after dialog returns
HRESULT GetFilePath(LPWSTR lpstrFilePath, int cchLength)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg != NULL);
ATL::CComPtr<IShellItem> spItem;
HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
if(SUCCEEDED(hRet))
hRet = GetFileNameFromShellItem(spItem, SIGDN_FILESYSPATH, lpstrFilePath, cchLength);
return hRet;
}
HRESULT GetFileTitle(LPWSTR lpstrFileTitle, int cchLength)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg != NULL);
ATL::CComPtr<IShellItem> spItem;
HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
if(SUCCEEDED(hRet))
hRet = GetFileNameFromShellItem(spItem, SIGDN_NORMALDISPLAY, lpstrFileTitle, cchLength);
return hRet;
}
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
HRESULT GetFilePath(_CSTRING_NS::CString& strFilePath)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg != NULL);
ATL::CComPtr<IShellItem> spItem;
HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
if(SUCCEEDED(hRet))
hRet = GetFileNameFromShellItem(spItem, SIGDN_FILESYSPATH, strFilePath);
return hRet;
}
HRESULT GetFileTitle(_CSTRING_NS::CString& strFileTitle)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg != NULL);
ATL::CComPtr<IShellItem> spItem;
HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
if(SUCCEEDED(hRet))
hRet = GetFileNameFromShellItem(spItem, SIGDN_NORMALDISPLAY, strFileTitle);
return hRet;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
// Helpers for IShellItem
static HRESULT GetFileNameFromShellItem(IShellItem* pShellItem, SIGDN type, LPWSTR lpstr, int cchLength)
{
ATLASSERT(pShellItem != NULL);
LPWSTR lpstrName = NULL;
HRESULT hRet = pShellItem->GetDisplayName(type, &lpstrName);
if(SUCCEEDED(hRet))
{
if(lstrlenW(lpstrName) < cchLength)
{
SecureHelper::strcpyW_x(lpstr, cchLength, lpstrName);
}
else
{
ATLASSERT(FALSE);
hRet = DISP_E_BUFFERTOOSMALL;
}
::CoTaskMemFree(lpstrName);
}
return hRet;
}
#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
static HRESULT GetFileNameFromShellItem(IShellItem* pShellItem, SIGDN type, _CSTRING_NS::CString& str)
{
ATLASSERT(pShellItem != NULL);
LPWSTR lpstrName = NULL;
HRESULT hRet = pShellItem->GetDisplayName(type, &lpstrName);
if(SUCCEEDED(hRet))
{
str = lpstrName;
::CoTaskMemFree(lpstrName);
}
return hRet;
}
#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
// Implementation
void _Advise(DWORD& dwCookie)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg != NULL);
HRESULT hRet = pT->m_spFileDlg->Advise((IFileDialogEvents*)this, &dwCookie);
ATLVERIFY(SUCCEEDED(hRet));
}
void _Unadvise(DWORD dwCookie)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg != NULL);
HRESULT hRet = pT->m_spFileDlg->Unadvise(dwCookie);
ATLVERIFY(SUCCEEDED(hRet));
}
void _Init(LPCWSTR lpszFileName, DWORD dwOptions, LPCWSTR lpszDefExt, const COMDLG_FILTERSPEC* arrFilterSpec, UINT uFilterSpecCount)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg != NULL);
HRESULT hRet = E_FAIL;
if(lpszFileName != NULL)
{
hRet = pT->m_spFileDlg->SetFileName(lpszFileName);
ATLASSERT(SUCCEEDED(hRet));
}
hRet = pT->m_spFileDlg->SetOptions(dwOptions);
ATLASSERT(SUCCEEDED(hRet));
if(lpszDefExt != NULL)
{
hRet = pT->m_spFileDlg->SetDefaultExtension(lpszDefExt);
ATLASSERT(SUCCEEDED(hRet));
}
if(arrFilterSpec != NULL && uFilterSpecCount != 0U)
{
hRet = pT->m_spFileDlg->SetFileTypes(uFilterSpecCount, arrFilterSpec);
ATLASSERT(SUCCEEDED(hRet));
}
}
// Implementation - IUnknown interface
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject)
{
if(ppvObject == NULL)
return E_POINTER;
T* pT = static_cast<T*>(this);
if(IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IFileDialogEvents))
{
*ppvObject = (IFileDialogEvents*)pT;
// AddRef() not needed
return S_OK;
}
return E_NOINTERFACE;
}
virtual ULONG STDMETHODCALLTYPE AddRef()
{
return 1;
}
virtual ULONG STDMETHODCALLTYPE Release()
{
return 1;
}
// Implementation - IFileDialogEvents interface
virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnFileOk(IFileDialog* pfd)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
pfd; // avoid level 4 warning
return pT->OnFileOk();
}
virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnFolderChanging(IFileDialog* pfd, IShellItem* psiFolder)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
pfd; // avoid level 4 warning
return pT->OnFolderChanging(psiFolder);
}
virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnFolderChange(IFileDialog* pfd)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
pfd; // avoid level 4 warning
return pT->OnFolderChange();
}
virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnSelectionChange(IFileDialog* pfd)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
pfd; // avoid level 4 warning
return pT->OnSelectionChange();
}
virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnShareViolation(IFileDialog* pfd, IShellItem* psi, FDE_SHAREVIOLATION_RESPONSE* pResponse)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
pfd; // avoid level 4 warning
return pT->OnShareViolation(psi, pResponse);
}
virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnTypeChange(IFileDialog* pfd)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
pfd; // avoid level 4 warning
return pT->OnTypeChange();
}
virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnOverwrite(IFileDialog* pfd, IShellItem* psi, FDE_OVERWRITE_RESPONSE* pResponse)
{
T* pT = static_cast<T*>(this);
ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
pfd; // avoid level 4 warning
return pT->OnOverwrite(psi, pResponse);
}
// Overrideables - Event handlers
HRESULT OnFileOk()
{
return E_NOTIMPL;
}
HRESULT OnFolderChanging(IShellItem* /*psiFolder*/)
{
return E_NOTIMPL;
}
HRESULT OnFolderChange()
{
return E_NOTIMPL;
}
HRESULT OnSelectionChange()
{
return E_NOTIMPL;
}
HRESULT OnShareViolation(IShellItem* /*psi*/, FDE_SHAREVIOLATION_RESPONSE* /*pResponse*/)
{
return E_NOTIMPL;
}
HRESULT OnTypeChange()
{
return E_NOTIMPL;
}
HRESULT OnOverwrite(IShellItem* /*psi*/, FDE_OVERWRITE_RESPONSE* /*pResponse*/)
{
return E_NOTIMPL;
}
};
///////////////////////////////////////////////////////////////////////////////
// CShellFileOpenDialogImpl - implements new Shell File Open dialog
template <class T>
class ATL_NO_VTABLE CShellFileOpenDialogImpl : public CShellFileDialogImpl< T >
{
public:
ATL::CComPtr<IFileOpenDialog> m_spFileDlg;
CShellFileOpenDialogImpl(LPCWSTR lpszFileName = NULL,
DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST,
LPCWSTR lpszDefExt = NULL,
const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
UINT uFilterSpecCount = 0U)
{
HRESULT hRet = m_spFileDlg.CoCreateInstance(CLSID_FileOpenDialog);
if(SUCCEEDED(hRet))
_Init(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount);
}
IFileOpenDialog* GetPtr()
{
return m_spFileDlg;
}
};
///////////////////////////////////////////////////////////////////////////////
// CShellFileOpenDialog - new Shell File Open dialog without events
class CShellFileOpenDialog : public CShellFileOpenDialogImpl<CShellFileOpenDialog>
{
public:
CShellFileOpenDialog(LPCWSTR lpszFileName = NULL,
DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST,
LPCWSTR lpszDefExt = NULL,
const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
UINT uFilterSpecCount = 0U) : CShellFileOpenDialogImpl<CShellFileOpenDialog>(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount)
{ }
// Implementation (remove _Advise/_Unadvise code using template magic)
void _Advise(DWORD& /*dwCookie*/)
{ }
void _Unadvise(DWORD /*dwCookie*/)
{ }
};
///////////////////////////////////////////////////////////////////////////////
// CShellFileSaveDialogImpl - implements new Shell File Save dialog
template <class T>
class ATL_NO_VTABLE CShellFileSaveDialogImpl : public CShellFileDialogImpl< T >
{
public:
ATL::CComPtr<IFileSaveDialog> m_spFileDlg;
CShellFileSaveDialogImpl(LPCWSTR lpszFileName = NULL,
DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_OVERWRITEPROMPT,
LPCWSTR lpszDefExt = NULL,
const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
UINT uFilterSpecCount = 0U)
{
HRESULT hRet = m_spFileDlg.CoCreateInstance(CLSID_FileSaveDialog);
if(SUCCEEDED(hRet))
_Init(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount);
}
IFileSaveDialog* GetPtr()
{
return m_spFileDlg;
}
};
///////////////////////////////////////////////////////////////////////////////
// CShellFileSaveDialog - new Shell File Save dialog without events
class CShellFileSaveDialog : public CShellFileSaveDialogImpl<CShellFileSaveDialog>
{
public:
CShellFileSaveDialog(LPCWSTR lpszFileName = NULL,
DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_OVERWRITEPROMPT,
LPCWSTR lpszDefExt = NULL,
const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
UINT uFilterSpecCount = 0U) : CShellFileSaveDialogImpl<CShellFileSaveDialog>(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount)
{ }
// Implementation (remove _Advise/_Unadvise code using template magic)
void _Advise(DWORD& /*dwCookie*/)
{ }
void _Unadvise(DWORD /*dwCookie*/)
{ }
};
#endif // (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
///////////////////////////////////////////////////////////////////////////////
// CFolderDialogImpl - used for browsing for a folder
#ifndef _WIN32_WCE
template <class T>
class ATL_NO_VTABLE CFolderDialogImpl
{
public:
BROWSEINFO m_bi;
LPCTSTR m_lpstrInitialFolder;
LPCITEMIDLIST m_pidlInitialSelection;
bool m_bExpandInitialSelection;
TCHAR m_szFolderDisplayName[MAX_PATH];
TCHAR m_szFolderPath[MAX_PATH];
LPITEMIDLIST m_pidlSelected;
HWND m_hWnd; // used only in the callback function
// Constructor
CFolderDialogImpl(HWND hWndParent = NULL, LPCTSTR lpstrTitle = NULL, UINT uFlags = BIF_RETURNONLYFSDIRS) :
m_lpstrInitialFolder(NULL), m_pidlInitialSelection(NULL), m_bExpandInitialSelection(false), m_pidlSelected(NULL), m_hWnd(NULL)
{
memset(&m_bi, 0, sizeof(m_bi)); // initialize structure to 0/NULL
m_bi.hwndOwner = hWndParent;
m_bi.pidlRoot = NULL;
m_bi.pszDisplayName = m_szFolderDisplayName;
m_bi.lpszTitle = lpstrTitle;
m_bi.ulFlags = uFlags;
m_bi.lpfn = BrowseCallbackProc;
m_bi.lParam = (LPARAM)static_cast<T*>(this);
m_szFolderPath[0] = 0;
m_szFolderDisplayName[0] = 0;
}
~CFolderDialogImpl()
{
::CoTaskMemFree(m_pidlSelected);
}
// Operations
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
{
if(m_bi.hwndOwner == NULL) // set only if not specified before
m_bi.hwndOwner = hWndParent;
// Clear out any previous results
m_szFolderPath[0] = 0;
m_szFolderDisplayName[0] = 0;
::CoTaskMemFree(m_pidlSelected);
INT_PTR nRet = IDCANCEL;
m_pidlSelected = ::SHBrowseForFolder(&m_bi);
if(m_pidlSelected != NULL)
{
nRet = IDOK;
// If BIF_RETURNONLYFSDIRS is set, we try to get the filesystem path.
// Otherwise, the caller must handle the ID-list directly.
if((m_bi.ulFlags & BIF_RETURNONLYFSDIRS) != 0)
{
if(::SHGetPathFromIDList(m_pidlSelected, m_szFolderPath) == FALSE)
nRet = IDCANCEL;
}
}
return nRet;
}
// Methods to call before DoModal
void SetInitialFolder(LPCTSTR lpstrInitialFolder, bool bExpand = true)
{
// lpstrInitialFolder may be a file if BIF_BROWSEINCLUDEFILES is specified
m_lpstrInitialFolder = lpstrInitialFolder;
m_bExpandInitialSelection = bExpand;
}
void SetInitialSelection(LPCITEMIDLIST pidl, bool bExpand = true)
{
m_pidlInitialSelection = pidl;
m_bExpandInitialSelection = bExpand;
}
// Methods to call after DoModal
LPITEMIDLIST GetSelectedItem(bool bDetach = false)
{
LPITEMIDLIST pidl = m_pidlSelected;
if(bDetach)
m_pidlSelected = NULL;
return pidl;
}
LPCTSTR GetFolderPath() const
{
return m_szFolderPath;
}
LPCTSTR GetFolderDisplayName() const
{
return m_szFolderDisplayName;
}
int GetFolderImageIndex() const
{
return m_bi.iImage;
}
// Callback function and overrideables
static int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
#ifndef BFFM_VALIDATEFAILED
#ifdef UNICODE
const int BFFM_VALIDATEFAILED = 4;
#else
const int BFFM_VALIDATEFAILED = 3;
#endif
#endif // !BFFM_VALIDATEFAILED
#ifndef BFFM_IUNKNOWN
const int BFFM_IUNKNOWN = 5;
#endif // !BFFM_IUNKNOWN
#ifndef BIF_NEWDIALOGSTYLE
const UINT BIF_NEWDIALOGSTYLE = 0x0040;
#endif // !BIF_NEWDIALOGSTYLE
int nRet = 0;
T* pT = (T*)lpData;
bool bClear = false;
if(pT->m_hWnd == NULL)
{
pT->m_hWnd = hWnd;
bClear = true;
}
else
{
ATLASSERT(pT->m_hWnd == hWnd);
}
switch(uMsg)
{
case BFFM_INITIALIZED:
// Set initial selection
// Note that m_pidlInitialSelection, if set, takes precedence over m_lpstrInitialFolder
if(pT->m_pidlInitialSelection != NULL)
pT->SetSelection(pT->m_pidlInitialSelection);
else if(pT->m_lpstrInitialFolder != NULL)
pT->SetSelection(pT->m_lpstrInitialFolder);
// Expand initial selection if appropriate
if(pT->m_bExpandInitialSelection && ((pT->m_bi.ulFlags & BIF_NEWDIALOGSTYLE) != 0))
{
if(pT->m_pidlInitialSelection != NULL)
pT->SetExpanded(pT->m_pidlInitialSelection);
else if(pT->m_lpstrInitialFolder != NULL)
pT->SetExpanded(pT->m_lpstrInitialFolder);
}
pT->OnInitialized();
break;
case BFFM_SELCHANGED:
pT->OnSelChanged((LPITEMIDLIST)lParam);
break;
case BFFM_VALIDATEFAILED:
nRet = pT->OnValidateFailed((LPCTSTR)lParam);
break;
case BFFM_IUNKNOWN:
pT->OnIUnknown((IUnknown*)lParam);
break;
default:
ATLTRACE2(atlTraceUI, 0, _T("Unknown message received in CFolderDialogImpl::BrowseCallbackProc\n"));
break;
}
if(bClear)
pT->m_hWnd = NULL;
return nRet;
}
void OnInitialized()
{
}
void OnSelChanged(LPITEMIDLIST /*pItemIDList*/)
{
}
int OnValidateFailed(LPCTSTR /*lpstrFolderPath*/)
{
return 1; // 1=continue, 0=EndDialog
}
void OnIUnknown(IUnknown* /*pUnknown*/)
{
}
// Commands - valid to call only from handlers
void EnableOK(BOOL bEnable)
{
ATLASSERT(m_hWnd != NULL);
::SendMessage(m_hWnd, BFFM_ENABLEOK, 0, bEnable);
}
void SetSelection(LPCITEMIDLIST pItemIDList)
{
ATLASSERT(m_hWnd != NULL);
::SendMessage(m_hWnd, BFFM_SETSELECTION, FALSE, (LPARAM)pItemIDList);
}
void SetSelection(LPCTSTR lpstrFolderPath)
{
ATLASSERT(m_hWnd != NULL);
::SendMessage(m_hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)lpstrFolderPath);
}
void SetStatusText(LPCTSTR lpstrText)
{
ATLASSERT(m_hWnd != NULL);
::SendMessage(m_hWnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)lpstrText);
}
void SetOKText(LPCTSTR lpstrOKText)
{
#ifndef BFFM_SETOKTEXT
const UINT BFFM_SETOKTEXT = WM_USER + 105;
#endif
ATLASSERT(m_hWnd != NULL);
USES_CONVERSION;
LPCWSTR lpstr = T2CW(lpstrOKText);
::SendMessage(m_hWnd, BFFM_SETOKTEXT, (WPARAM)lpstr, 0L);
}
void SetExpanded(LPCITEMIDLIST pItemIDList)
{
#ifndef BFFM_SETEXPANDED
const UINT BFFM_SETEXPANDED = WM_USER + 106;
#endif
ATLASSERT(m_hWnd != NULL);
::SendMessage(m_hWnd, BFFM_SETEXPANDED, FALSE, (LPARAM)pItemIDList);
}
void SetExpanded(LPCTSTR lpstrFolderPath)
{
#ifndef BFFM_SETEXPANDED
const UINT BFFM_SETEXPANDED = WM_USER + 106;
#endif
ATLASSERT(m_hWnd != NULL);
USES_CONVERSION;
LPCWSTR lpstr = T2CW(lpstrFolderPath);
::SendMessage(m_hWnd, BFFM_SETEXPANDED, TRUE, (LPARAM)lpstr);
}
};
class CFolderDialog : public CFolderDialogImpl<CFolderDialog>
{
public:
CFolderDialog(HWND hWndParent = NULL, LPCTSTR lpstrTitle = NULL, UINT uFlags = BIF_RETURNONLYFSDIRS)
: CFolderDialogImpl<CFolderDialog>(hWndParent, lpstrTitle, uFlags)
{ }
};
#endif // !_WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CCommonDialogImplBase - base class for common dialog classes
class ATL_NO_VTABLE CCommonDialogImplBase : public ATL::CWindowImplBase
{
public:
static UINT_PTR APIENTRY HookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(uMsg != WM_INITDIALOG)
return 0;
CCommonDialogImplBase* pT = (CCommonDialogImplBase*)ModuleHelper::ExtractCreateWndData();
ATLASSERT(pT != NULL);
ATLASSERT(pT->m_hWnd == NULL);
ATLASSERT(::IsWindow(hWnd));
// subclass dialog's window
if(!pT->SubclassWindow(hWnd))
{
ATLTRACE2(atlTraceUI, 0, _T("Subclassing a common dialog failed\n"));
return 0;
}
// check message map for WM_INITDIALOG handler
LRESULT lRes = 0;
if(pT->ProcessWindowMessage(pT->m_hWnd, uMsg, wParam, lParam, lRes, 0) == FALSE)
return 0;
return lRes;
}
// Special override for common dialogs
BOOL EndDialog(INT_PTR /*nRetCode*/ = 0)
{
ATLASSERT(::IsWindow(m_hWnd));
SendMessage(WM_COMMAND, MAKEWPARAM(IDABORT, 0));
return TRUE;
}
// Implementation - try to override these, to prevent errors
HWND Create(HWND, ATL::_U_RECT, LPCTSTR, DWORD, DWORD, ATL::_U_MENUorID, ATOM, LPVOID)
{
ATLASSERT(FALSE); // should not be called
return NULL;
}
static LRESULT CALLBACK StartWindowProc(HWND /*hWnd*/, UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
{
ATLASSERT(FALSE); // should not be called
return 0;
}
};
///////////////////////////////////////////////////////////////////////////////
// CFontDialogImpl - font selection dialog
#ifndef _WIN32_WCE
template <class T>
class ATL_NO_VTABLE CFontDialogImpl : public CCommonDialogImplBase
{
public:
enum { _cchStyleName = 64 };
CHOOSEFONT m_cf;
TCHAR m_szStyleName[_cchStyleName]; // contains style name after return
LOGFONT m_lf; // default LOGFONT to store the info
// Constructors
CFontDialogImpl(LPLOGFONT lplfInitial = NULL,
DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS,
HDC hDCPrinter = NULL,
HWND hWndParent = NULL)
{
memset(&m_cf, 0, sizeof(m_cf));
memset(&m_lf, 0, sizeof(m_lf));
memset(&m_szStyleName, 0, sizeof(m_szStyleName));
m_cf.lStructSize = sizeof(m_cf);
m_cf.hwndOwner = hWndParent;
m_cf.rgbColors = RGB(0, 0, 0);
m_cf.lpszStyle = (LPTSTR)&m_szStyleName;
m_cf.Flags = dwFlags | CF_ENABLEHOOK;
m_cf.lpfnHook = (LPCFHOOKPROC)T::HookProc;
if(lplfInitial != NULL)
{
m_cf.lpLogFont = lplfInitial;
m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
m_lf = *lplfInitial;
}
else
{
m_cf.lpLogFont = &m_lf;
}
if(hDCPrinter != NULL)
{
m_cf.hDC = hDCPrinter;
m_cf.Flags |= CF_PRINTERFONTS;
}
}
// Operations
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
{
ATLASSERT((m_cf.Flags & CF_ENABLEHOOK) != 0);
ATLASSERT(m_cf.lpfnHook != NULL); // can still be a user hook
if(m_cf.hwndOwner == NULL) // set only if not specified before
m_cf.hwndOwner = hWndParent;
ATLASSERT(m_hWnd == NULL);
ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
BOOL bRet = ::ChooseFont(&m_cf);
m_hWnd = NULL;
if(bRet) // copy logical font from user's initialization buffer (if needed)
SecureHelper::memcpy_x(&m_lf, sizeof(m_lf), m_cf.lpLogFont, sizeof(m_lf));
return bRet ? IDOK : IDCANCEL;
}
// works only when the dialog is dislayed or after
void GetCurrentFont(LPLOGFONT lplf) const
{
ATLASSERT(lplf != NULL);
if(m_hWnd != NULL)
::SendMessage(m_hWnd, WM_CHOOSEFONT_GETLOGFONT, 0, (LPARAM)lplf);
else
*lplf = m_lf;
}
// works only when the dialog is dislayed or before
#ifndef _WIN32_WCE
void SetLogFont(LPLOGFONT lplf)
{
ATLASSERT(lplf != NULL);
#ifndef WM_CHOOSEFONT_SETLOGFONT
const UINT WM_CHOOSEFONT_SETLOGFONT = (WM_USER + 101);
#endif
if(m_hWnd != NULL)
{
::SendMessage(m_hWnd, WM_CHOOSEFONT_SETLOGFONT, 0, (LPARAM)lplf);
}
else
{
m_lf = *lplf;
m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
}
}
void SetFlags(DWORD dwFlags)
{
#ifndef WM_CHOOSEFONT_SETFLAGS
const UINT WM_CHOOSEFONT_SETFLAGS = (WM_USER + 102);
#endif
if(m_hWnd != NULL)
{
CHOOSEFONT cf = { sizeof(CHOOSEFONT) };
cf.Flags = dwFlags;
::SendMessage(m_hWnd, WM_CHOOSEFONT_SETFLAGS, 0, (LPARAM)&cf);
}
else
{
m_cf.Flags = dwFlags;
}
}
#endif // !_WIN32_WCE
// Helpers for parsing information after successful return
LPCTSTR GetFaceName() const // return the face name of the font
{
return (LPCTSTR)m_cf.lpLogFont->lfFaceName;
}
LPCTSTR GetStyleName() const // return the style name of the font
{
return m_cf.lpszStyle;
}
int GetSize() const // return the pt size of the font
{
return m_cf.iPointSize;
}
COLORREF GetColor() const // return the color of the font
{
return m_cf.rgbColors;
}
int GetWeight() const // return the chosen font weight
{
return (int)m_cf.lpLogFont->lfWeight;
}
BOOL IsStrikeOut() const // return TRUE if strikeout
{
return (m_cf.lpLogFont->lfStrikeOut) ? TRUE : FALSE;
}
BOOL IsUnderline() const // return TRUE if underline
{
return (m_cf.lpLogFont->lfUnderline) ? TRUE : FALSE;
}
BOOL IsBold() const // return TRUE if bold font
{
return (m_cf.lpLogFont->lfWeight == FW_BOLD) ? TRUE : FALSE;
}
BOOL IsItalic() const // return TRUE if italic font
{
return m_cf.lpLogFont->lfItalic ? TRUE : FALSE;
}
};
class CFontDialog : public CFontDialogImpl<CFontDialog>
{
public:
CFontDialog(LPLOGFONT lplfInitial = NULL,
DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS,
HDC hDCPrinter = NULL,
HWND hWndParent = NULL)
: CFontDialogImpl<CFontDialog>(lplfInitial, dwFlags, hDCPrinter, hWndParent)
{ }
DECLARE_EMPTY_MSG_MAP()
};
#endif // _WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CRichEditFontDialogImpl - font selection for the Rich Edit ctrl
#if defined(_RICHEDIT_) && !defined(_WIN32_WCE)
template <class T>
class ATL_NO_VTABLE CRichEditFontDialogImpl : public CFontDialogImpl< T >
{
public:
CRichEditFontDialogImpl(const CHARFORMAT& charformat,
DWORD dwFlags = CF_SCREENFONTS,
HDC hDCPrinter = NULL,
HWND hWndParent = NULL)
: CFontDialogImpl< T >(NULL, dwFlags, hDCPrinter, hWndParent)
{
m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
m_cf.Flags |= FillInLogFont(charformat);
m_cf.lpLogFont = &m_lf;
if((charformat.dwMask & CFM_COLOR) != 0)
m_cf.rgbColors = charformat.crTextColor;
}
void GetCharFormat(CHARFORMAT& cf) const
{
USES_CONVERSION;
cf.dwEffects = 0;
cf.dwMask = 0;
if((m_cf.Flags & CF_NOSTYLESEL) == 0)
{
cf.dwMask |= CFM_BOLD | CFM_ITALIC;
cf.dwEffects |= IsBold() ? CFE_BOLD : 0;
cf.dwEffects |= IsItalic() ? CFE_ITALIC : 0;
}
if((m_cf.Flags & CF_NOSIZESEL) == 0)
{
cf.dwMask |= CFM_SIZE;
// GetSize() returns in tenths of points so mulitply by 2 to get twips
cf.yHeight = GetSize() * 2;
}
if((m_cf.Flags & CF_NOFACESEL) == 0)
{
cf.dwMask |= CFM_FACE;
cf.bPitchAndFamily = m_cf.lpLogFont->lfPitchAndFamily;
#if (_RICHEDIT_VER >= 0x0200)
SecureHelper::strcpy_x(cf.szFaceName, _countof(cf.szFaceName), GetFaceName());
#else // !(_RICHEDIT_VER >= 0x0200)
SecureHelper::strcpyA_x(cf.szFaceName, _countof(cf.szFaceName), T2A((LPTSTR)(LPCTSTR)GetFaceName()));
#endif // !(_RICHEDIT_VER >= 0x0200)
}
if((m_cf.Flags & CF_EFFECTS) != 0)
{
cf.dwMask |= CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR;
cf.dwEffects |= IsUnderline() ? CFE_UNDERLINE : 0;
cf.dwEffects |= IsStrikeOut() ? CFE_STRIKEOUT : 0;
cf.crTextColor = GetColor();
}
if((m_cf.Flags & CF_NOSCRIPTSEL) == 0)
{
cf.bCharSet = m_cf.lpLogFont->lfCharSet;
cf.dwMask |= CFM_CHARSET;
}
cf.yOffset = 0;
}
DWORD FillInLogFont(const CHARFORMAT& cf)
{
USES_CONVERSION;
DWORD dwFlags = 0;
if((cf.dwMask & CFM_SIZE) != 0)
{
HDC hDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
LONG yPerInch = ::GetDeviceCaps(hDC, LOGPIXELSY);
m_lf.lfHeight = -(int)((cf.yHeight * yPerInch) / 1440);
}
else
m_lf.lfHeight = 0;
m_lf.lfWidth = 0;
m_lf.lfEscapement = 0;
m_lf.lfOrientation = 0;
if((cf.dwMask & (CFM_ITALIC | CFM_BOLD)) == (CFM_ITALIC | CFM_BOLD))
{
m_lf.lfWeight = ((cf.dwEffects & CFE_BOLD) != 0) ? FW_BOLD : FW_NORMAL;
m_lf.lfItalic = (BYTE)(((cf.dwEffects & CFE_ITALIC) != 0) ? TRUE : FALSE);
}
else
{
dwFlags |= CF_NOSTYLESEL;
m_lf.lfWeight = FW_DONTCARE;
m_lf.lfItalic = FALSE;
}
if((cf.dwMask & (CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR)) == (CFM_UNDERLINE|CFM_STRIKEOUT|CFM_COLOR))
{
dwFlags |= CF_EFFECTS;
m_lf.lfUnderline = (BYTE)(((cf.dwEffects & CFE_UNDERLINE) != 0) ? TRUE : FALSE);
m_lf.lfStrikeOut = (BYTE)(((cf.dwEffects & CFE_STRIKEOUT) != 0) ? TRUE : FALSE);
}
else
{
m_lf.lfUnderline = (BYTE)FALSE;
m_lf.lfStrikeOut = (BYTE)FALSE;
}
if((cf.dwMask & CFM_CHARSET) != 0)
m_lf.lfCharSet = cf.bCharSet;
else
dwFlags |= CF_NOSCRIPTSEL;
m_lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
m_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
m_lf.lfQuality = DEFAULT_QUALITY;
if((cf.dwMask & CFM_FACE) != 0)
{
m_lf.lfPitchAndFamily = cf.bPitchAndFamily;
#if (_RICHEDIT_VER >= 0x0200)
SecureHelper::strcpy_x(m_lf.lfFaceName, _countof(m_lf.lfFaceName), cf.szFaceName);
#else // !(_RICHEDIT_VER >= 0x0200)
SecureHelper::strcpy_x(m_lf.lfFaceName, _countof(m_lf.lfFaceName), A2T((LPSTR)cf.szFaceName));
#endif // !(_RICHEDIT_VER >= 0x0200)
}
else
{
m_lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
m_lf.lfFaceName[0] = (TCHAR)0;
}
return dwFlags;
}
};
class CRichEditFontDialog : public CRichEditFontDialogImpl<CRichEditFontDialog>
{
public:
CRichEditFontDialog(const CHARFORMAT& charformat,
DWORD dwFlags = CF_SCREENFONTS,
HDC hDCPrinter = NULL,
HWND hWndParent = NULL)
: CRichEditFontDialogImpl<CRichEditFontDialog>(charformat, dwFlags, hDCPrinter, hWndParent)
{ }
DECLARE_EMPTY_MSG_MAP()
};
#endif // defined(_RICHEDIT_) && !defined(_WIN32_WCE)
///////////////////////////////////////////////////////////////////////////////
// CColorDialogImpl - color selection
#if !defined(_WIN32_WCE) || ((_WIN32_WCE > 420) && !(defined(WIN32_PLATFORM_WFSP) && (_WIN32_WCE > 0x0500)))
#ifdef _WIN32_WCE
#pragma comment(lib, "commdlg.lib")
#ifndef SETRGBSTRING
#define SETRGBSTRING _T("commdlg_SetRGBColor")
#endif
#ifndef COLOROKSTRING
#define COLOROKSTRING _T("commdlg_ColorOK")
#endif
#endif
template <class T>
class ATL_NO_VTABLE CColorDialogImpl : public CCommonDialogImplBase
{
public:
CHOOSECOLOR m_cc;
// Constructor
CColorDialogImpl(COLORREF clrInit = 0, DWORD dwFlags = 0, HWND hWndParent = NULL)
{
memset(&m_cc, 0, sizeof(m_cc));
m_cc.lStructSize = sizeof(m_cc);
m_cc.lpCustColors = GetCustomColors();
m_cc.hwndOwner = hWndParent;
m_cc.Flags = dwFlags | CC_ENABLEHOOK;
m_cc.lpfnHook = (LPCCHOOKPROC)T::HookProc;
if(clrInit != 0)
{
m_cc.rgbResult = clrInit;
m_cc.Flags |= CC_RGBINIT;
}
}
// Operations
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
{
ATLASSERT((m_cc.Flags & CC_ENABLEHOOK) != 0);
ATLASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
if(m_cc.hwndOwner == NULL) // set only if not specified before
m_cc.hwndOwner = hWndParent;
ATLASSERT(m_hWnd == NULL);
ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
BOOL bRet = ::ChooseColor(&m_cc);
m_hWnd = NULL;
return bRet ? IDOK : IDCANCEL;
}
// Set the current color while dialog is displayed
void SetCurrentColor(COLORREF clr)
{
ATLASSERT(::IsWindow(m_hWnd));
SendMessage(_GetSetRGBMessage(), 0, (LPARAM)clr);
}
// Get the selected color after DoModal returns, or in OnColorOK
COLORREF GetColor() const
{
return m_cc.rgbResult;
}
// Special override for the color dialog
static UINT_PTR APIENTRY HookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(uMsg != WM_INITDIALOG && uMsg != _GetColorOKMessage())
return 0;
LPCHOOSECOLOR lpCC = (LPCHOOSECOLOR)lParam;
CCommonDialogImplBase* pT = NULL;
if(uMsg == WM_INITDIALOG)
{
pT = (CCommonDialogImplBase*)ModuleHelper::ExtractCreateWndData();
lpCC->lCustData = (LPARAM)pT;
ATLASSERT(pT != NULL);
ATLASSERT(pT->m_hWnd == NULL);
ATLASSERT(::IsWindow(hWnd));
// subclass dialog's window
if(!pT->SubclassWindow(hWnd))
{
ATLTRACE2(atlTraceUI, 0, _T("Subclassing a Color common dialog failed\n"));
return 0;
}
}
else if(uMsg == _GetColorOKMessage())
{
pT = (CCommonDialogImplBase*)lpCC->lCustData;
ATLASSERT(pT != NULL);
ATLASSERT(::IsWindow(pT->m_hWnd));
}
// pass to the message map
LRESULT lRes;
if(pT->ProcessWindowMessage(pT->m_hWnd, uMsg, wParam, lParam, lRes, 0) == FALSE)
return 0;
return lRes;
}
// Helpers
static COLORREF* GetCustomColors()
{
static COLORREF rgbCustomColors[16] =
{
RGB(255, 255, 255), RGB(255, 255, 255),
RGB(255, 255, 255), RGB(255, 255, 255),
RGB(255, 255, 255), RGB(255, 255, 255),
RGB(255, 255, 255), RGB(255, 255, 255),
RGB(255, 255, 255), RGB(255, 255, 255),
RGB(255, 255, 255), RGB(255, 255, 255),
RGB(255, 255, 255), RGB(255, 255, 255),
RGB(255, 255, 255), RGB(255, 255, 255),
};
return rgbCustomColors;
}
static UINT _GetSetRGBMessage()
{
static UINT uSetRGBMessage = 0;
if(uSetRGBMessage == 0)
{
CStaticDataInitCriticalSectionLock lock;
if(FAILED(lock.Lock()))
{
ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CColorDialogImpl::_GetSetRGBMessage.\n"));
ATLASSERT(FALSE);
return 0;
}
if(uSetRGBMessage == 0)
uSetRGBMessage = ::RegisterWindowMessage(SETRGBSTRING);
lock.Unlock();
}
ATLASSERT(uSetRGBMessage != 0);
return uSetRGBMessage;
}
static UINT _GetColorOKMessage()
{
static UINT uColorOKMessage = 0;
if(uColorOKMessage == 0)
{
CStaticDataInitCriticalSectionLock lock;
if(FAILED(lock.Lock()))
{
ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CColorDialogImpl::_GetColorOKMessage.\n"));
ATLASSERT(FALSE);
return 0;
}
if(uColorOKMessage == 0)
uColorOKMessage = ::RegisterWindowMessage(COLOROKSTRING);
lock.Unlock();
}
ATLASSERT(uColorOKMessage != 0);
return uColorOKMessage;
}
// Message map and handlers
BEGIN_MSG_MAP(CColorDialogImpl)
MESSAGE_HANDLER(_GetColorOKMessage(), _OnColorOK)
END_MSG_MAP()
LRESULT _OnColorOK(UINT, WPARAM, LPARAM, BOOL&)
{
T* pT = static_cast<T*>(this);
return pT->OnColorOK();
}
// Overrideable
BOOL OnColorOK() // validate color
{
return FALSE;
}
};
class CColorDialog : public CColorDialogImpl<CColorDialog>
{
public:
CColorDialog(COLORREF clrInit = 0, DWORD dwFlags = 0, HWND hWndParent = NULL)
: CColorDialogImpl<CColorDialog>(clrInit, dwFlags, hWndParent)
{ }
// override base class map and references to handlers
DECLARE_EMPTY_MSG_MAP()
};
#endif // !defined(_WIN32_WCE) || ((_WIN32_WCE > 420) && !(defined(WIN32_PLATFORM_WFSP) && (_WIN32_WCE > 0x0500)))
///////////////////////////////////////////////////////////////////////////////
// CPrintDialogImpl - used for Print... and PrintSetup...
#ifndef _WIN32_WCE
// global helper
static HDC _AtlCreateDC(HGLOBAL hDevNames, HGLOBAL hDevMode)
{
if(hDevNames == NULL)
return NULL;
LPDEVNAMES lpDevNames = (LPDEVNAMES)::GlobalLock(hDevNames);
LPDEVMODE lpDevMode = (hDevMode != NULL) ? (LPDEVMODE)::GlobalLock(hDevMode) : NULL;
if(lpDevNames == NULL)
return NULL;
HDC hDC = ::CreateDC((LPCTSTR)lpDevNames + lpDevNames->wDriverOffset,
(LPCTSTR)lpDevNames + lpDevNames->wDeviceOffset,
(LPCTSTR)lpDevNames + lpDevNames->wOutputOffset,
lpDevMode);
::GlobalUnlock(hDevNames);
if(hDevMode != NULL)
::GlobalUnlock(hDevMode);
return hDC;
}
template <class T>
class ATL_NO_VTABLE CPrintDialogImpl : public CCommonDialogImplBase
{
public:
// print dialog parameter block (note this is a reference)
PRINTDLG& m_pd;
// Constructors
CPrintDialogImpl(BOOL bPrintSetupOnly = FALSE, // TRUE for Print Setup, FALSE for Print Dialog
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION,
HWND hWndParent = NULL)
: m_pd(m_pdActual)
{
memset(&m_pdActual, 0, sizeof(m_pdActual));
m_pd.lStructSize = sizeof(m_pdActual);
m_pd.hwndOwner = hWndParent;
m_pd.Flags = (dwFlags | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK);
m_pd.lpfnPrintHook = (LPPRINTHOOKPROC)T::HookProc;
m_pd.lpfnSetupHook = (LPSETUPHOOKPROC)T::HookProc;
if(bPrintSetupOnly)
m_pd.Flags |= PD_PRINTSETUP;
else
m_pd.Flags |= PD_RETURNDC;
m_pd.Flags &= ~PD_RETURNIC; // do not support information context
}
// Operations
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
{
ATLASSERT((m_pd.Flags & PD_ENABLEPRINTHOOK) != 0);
ATLASSERT((m_pd.Flags & PD_ENABLESETUPHOOK) != 0);
ATLASSERT(m_pd.lpfnPrintHook != NULL); // can still be a user hook
ATLASSERT(m_pd.lpfnSetupHook != NULL); // can still be a user hook
ATLASSERT((m_pd.Flags & PD_RETURNDEFAULT) == 0); // use GetDefaults for this
if(m_pd.hwndOwner == NULL) // set only if not specified before
m_pd.hwndOwner = hWndParent;
ATLASSERT(m_hWnd == NULL);
ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
BOOL bRet = ::PrintDlg(&m_pd);
m_hWnd = NULL;
return bRet ? IDOK : IDCANCEL;
}
// GetDefaults will not display a dialog but will get device defaults
BOOL GetDefaults()
{
m_pd.Flags |= PD_RETURNDEFAULT;
ATLASSERT(m_pd.hDevMode == NULL); // must be NULL
ATLASSERT(m_pd.hDevNames == NULL); // must be NULL
return ::PrintDlg(&m_pd);
}
// Helpers for parsing information after successful return num. copies requested
int GetCopies() const
{
if((m_pd.Flags & PD_USEDEVMODECOPIES) != 0)
{
LPDEVMODE lpDevMode = GetDevMode();
return (lpDevMode != NULL) ? lpDevMode->dmCopies : -1;
}
return m_pd.nCopies;
}
BOOL PrintCollate() const // TRUE if collate checked
{
return ((m_pd.Flags & PD_COLLATE) != 0) ? TRUE : FALSE;
}
BOOL PrintSelection() const // TRUE if printing selection
{
return ((m_pd.Flags & PD_SELECTION) != 0) ? TRUE : FALSE;
}
BOOL PrintAll() const // TRUE if printing all pages
{
return (!PrintRange() && !PrintSelection()) ? TRUE : FALSE;
}
BOOL PrintRange() const // TRUE if printing page range
{
return ((m_pd.Flags & PD_PAGENUMS) != 0) ? TRUE : FALSE;
}
BOOL PrintToFile() const // TRUE if printing to a file
{
return ((m_pd.Flags & PD_PRINTTOFILE) != 0) ? TRUE : FALSE;
}
int GetFromPage() const // starting page if valid
{
return PrintRange() ? m_pd.nFromPage : -1;
}
int GetToPage() const // ending page if valid
{
return PrintRange() ? m_pd.nToPage : -1;
}
LPDEVMODE GetDevMode() const // return DEVMODE
{
if(m_pd.hDevMode == NULL)
return NULL;
return (LPDEVMODE)::GlobalLock(m_pd.hDevMode);
}
LPCTSTR GetDriverName() const // return driver name
{
if(m_pd.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pd.hDevNames);
if(lpDev == NULL)
return NULL;
return (LPCTSTR)lpDev + lpDev->wDriverOffset;
}
LPCTSTR GetDeviceName() const // return device name
{
if(m_pd.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pd.hDevNames);
if(lpDev == NULL)
return NULL;
return (LPCTSTR)lpDev + lpDev->wDeviceOffset;
}
LPCTSTR GetPortName() const // return output port name
{
if(m_pd.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pd.hDevNames);
if(lpDev == NULL)
return NULL;
return (LPCTSTR)lpDev + lpDev->wOutputOffset;
}
HDC GetPrinterDC() const // return HDC (caller must delete)
{
ATLASSERT((m_pd.Flags & PD_RETURNDC) != 0);
return m_pd.hDC;
}
// This helper creates a DC based on the DEVNAMES and DEVMODE structures.
// This DC is returned, but also stored in m_pd.hDC as though it had been
// returned by CommDlg. It is assumed that any previously obtained DC
// has been/will be deleted by the user. This may be
// used without ever invoking the print/print setup dialogs.
HDC CreatePrinterDC()
{
m_pd.hDC = _AtlCreateDC(m_pd.hDevNames, m_pd.hDevMode);
return m_pd.hDC;
}
// Implementation
PRINTDLG m_pdActual; // the Print/Print Setup need to share this
// The following handle the case of print setup... from the print dialog
CPrintDialogImpl(PRINTDLG& pdInit) : m_pd(pdInit)
{ }
BEGIN_MSG_MAP(CPrintDialogImpl)
#ifdef psh1
COMMAND_ID_HANDLER(psh1, OnPrintSetup) // print setup button when print is displayed
#else // !psh1
COMMAND_ID_HANDLER(0x0400, OnPrintSetup) // value from dlgs.h
#endif // !psh1
END_MSG_MAP()
LRESULT OnPrintSetup(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
{
T dlgSetup(m_pd);
ModuleHelper::AddCreateWndData(&dlgSetup.m_thunk.cd, (CCommonDialogImplBase*)&dlgSetup);
return DefWindowProc(WM_COMMAND, MAKEWPARAM(wID, wNotifyCode), (LPARAM)hWndCtl);
}
};
class CPrintDialog : public CPrintDialogImpl<CPrintDialog>
{
public:
CPrintDialog(BOOL bPrintSetupOnly = FALSE,
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION,
HWND hWndParent = NULL)
: CPrintDialogImpl<CPrintDialog>(bPrintSetupOnly, dwFlags, hWndParent)
{ }
CPrintDialog(PRINTDLG& pdInit) : CPrintDialogImpl<CPrintDialog>(pdInit)
{ }
};
#endif // _WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CPrintDialogExImpl - new print dialog for Windows 2000
#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
}; // namespace WTL
#include <atlcom.h>
extern "C" const __declspec(selectany) IID IID_IPrintDialogCallback = {0x5852a2c3, 0x6530, 0x11d1, {0xb6, 0xa3, 0x0, 0x0, 0xf8, 0x75, 0x7b, 0xf9}};
extern "C" const __declspec(selectany) IID IID_IPrintDialogServices = {0x509aaeda, 0x5639, 0x11d1, {0xb6, 0xa1, 0x0, 0x0, 0xf8, 0x75, 0x7b, 0xf9}};
namespace WTL
{
template <class T>
class ATL_NO_VTABLE CPrintDialogExImpl :
public ATL::CWindow,
public ATL::CMessageMap,
public IPrintDialogCallback,
public ATL::IObjectWithSiteImpl< T >
{
public:
PRINTDLGEX m_pdex;
// Constructor
CPrintDialogExImpl(DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION | PD_NOCURRENTPAGE,
HWND hWndParent = NULL)
{
memset(&m_pdex, 0, sizeof(m_pdex));
m_pdex.lStructSize = sizeof(PRINTDLGEX);
m_pdex.hwndOwner = hWndParent;
m_pdex.Flags = dwFlags;
m_pdex.nStartPage = START_PAGE_GENERAL;
// callback object will be set in DoModal
m_pdex.Flags &= ~PD_RETURNIC; // do not support information context
}
// Operations
HRESULT DoModal(HWND hWndParent = ::GetActiveWindow())
{
ATLASSERT(m_hWnd == NULL);
ATLASSERT((m_pdex.Flags & PD_RETURNDEFAULT) == 0); // use GetDefaults for this
if(m_pdex.hwndOwner == NULL) // set only if not specified before
m_pdex.hwndOwner = hWndParent;
T* pT = static_cast<T*>(this);
m_pdex.lpCallback = (IUnknown*)(IPrintDialogCallback*)pT;
HRESULT hResult = ::PrintDlgEx(&m_pdex);
m_hWnd = NULL;
return hResult;
}
BOOL EndDialog(INT_PTR /*nRetCode*/ = 0)
{
ATLASSERT(::IsWindow(m_hWnd));
SendMessage(WM_COMMAND, MAKEWPARAM(IDABORT, 0));
return TRUE;
}
// GetDefaults will not display a dialog but will get device defaults
HRESULT GetDefaults()
{
m_pdex.Flags |= PD_RETURNDEFAULT;
ATLASSERT(m_pdex.hDevMode == NULL); // must be NULL
ATLASSERT(m_pdex.hDevNames == NULL); // must be NULL
return ::PrintDlgEx(&m_pdex);
}
// Helpers for parsing information after successful return num. copies requested
int GetCopies() const
{
if((m_pdex.Flags & PD_USEDEVMODECOPIES) != 0)
{
LPDEVMODE lpDevMode = GetDevMode();
return (lpDevMode != NULL) ? lpDevMode->dmCopies : -1;
}
return m_pdex.nCopies;
}
BOOL PrintCollate() const // TRUE if collate checked
{
return ((m_pdex.Flags & PD_COLLATE) != 0) ? TRUE : FALSE;
}
BOOL PrintSelection() const // TRUE if printing selection
{
return ((m_pdex.Flags & PD_SELECTION) != 0) ? TRUE : FALSE;
}
BOOL PrintAll() const // TRUE if printing all pages
{
return (!PrintRange() && !PrintSelection()) ? TRUE : FALSE;
}
BOOL PrintRange() const // TRUE if printing page range
{
return ((m_pdex.Flags & PD_PAGENUMS) != 0) ? TRUE : FALSE;
}
BOOL PrintToFile() const // TRUE if printing to a file
{
return ((m_pdex.Flags & PD_PRINTTOFILE) != 0) ? TRUE : FALSE;
}
LPDEVMODE GetDevMode() const // return DEVMODE
{
if(m_pdex.hDevMode == NULL)
return NULL;
return (LPDEVMODE)::GlobalLock(m_pdex.hDevMode);
}
LPCTSTR GetDriverName() const // return driver name
{
if(m_pdex.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pdex.hDevNames);
if(lpDev == NULL)
return NULL;
return (LPCTSTR)lpDev + lpDev->wDriverOffset;
}
LPCTSTR GetDeviceName() const // return device name
{
if(m_pdex.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pdex.hDevNames);
if(lpDev == NULL)
return NULL;
return (LPCTSTR)lpDev + lpDev->wDeviceOffset;
}
LPCTSTR GetPortName() const // return output port name
{
if(m_pdex.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pdex.hDevNames);
if(lpDev == NULL)
return NULL;
return (LPCTSTR)lpDev + lpDev->wOutputOffset;
}
HDC GetPrinterDC() const // return HDC (caller must delete)
{
ATLASSERT((m_pdex.Flags & PD_RETURNDC) != 0);
return m_pdex.hDC;
}
// This helper creates a DC based on the DEVNAMES and DEVMODE structures.
// This DC is returned, but also stored in m_pdex.hDC as though it had been
// returned by CommDlg. It is assumed that any previously obtained DC
// has been/will be deleted by the user. This may be
// used without ever invoking the print/print setup dialogs.
HDC CreatePrinterDC()
{
m_pdex.hDC = _AtlCreateDC(m_pdex.hDevNames, m_pdex.hDevMode);
return m_pdex.hDC;
}
// Implementation - interfaces
// IUnknown
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject)
{
if(ppvObject == NULL)
return E_POINTER;
T* pT = static_cast<T*>(this);
if(IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IPrintDialogCallback))
{
*ppvObject = (IPrintDialogCallback*)pT;
// AddRef() not needed
return S_OK;
}
else if(IsEqualGUID(riid, IID_IObjectWithSite))
{
*ppvObject = (IObjectWithSite*)pT;
// AddRef() not needed
return S_OK;
}
return E_NOINTERFACE;
}
virtual ULONG STDMETHODCALLTYPE AddRef()
{
return 1;
}
virtual ULONG STDMETHODCALLTYPE Release()
{
return 1;
}
// IPrintDialogCallback
STDMETHOD(InitDone)()
{
return S_FALSE;
}
STDMETHOD(SelectionChange)()
{
return S_FALSE;
}
STDMETHOD(HandleMessage)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
{
// set up m_hWnd the first time
if(m_hWnd == NULL)
Attach(hWnd);
// call message map
HRESULT hRet = ProcessWindowMessage(hWnd, uMsg, wParam, lParam, *plResult, 0) ? S_OK : S_FALSE;
if(hRet == S_OK && uMsg == WM_NOTIFY) // return in DWLP_MSGRESULT
::SetWindowLongPtr(GetParent(), DWLP_MSGRESULT, (LONG_PTR)*plResult);
if(uMsg == WM_INITDIALOG && hRet == S_OK && (BOOL)*plResult != FALSE)
hRet = S_FALSE;
return hRet;
}
};
class CPrintDialogEx : public CPrintDialogExImpl<CPrintDialogEx>
{
public:
CPrintDialogEx(
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION | PD_NOCURRENTPAGE,
HWND hWndParent = NULL)
: CPrintDialogExImpl<CPrintDialogEx>(dwFlags, hWndParent)
{ }
DECLARE_EMPTY_MSG_MAP()
};
#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
///////////////////////////////////////////////////////////////////////////////
// CPageSetupDialogImpl - Page Setup dialog
#ifndef _WIN32_WCE
template <class T>
class ATL_NO_VTABLE CPageSetupDialogImpl : public CCommonDialogImplBase
{
public:
PAGESETUPDLG m_psd;
ATL::CWndProcThunk m_thunkPaint;
// Constructors
CPageSetupDialogImpl(DWORD dwFlags = PSD_MARGINS | PSD_INWININIINTLMEASURE, HWND hWndParent = NULL)
{
memset(&m_psd, 0, sizeof(m_psd));
m_psd.lStructSize = sizeof(m_psd);
m_psd.hwndOwner = hWndParent;
m_psd.Flags = (dwFlags | PSD_ENABLEPAGESETUPHOOK | PSD_ENABLEPAGEPAINTHOOK);
m_psd.lpfnPageSetupHook = (LPPAGESETUPHOOK)T::HookProc;
m_thunkPaint.Init((WNDPROC)T::PaintHookProc, this);
#if (_ATL_VER >= 0x0700)
m_psd.lpfnPagePaintHook = (LPPAGEPAINTHOOK)m_thunkPaint.GetWNDPROC();
#else
m_psd.lpfnPagePaintHook = (LPPAGEPAINTHOOK)&(m_thunkPaint.thunk);
#endif
}
DECLARE_EMPTY_MSG_MAP()
// Attributes
LPDEVMODE GetDevMode() const // return DEVMODE
{
if(m_psd.hDevMode == NULL)
return NULL;
return (LPDEVMODE)::GlobalLock(m_psd.hDevMode);
}
LPCTSTR GetDriverName() const // return driver name
{
if(m_psd.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_psd.hDevNames);
return (LPCTSTR)lpDev + lpDev->wDriverOffset;
}
LPCTSTR GetDeviceName() const // return device name
{
if(m_psd.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_psd.hDevNames);
return (LPCTSTR)lpDev + lpDev->wDeviceOffset;
}
LPCTSTR GetPortName() const // return output port name
{
if(m_psd.hDevNames == NULL)
return NULL;
LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_psd.hDevNames);
return (LPCTSTR)lpDev + lpDev->wOutputOffset;
}
HDC CreatePrinterDC()
{
return _AtlCreateDC(m_psd.hDevNames, m_psd.hDevMode);
}
SIZE GetPaperSize() const
{
SIZE size;
size.cx = m_psd.ptPaperSize.x;
size.cy = m_psd.ptPaperSize.y;
return size;
}
void GetMargins(LPRECT lpRectMargins, LPRECT lpRectMinMargins) const
{
if(lpRectMargins != NULL)
*lpRectMargins = m_psd.rtMargin;
if(lpRectMinMargins != NULL)
*lpRectMinMargins = m_psd.rtMinMargin;
}
// Operations
INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
{
ATLASSERT((m_psd.Flags & PSD_ENABLEPAGESETUPHOOK) != 0);
ATLASSERT((m_psd.Flags & PSD_ENABLEPAGEPAINTHOOK) != 0);
ATLASSERT(m_psd.lpfnPageSetupHook != NULL); // can still be a user hook
ATLASSERT(m_psd.lpfnPagePaintHook != NULL); // can still be a user hook
if(m_psd.hwndOwner == NULL) // set only if not specified before
m_psd.hwndOwner = hWndParent;
ATLASSERT(m_hWnd == NULL);
ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
BOOL bRet = ::PageSetupDlg(&m_psd);
m_hWnd = NULL;
return bRet ? IDOK : IDCANCEL;
}
// Implementation
static UINT_PTR CALLBACK PaintHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
T* pT = (T*)hWnd;
UINT_PTR uRet = 0;
switch(uMsg)
{
case WM_PSD_PAGESETUPDLG:
uRet = pT->PreDrawPage(LOWORD(wParam), HIWORD(wParam), (LPPAGESETUPDLG)lParam);
break;
case WM_PSD_FULLPAGERECT:
case WM_PSD_MINMARGINRECT:
case WM_PSD_MARGINRECT:
case WM_PSD_GREEKTEXTRECT:
case WM_PSD_ENVSTAMPRECT:
case WM_PSD_YAFULLPAGERECT:
uRet = pT->OnDrawPage(uMsg, (HDC)wParam, (LPRECT)lParam);
break;
default:
ATLTRACE2(atlTraceUI, 0, _T("CPageSetupDialogImpl::PaintHookProc - unknown message received\n"));
break;
}
return uRet;
}
// Overridables
UINT_PTR PreDrawPage(WORD /*wPaper*/, WORD /*wFlags*/, LPPAGESETUPDLG /*pPSD*/)
{
// return 1 to prevent any more drawing
return 0;
}
UINT_PTR OnDrawPage(UINT /*uMsg*/, HDC /*hDC*/, LPRECT /*lpRect*/)
{
return 0; // do the default
}
};
class CPageSetupDialog : public CPageSetupDialogImpl<CPageSetupDialog>
{
public:
CPageSetupDialog(DWORD dwFlags = PSD_MARGINS | PSD_INWININIINTLMEASURE, HWND hWndParent = NULL)
: CPageSetupDialogImpl<CPageSetupDialog>(dwFlags, hWndParent)
{ }
// override PaintHookProc and references to handlers
static UINT_PTR CALLBACK PaintHookProc(HWND, UINT, WPARAM, LPARAM)
{
return 0;
}
};
#endif // _WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CFindReplaceDialogImpl - Find/FindReplace modeless dialogs
#ifndef _WIN32_WCE
templa