📄 atldlgs.h
字号:
}
// 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 // _WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// 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);
#if (_ATL_VER >= 0x0700)
ATL::_AtlWinModule.AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
#else //!(_ATL_VER >= 0x0700)
_Module.AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
#endif //!(_ATL_VER >= 0x0700)
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);
#if (_ATL_VER >= 0x0700)
ATL::_AtlWinModule.AddCreateWndData(&dlgSetup.m_thunk.cd, (CCommonDialogImplBase*)&dlgSetup);
#else //!(_ATL_VER >= 0x0700)
_Module.AddCreateWndData(&dlgSetup.m_thunk.cd, (CCommonDialogImplBase*)&dlgSetup);
#endif //!(_ATL_VER >= 0x0700)
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -