📄 subject_57107.htm
字号:
<p>
序号:57107 发表者:最后一根稻草 发表日期:2003-10-22 21:50:53
<br>主题:如何看MFC源代码
<br>内容:最近看打印的问题,发现纸张设置类里没有自定义的形式,便想看看CPageSetupDialog在MFC中是怎样定义的,高手指点?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:jackyxio 回复日期:2003-10-23 09:29:37
<br>内容:Mfc很大部分源码都隐藏了,只能看到头文件。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:最后一根稻草 回复日期:2003-10-23 10:01:17
<br>内容:我的意思就是用什么办法能看到隐藏的代码,我想修改CPageSetupDialog类的使用方法,高手指点
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:jackyxio 回复日期:2003-10-23 10:11:15
<br>内容:全是lib,改不了。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:jackyxio 回复日期:2003-10-23 10:11:49
<br>内容:想改的话,用继承就行了啊。重载。。。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:dr0 回复日期:2003-10-23 12:26:38
<br>内容:// This is a part of the Microsoft Foundation Classes C++ library.<BR>// Copyright (C) 1992-1998 Microsoft Corporation<BR>// All rights reserved.<BR>//<BR>// This source code is only intended as a supplement to the<BR>// Microsoft Foundation Classes Reference and related<BR>// electronic documentation provided with the library.<BR>// See these sources for detailed information regarding the<BR>// Microsoft Foundation Classes product.<BR><BR>#include "stdafx.h"<BR>#include <dlgs.h> // for standard control IDs for commdlg<BR><BR>#ifdef AFX_AUX_SEG<BR>#pragma code_seg(AFX_AUX_SEG)<BR>#endif<BR><BR>#ifdef _DEBUG<BR>#undef THIS_FILE<BR>static char THIS_FILE[] = __FILE__;<BR>#endif<BR><BR>#define new DEBUG_NEW<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// Page Setup dialog<BR><BR>CPageSetupDialog::CPageSetupDialog(DWORD dwFlags, CWnd* pParentWnd) :<BR> CCommonDialog(pParentWnd)<BR>{<BR> memset(&m_psd, 0, sizeof(m_psd));<BR><BR> m_psd.lStructSize = sizeof(m_psd);<BR> m_psd.Flags = (dwFlags | PSD_ENABLEPAGESETUPHOOK | PSD_ENABLEPAGEPAINTHOOK);<BR> if (!afxData.bWin4 && AfxHelpEnabled())<BR> m_psd.Flags |= PSD_SHOWHELP;<BR> m_psd.lpfnPageSetupHook = (COMMDLGPROC)_AfxCommDlgProc;<BR> m_psd.lpfnPagePaintHook = (COMMDLGPROC)CPageSetupDialog::PaintHookProc;<BR>}<BR><BR>int CPageSetupDialog::DoModal()<BR>{<BR> ASSERT_VALID(this);<BR> ASSERT(m_psd.Flags & PSD_ENABLEPAGESETUPHOOK);<BR> ASSERT(m_psd.Flags & PSD_ENABLEPAGEPAINTHOOK);<BR> ASSERT(m_psd.lpfnPageSetupHook != NULL); // can still be a user hook<BR> ASSERT(m_psd.lpfnPagePaintHook != NULL); // can still be a user hook<BR><BR> m_psd.hwndOwner = PreModal();<BR> int nResult = ::PageSetupDlg(&m_psd);<BR> PostModal();<BR> return nResult ? nResult : IDCANCEL;<BR>}<BR><BR>////////////////////////////////////////////////////////////////////////////<BR>// CPageSetupDialog attributes<BR><BR>LPDEVMODE CPageSetupDialog::GetDevMode() const<BR>{<BR> if (m_psd.hDevMode == NULL)<BR> return NULL;<BR><BR> return (LPDEVMODE)::GlobalLock(m_psd.hDevMode);<BR>}<BR><BR>CString CPageSetupDialog::GetDriverName() const<BR>{<BR> if (m_psd.hDevNames == NULL)<BR> return afxEmptyString;<BR><BR> LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_psd.hDevNames);<BR> return (LPCTSTR)lpDev + lpDev->wDriverOffset;<BR>}<BR><BR>CString CPageSetupDialog::GetDeviceName() const<BR>{<BR> if (m_psd.hDevNames == NULL)<BR> return afxEmptyString;<BR><BR> LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_psd.hDevNames);<BR> return (LPCTSTR)lpDev + lpDev->wDeviceOffset;<BR>}<BR><BR>CString CPageSetupDialog::GetPortName() const<BR>{<BR> if (m_psd.hDevNames == NULL)<BR> return afxEmptyString;<BR><BR> LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_psd.hDevNames);<BR> return (LPCTSTR)lpDev + lpDev->wOutputOffset;<BR>}<BR><BR>// Create an HDC from the devnames and devmode.<BR>HDC CPageSetupDialog::CreatePrinterDC()<BR>{<BR> ASSERT_VALID(this);<BR> return AfxCreateDC(m_psd.hDevNames, m_psd.hDevMode);<BR>}<BR><BR>void CPageSetupDialog::GetMargins(LPRECT lpRectMargins, LPRECT lpRectMinMargins) const<BR>{<BR> if (lpRectMargins != NULL)<BR> memcpy(lpRectMargins, &m_psd.rtMargin, sizeof(RECT));<BR> if (lpRectMinMargins != NULL)<BR> memcpy(lpRectMinMargins, &m_psd.rtMinMargin, sizeof(RECT));<BR>}<BR><BR>////////////////////////////////////////////////////////////////////////////<BR>// CPageSetupDialog diagnostics<BR><BR>#ifdef _DEBUG<BR>void CPageSetupDialog::Dump(CDumpContext& dc) const<BR>{<BR> CDialog::Dump(dc);<BR><BR> dc << "m_psd.hwndOwner = " << (UINT)m_psd.hwndOwner;<BR> dc << "\nm_psd.Flags = " << (LPVOID)m_psd.Flags;<BR><BR> dc << "\nm_psd.ptPaperSize = " << m_psd.ptPaperSize;<BR> dc << "\nm_psd.rtMinMargin = " << m_psd.rtMinMargin;<BR> dc << "\nm_psd.rtMinMargin = " << m_psd.rtMinMargin;<BR><BR> if (m_psd.lpfnPageSetupHook == (COMMDLGPROC)_AfxCommDlgProc)<BR> dc << "\nsetup hook function set to standard MFC hook function";<BR> else<BR> dc << "\nsetup hook function set to non-standard hook function";<BR><BR> if (m_psd.lpfnPagePaintHook == (COMMDLGPROC)_AfxCommDlgProc)<BR> dc << "\nprint hook function set to standard MFC hook function";<BR> else<BR> dc << "\nprint hook function set to non-standard hook function";<BR><BR> dc << "\n";<BR>}<BR>#endif //_DEBUG<BR><BR>////////////////////////////////////////////////////////////////////////////<BR>// CPageSetupDialog hook<BR><BR>UINT CPageSetupDialog::PreDrawPage(WORD /*wPaperType*/, WORD /*wFlags*/,<BR> LPPAGESETUPDLG)<BR>{<BR> return 0;<BR> //return 1 to prevent any more drawing<BR>}<BR><BR>UINT CPageSetupDialog::OnDrawPage(CDC*, UINT /*nMessage*/, LPRECT)<BR>{<BR> return 0; // do the default<BR>}<BR><BR>UINT CALLBACK CPageSetupDialog::PaintHookProc(HWND hWnd, UINT message, WPARAM wParam,<BR> LPARAM lParam)<BR>{<BR> if (hWnd == NULL)<BR> return 0;<BR> // Get our Window<BR> // assume it is already wired up to a permanent one<BR> // the hWnd is the HWND of a control in the page setup proc<BR> CPageSetupDialog* pDlg = DYNAMIC_DOWNCAST(CPageSetupDialog,<BR> CWnd::FromHandlePermanent(::GetParent(hWnd)));<BR> if (pDlg == NULL)<BR> return 0;<BR> switch (message)<BR> {<BR> case WM_PSD_PAGESETUPDLG:<BR> return pDlg->PreDrawPage(LOWORD(wParam), HIWORD(wParam),<BR> (LPPAGESETUPDLG) lParam);<BR> break;<BR> case WM_PSD_FULLPAGERECT:<BR> case WM_PSD_MINMARGINRECT:<BR> case WM_PSD_MARGINRECT:<BR> case WM_PSD_GREEKTEXTRECT:<BR> case WM_PSD_ENVSTAMPRECT:<BR> case WM_PSD_YAFULLPAGERECT:<BR> return pDlg->OnDrawPage(CDC::FromHandle((HDC)wParam), message, (LPRECT)lParam);<BR> break;<BR> }<BR> return 0;<BR>}<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// Print/Print Setup dialog<BR><BR>BEGIN_MESSAGE_MAP(CPrintDialog, CCommonDialog)<BR> //{{AFX_MSG_MAP(CPrintDialog)<BR> ON_COMMAND(psh1, OnPrintSetup) // print setup button when print is displayed<BR> //}}AFX_MSG_MAP<BR>END_MESSAGE_MAP()<BR><BR>CPrintDialog::CPrintDialog(BOOL bPrintSetupOnly,<BR> DWORD dwFlags, CWnd* pParentWnd)<BR> : m_pd(m_pdActual), CCommonDialog(pParentWnd)<BR>{<BR> memset(&m_pdActual, 0, sizeof(m_pdActual));<BR><BR> m_pd.lStructSize = sizeof(m_pdActual);<BR> m_pd.Flags = (dwFlags | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK);<BR> if (!afxData.bWin4 && AfxHelpEnabled())<BR> m_pd.Flags |= PD_SHOWHELP;<BR> m_pd.lpfnPrintHook = (COMMDLGPROC)_AfxCommDlgProc;<BR> m_pd.lpfnSetupHook = (COMMDLGPROC)_AfxCommDlgProc;<BR><BR> if (bPrintSetupOnly)<BR> {<BR> m_nIDHelp = AFX_IDD_PRINTSETUP;<BR> m_pd.Flags |= PD_PRINTSETUP;<BR> }<BR> else<BR> {<BR> m_nIDHelp = AFX_IDD_PRINT;<BR> m_pd.Flags |= PD_RETURNDC;<BR> }<BR><BR> m_pd.Flags &= ~PD_RETURNIC; // do not support information context<BR>}<BR><BR>// Helper ctor for AttachOnSetup<BR>CPrintDialog::CPrintDialog(PRINTDLG& pdInit)<BR> : m_pd(pdInit), CCommonDialog(NULL)<BR>{<BR>}<BR><BR>// Function to keep m_pd in sync after user invokes Setup from<BR>// the print dialog (via the Setup button)<BR>// If you decide to handle any messages/notifications and wish to<BR>// handle them differently between Print/PrintSetup then override<BR>// this function and create an object of a derived class<BR>CPrintDialog* CPrintDialog::AttachOnSetup()<BR>{<BR> ASSERT_VALID(this);<BR><BR> CPrintDialog* pDlgSetup;<BR><BR> pDlgSetup = new CPrintDialog(m_pd);<BR> pDlgSetup->m_hWnd = NULL;<BR> pDlgSetup->m_pParentWnd = m_pParentWnd;<BR> pDlgSetup->m_nIDHelp = AFX_IDD_PRINTSETUP;<BR> return pDlgSetup;<BR>}<BR><BR>void CPrintDialog::OnPrintSetup()<BR>{<BR> ASSERT_VALID(this);<BR><BR> CPrintDialog* pDlgSetup = AttachOnSetup();<BR> ASSERT(pDlgSetup != NULL);<BR><BR> AfxHookWindowCreate(pDlgSetup);<BR> Default();<BR> AfxUnhookWindowCreate();<BR><BR> delete pDlgSetup;<BR>}<BR><BR>int CPrintDialog::DoModal()<BR>{<BR> ASSERT_VALID(this);<BR> ASSERT(m_pd.Flags & PD_ENABLEPRINTHOOK);<BR> ASSERT(m_pd.Flags & PD_ENABLESETUPHOOK);<BR> ASSERT(m_pd.lpfnPrintHook != NULL); // can still be a user hook<BR> ASSERT(m_pd.lpfnSetupHook != NULL); // can still be a user hook<BR><BR> m_pd.hwndOwner = PreModal();<BR> int nResult = ::PrintDlg(&m_pd);<BR> PostModal();<BR> return nResult ? nResult : IDCANCEL;<BR>}<BR><BR>// Create an HDC without calling DoModal.<BR>HDC CPrintDialog::CreatePrinterDC()<BR>{<BR> ASSERT_VALID(this);<BR> m_pd.hDC = AfxCreateDC(m_pd.hDevNames, m_pd.hDevMode);<BR> return m_pd.hDC;<BR>}<BR><BR>int CPrintDialog::GetCopies() const<BR>{<BR> ASSERT_VALID(this);<BR><BR> if (m_pd.Flags & PD_USEDEVMODECOPIES)<BR> return GetDevMode()->dmCopies;<BR> else<BR> return m_pd.nCopies;<BR>}<BR><BR>LPDEVMODE CPrintDialog::GetDevMode() const<BR>{<BR> if (m_pd.hDevMode == NULL)<BR> return NULL;<BR><BR> return (LPDEVMODE)::GlobalLock(m_pd.hDevMode);<BR>}<BR><BR>CString CPrintDialog::GetDriverName() const<BR>{<BR> if (m_pd.hDevNames == NULL)<BR> return afxEmptyString;<BR><BR> LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_pd.hDevNames);<BR> return (LPCTSTR)lpDev + lpDev->wDriverOffset;<BR>}<BR><BR>CString CPrintDialog::GetDeviceName() const<BR>{<BR> if (m_pd.hDevNames == NULL)<BR> return afxEmptyString;<BR><BR> LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_pd.hDevNames);<BR> return (LPCTSTR)lpDev + lpDev->wDeviceOffset;<BR>}<BR><BR>CString CPrintDialog::GetPortName() const<BR>{<BR> if (m_pd.hDevNames == NULL)<BR> return afxEmptyString;<BR><BR> LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_pd.hDevNames);<BR> return (LPCTSTR)lpDev + lpDev->wOutputOffset;<BR>}<BR><BR>// this function must not be in afxdlgs.inl because of DLL delay loading<BR>BOOL CPrintDialog::GetDefaults()<BR>{<BR> m_pd.Flags |= PD_RETURNDEFAULT;<BR> return ::PrintDlg(&m_pd);<BR>}<BR><BR>////////////////////////////////////////////////////////////////////////////<BR>// CPrintDialog diagnostics<BR><BR>#ifdef _DEBUG<BR>void CPrintDialog::Dump(CDumpContext& dc) const<BR>{<BR> CDialog::Dump(dc);<BR><BR> dc << "m_pd.hwndOwner = " << (UINT)m_pd.hwndOwner;<BR><BR> if (m_pd.hDC != NULL)<BR> dc << "\nm_pd.hDC = " << CDC::FromHandle(m_pd.hDC);<BR><BR> dc << "\nm_pd.Flags = " << (LPVOID)m_pd.Flags;<BR> dc << "\nm_pd.nFromPage = " << m_pd.nFromPage;<BR> dc << "\nm_pd.nToPage = " << m_pd.nToPage;<BR> dc << "\nm_pd.nMinPage = " << m_pd.nMinPage;<BR> dc << "\nm_pd.nMaxPage = " << m_pd.nMaxPage;<BR> dc << "\nm_pd.nCopies = " << m_pd.nCopies;<BR><BR> if (m_pd.lpfnSetupHook == (COMMDLGPROC)_AfxCommDlgProc)<BR> dc << "\nsetup hook function set to standard MFC hook function";<BR> else<BR> dc << "\nsetup hook function set to non-standard hook function";<BR><BR> if (m_pd.lpfnPrintHook == (COMMDLGPROC)_AfxCommDlgProc)<BR> dc << "\nprint hook function set to standard MFC hook function";<BR> else<BR> dc << "\nprint hook function set to non-standard hook function";<BR><BR> dc << "\n";<BR>}<BR>#endif //_DEBUG<BR><BR>////////////////////////////////////////////////////////////////////////////<BR>// AfxCreateDC<BR><BR>HDC AFXAPI AfxCreateDC(HGLOBAL hDevNames, HGLOBAL hDevMode)<BR>{<BR> if (hDevNames == NULL)<BR> return NULL;<BR><BR> LPDEVNAMES lpDevNames = (LPDEVNAMES)::GlobalLock(hDevNames);<BR> LPDEVMODE lpDevMode = (hDevMode != NULL) ?<BR> (LPDEVMODE)::GlobalLock(hDevMode) : NULL;<BR><BR> if (lpDevNames == NULL)<BR> return NULL;<BR><BR> HDC hDC = ::CreateDC((LPCTSTR)lpDevNames + lpDevNames->wDriverOffset,<BR> (LPCTSTR)lpDevNames + lpDevNames->wDeviceOffset,<BR> (LPCTSTR)lpDevNames + lpDevNames->wOutputOffset,<BR> lpDevMode);<BR><BR> ::GlobalUnlock(hDevNames);<BR> if (hDevMode != NULL)<BR> ::GlobalUnlock(hDevMode);<BR> return hDC;<BR>}<BR><BR>#ifdef AFX_INIT_SEG<BR>#pragma code_seg(AFX_INIT_SEG)<BR>#endif<BR><BR>IMPLEMENT_DYNAMIC(CPrintDialog, CDialog)<BR>IMPLEMENT_DYNAMIC(CPageSetupDialog, CDialog)<BR><BR>////////////////////////////////////////////////////////////////////////////<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -