?? atldlgs.h
字號:
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()
};
/////////////////////////////////////////////////////////////////////////////
// CPrintDialogImpl - used for Print... and PrintSetup...
// 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);
ATLASSERT(m_pd.Flags & PD_ENABLESETUPHOOK);
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);
_Module.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)
{
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) ? TRUE : FALSE;
}
BOOL PrintSelection() const // TRUE if printing selection
{
return (m_pd.Flags & PD_SELECTION) ? 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) ? 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);
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*/)
{
CPrintDialogImpl< T >* pDlgSetup = NULL;
ATLTRY(pDlgSetup = new CPrintDialogImpl< T >(m_pd));
ATLASSERT(pDlgSetup != NULL);
_Module.AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)pDlgSetup);
LRESULT lRet = DefWindowProc(WM_COMMAND, MAKEWPARAM(wID, wNotifyCode), (LPARAM)hWndCtl);
delete pDlgSetup;
return lRet;
}
};
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)
{ }
};
/////////////////////////////////////////////////////////////////////////////
// CPrintDialogExImpl - new print dialog for Windows 2000
#if (WINVER >= 0x0500)
}; //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 CWindow,
public CMessageMap,
public IPrintDialogCallback,
public 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)
{
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) ? TRUE : FALSE;
}
BOOL PrintSelection() const // TRUE if printing selection
{
return (m_pdex.Flags & PD_SELECTION) ? 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) ? 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);
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)
// 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()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -