📄 atldlgs.h
字号:
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)
memcpy(lpRectMargins, &m_psd.rtMargin, sizeof(RECT));
if(lpRectMinMargins != NULL)
memcpy(lpRectMinMargins, &m_psd.rtMinMargin, sizeof(RECT));
}
// 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);
#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 = ::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
template <class T>
class ATL_NO_VTABLE CFindReplaceDialogImpl : public CCommonDialogImplBase
{
public:
enum { _cchFindReplaceBuffer = 128 };
FINDREPLACE m_fr;
TCHAR m_szFindWhat[_cchFindReplaceBuffer];
TCHAR m_szReplaceWith[_cchFindReplaceBuffer];
// Constructors
CFindReplaceDialogImpl()
{
memset(&m_fr, 0, sizeof(m_fr));
m_szFindWhat[0] = _T('\0');
m_szReplaceWith[0] = _T('\0');
m_fr.lStructSize = sizeof(m_fr);
m_fr.Flags = FR_ENABLEHOOK;
m_fr.lpfnHook = (LPFRHOOKPROC)T::HookProc;
m_fr.lpstrFindWhat = (LPTSTR)m_szFindWhat;
m_fr.wFindWhatLen = _cchFindReplaceBuffer;
m_fr.lpstrReplaceWith = (LPTSTR)m_szReplaceWith;
m_fr.wReplaceWithLen = _cchFindReplaceBuffer;
}
// Note: You must allocate the object on the heap.
// If you do not, you must override OnFinalMessage()
virtual void OnFinalMessage(HWND /*hWnd*/)
{
delete this;
}
HWND Create(BOOL bFindDialogOnly, // TRUE for Find, FALSE for FindReplace
LPCTSTR lpszFindWhat,
LPCTSTR lpszReplaceWith = NULL,
DWORD dwFlags = FR_DOWN,
HWND hWndParent = NULL)
{
ATLASSERT((m_fr.Flags & FR_ENABLEHOOK) != 0);
ATLASSERT(m_fr.lpfnHook != NULL);
m_fr.Flags |= dwFlags;
if(hWndParent == NULL)
m_fr.hwndOwner = ::GetActiveWindow();
else
m_fr.hwndOwner = hWndParent;
ATLASSERT(m_fr.hwndOwner != NULL); // must have an owner for modeless dialog
if(lpszFindWhat != NULL)
lstrcpyn(m_szFindWhat, lpszFindWhat, _cchFindReplaceBuffer);
if(lpszReplaceWith != NULL)
lstrcpyn(m_szReplaceWith, lpszReplaceWith, _cchFindReplaceBuffer);
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)
HWND hWnd;
if(bFindDialogOnly)
hWnd = ::FindText(&m_fr);
else
hWnd = ::ReplaceText(&m_fr);
ATLASSERT(m_hWnd == hWnd);
return hWnd;
}
static const UINT GetFindReplaceMsg()
{
static const UINT nMsgFindReplace = ::RegisterWindowMessage(FINDMSGSTRING);
return nMsgFindReplace;
}
// call while handling FINDMSGSTRING registered message
// to retreive the object
static T* PASCAL GetNotifier(LPARAM lParam)
{
ATLASSERT(lParam != NULL);
T* pDlg = (T*)(lParam - offsetof(T, m_fr));
return pDlg;
}
// Operations
// Helpers for parsing information after successful return
LPCTSTR GetFindString() const // get find string
{
return (LPCTSTR)m_fr.lpstrFindWhat;
}
LPCTSTR GetReplaceString() const // get replacement string
{
return (LPCTSTR)m_fr.lpstrReplaceWith;
}
BOOL SearchDown() const // TRUE if search down, FALSE is up
{
return ((m_fr.Flags & FR_DOWN) != 0) ? TRUE : FALSE;
}
BOOL FindNext() const // TRUE if command is find next
{
return ((m_fr.Flags & FR_FINDNEXT) != 0) ? TRUE : FALSE;
}
BOOL MatchCase() const // TRUE if matching case
{
return ((m_fr.Flags & FR_MATCHCASE) != 0) ? TRUE : FALSE;
}
BOOL MatchWholeWord() const // TRUE if matching whole words only
{
return ((m_fr.Flags & FR_WHOLEWORD) != 0) ? TRUE : FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -