CPrintDialog无法在某些PC上运行(64位) [英] CPrintDialog not working on some PC (64 bits)
问题描述
   
在一些非常罕见的情况下,创建CPrintDialog并在其上调用DoModal()无法正常工作。显示对话框,但不调用OnInitDialog()。
问题没有发生如果我直接调用Create()函数。但在这种情况下,打印机设置未填充。
我能够在一个非常简单的应用程序中重现该问题。这个应用程序工作在32位编译时,但不是64位。
这里是我的示例对话框的标题:
// ----------------------------------------------- -------------------------------------------------- -
//摘要
//进行值列表的打印设置。
class TestPrintSetup:public CPrintDialog
{
CWnd * m_pText;
public:
//对话数据
// {{AFX_DATA(DlgPrintSetupVal)
enum {IDD = IDD_ABOUTBOX};
//摘要
//构造函数
TestPrintSetup(
CWnd * pText,
BOOL bPrintSetupOnly,// [in] TRUE for Print Setup,FALSE for print Dialog。
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_HIDEPRINTTOFILE,// [in] flags的组合。
CWnd * pParentWnd = NULL // [in]父窗口
);
//摘要
//析构函数
~TestPrintSetup(){}
//实现
protected:
//生成的消息映射函数
// {{AFX_MSG(DlgPrintSetupVal)
virtual BOOL OnInitDialog();
//}} AFX_MSG
DECLARE_MESSAGE_MAP()
};
这里是cpp文件:
BEGIN_MESSAGE_MAP(TestPrintSetup,CPrintDialog)
// {{AFX_MSG_MAP(DlgPrintSetupVal)
//}} AFX_MSG_MAP
END_MESSAGE_MAP()
// ------------- -------------------------------------------------- -------------------------
//摘要
//构造函数
TestPrintSetup :: TestPrintSetup(
CWnd * pText,
BOOL bPrintSetupOnly,// [in] TRUE for Print Setup,FALSE for Print Dialog。
DWORD dwFlags,// [in] flags的组合。
CWnd * pParentWnd // [in]父窗口
)
:CPrintDialog(bPrintSetupOnly,dwFlags,pParentWnd),
m_pText(pText)
{
if(m_pText)
m_pText-> SetWindowText(L" DlgPrintSetupVal :: DlgPrintSetupVal");
m_pd.Flags | = PD_ENABLESETUPTEMPLATE;
m_pd.lpSetupTemplateName = MAKEINTRESOURCE(IDD_ABOUTBOX);
m_pd.hInstance = AfxGetInstanceHandle();
}
// ----------------------------------- -------------------------------------------------- --------------------------------
/// @brief
///
BOOL TestPrintSetup :: OnInitDialog()
{
if(m_pText)
m_pText-> SetWindowText(L" DlgPrintSetupVal :: OnInitDialog");
return __super :: OnInitDialog();
}
这里是创建对话框的代码:
TestPrintSetup dlg(GetDlgItem(IDC_STATIC),TRUE);
dlg.DoModal();
我将此代码放在Sample MFC项目(Dialog base)中。
非常奇怪的是,这个样本可以在99%的PC上运行。但在很少的情况下,它不是64位工作。我拥有的最后一个案例,它位于装有Windows 10的PC上。
问候,
François
>非常奇怪的是,这个样本可以在99%的PC上运行。但在很少的情况下,它不是64位工作。我拥有的最后一个案例,它位于装有Windows 10的PC上。
François,
在该PC上,它是否有默认的打印机设置,或者它有"让Windows管理我的默认打印机"设置?
戴夫
Hi,
in some very rare case, creating a CPrintDialog and calling DoModal() on it do not work correctly. The dialog is display, but the OnInitDialog() is not called.
The problem not happen If I call directly the Create() function. But in this case, the Printer settings is not filled.
I was able to reproduce the problem inside a very simple application. This application work when it's compile in 32 bits, but not in 64 bits.
Here the header of my sample dialog:
//--------------------------------------------------------------------------------------------------- // SUMMARY // To make the print setup of a value list. class TestPrintSetup : public CPrintDialog { CWnd* m_pText; public: // Dialog Data //{{AFX_DATA(DlgPrintSetupVal) enum { IDD = IDD_ABOUTBOX }; // SUMMARY // Constructor TestPrintSetup( CWnd* pText, BOOL bPrintSetupOnly, // [in] TRUE for Print Setup, FALSE for Print Dialog. DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_HIDEPRINTTOFILE, // [in] Combination of flags. CWnd* pParentWnd = NULL // [in] Parent window ); // SUMMARY // Destructor ~TestPrintSetup() {} // Implementation protected: // Generated message map functions //{{AFX_MSG(DlgPrintSetupVal) virtual BOOL OnInitDialog(); //}}AFX_MSG DECLARE_MESSAGE_MAP() };
Here the cpp file:
BEGIN_MESSAGE_MAP(TestPrintSetup, CPrintDialog) //{{AFX_MSG_MAP(DlgPrintSetupVal) //}}AFX_MSG_MAP END_MESSAGE_MAP() //---------------------------------------------------------------------------------------- // SUMMARY // Constructor TestPrintSetup::TestPrintSetup( CWnd* pText, BOOL bPrintSetupOnly, // [in] TRUE for Print Setup, FALSE for Print Dialog. DWORD dwFlags, // [in] Combination of flags. CWnd* pParentWnd // [in] Parent window ) : CPrintDialog(bPrintSetupOnly, dwFlags, pParentWnd), m_pText(pText) { if(m_pText) m_pText->SetWindowText(L"DlgPrintSetupVal::DlgPrintSetupVal"); m_pd.Flags |= PD_ENABLESETUPTEMPLATE ; m_pd.lpSetupTemplateName = MAKEINTRESOURCE(IDD_ABOUTBOX) ; m_pd.hInstance = AfxGetInstanceHandle() ; } //--------------------------------------------------------------------------------------------------------------------- /// @brief /// BOOL TestPrintSetup::OnInitDialog() { if(m_pText) m_pText->SetWindowText(L"DlgPrintSetupVal::OnInitDialog"); return __super::OnInitDialog(); }
And here the code to create the dialog:
TestPrintSetup dlg(GetDlgItem(IDC_STATIC), TRUE); dlg.DoModal();
I put this code inside a Sample MFC project (Dialog base).
The very strange think, it that this sample work on 99% of the PC. But on very few, it's not working in 64 bits. The last case I have, it's on a PC with Windows 10.
regards,
François
>The very strange think, it that this sample work on 99% of the PC. But on very few, it's not working in 64 bits. The last case I have, it's on a PC with Windows 10.
François,
On that PC, does it have a default printer set, or has it got "Let Windows manage my default printer" set?
Dave
这篇关于CPrintDialog无法在某些PC上运行(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!