• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >vc/mfc > 怎么在VC做的ACTIVEX中实现打印预览??

怎么在VC做的ACTIVEX中实现打印预览??

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-06-04

佚名通过本文主要向大家介绍了 怎么在VC做的ACTIVEX中实现打印预览??等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 怎么在VC做的ACTIVEX中实现打印预览??
描述:

我在ACTIVEX中创建了CFrameWnd,CView 可是在CVIEW中创建的CDialogBar在create的时候总是失败,但我检查了其中的pParent,nIDResource是AFX_IDD_PREVIEW_TOOLBARVC自己带的ID这些对象都是有效的,很奇怪,这种预览方式在CDialog的应用中是实现是没有问题的,这样创建也没保错,就是在Activex这种情况下就出现创建不了了,郁闷ing!
// Create the toolbar from the dialog resource
pView->m_pToolBar = new CDialogBar;
if (!pView->m_pToolBar->Create(pParent, MAKEINTRESOURCE(nIDResource),
CBRS_TOP, AFX_IDW_PREVIEW_BAR))
{
TRACE0("Error: Preview could not create toolbar dialog.\n");
pParent->OnSetPreviewMode(FALSE, pState);   // restore Frame Window
delete pView->m_pToolBar;       // not autodestruct yet
pView->m_pToolBar = NULL;
pView->m_pPreviewState = NULL;  // do not delete state structure
delete pView;
return FALSE;
}


解决方案1:

在ActiveX控件中引入窗体技术  
   
 一、引入Dialog技术 
---- 下面介绍在制作ActiveX控件时引入有模式对话框技术,制作步骤如下: 
创建一新的MFC ActiveX ControlWizard项目,取名为Hello,其他用缺省选项;
在ResourceView页中新增一对话框资源,命名为IDD_HELLODIALOG,可以在对话框上放自己的控件;
为对话框资源IDD_HELLODIALOG创建新类CHelloDialog,从CDialog继承;
确认在HelloCtrl.h中已加入语句#include "HelloDialog.h",为CHelloCtrl类添加成员变量CHelloDialog m_helloDialog;
用ClassWizard在Automation页中为CHelloCtrl添加一方法void DoHello(),外部名亦为DoHello; 
void CHelloCtrl::DoHello() 
{
// 显示对话框
m_helloDialog.DoModal();
}
---- 可以用ActiveX Control Test Container测试Hello Control的DoHello方法。 
---- 下面介绍在制作ActiveX控件时引入无模式对话框技术,制作步骤如下: 
在上面工作的基础上,用ClassWizard为CHelloCtrl添加WM_CREATE的处理函数OnCreate,在此创建无模式对话框;
修改DoHello代码,在此显示对话框; 
int CHelloCtrl::OnCreate
(LPCREATESTRUCT lpCreateStruct) 
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// 创建对话框
m_helloDialog.Create(IDD_HELLODIALOG);
return 0;
}
void CHelloCtrl::DoHello() 
{
// 显示对话框
m_helloDialog.ShowWindow(SW_SHOW);
}
---- 下面介绍制作以对话框作为界面的ActiveX控件技术,制作步骤如下: 
在上面工作的基础上,设置对话框资源IDD_HELLODIALOG属性的Style页为Style:Child、Border:Dialog Frame、Title Bar:unchecked;设置More Style页为Visible:checked;Control:checked;设置Extended Styles页为Static Edge:checked;
在CHelloCtrl::OnCreate中写入m_helloDialog.Create(IDD_HELLODIALOG,this)语句;
在CHelloCtrl::OnDraw中写入m_helloDialog.MoveWindow(rcBounds,TRUE); 
int CHelloCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// 创建对话框
m_helloDialog.Create(IDD_HELLODIALOG,this);
return 0;
}
void CHelloCtrl::OnDraw(CDC* pdc, const
 CRect& rcBounds, const CRect& rcInvalid)
{
// 定位Hello对话框
m_helloDialog.MoveWindow(rcBounds,TRUE);
}
---- 二、引入FormView技术 
---- 下面介绍在制作ActiveX控件时引入FormView技术,制作步骤如下: 
在上面工作的基础上,在ResourceView页中新增一对话框资源,命名为IDD_HELLOFORMVIEW,可以在对话框上放自己的控件;
设置对话框资源IDD_HELLODIALOG属性的Style页为Style:Child、Border:Dialog Frame、Title Bar:unchecked;设置More Style页为Visible:checked;Control:checked;设置Extended Styles页为Static Edge:checked;
为对话框资源IDD_HELLOFORMVIEW创建新类CHelloFormView,从CFormView继承;
在HelloFormView.h中将CHelloFormView的构造函数CHelloFormView()和析构函数virtual ~CHelloFormView()从protected改为public;
在HelloFormView.h中对CHelloFormView类加入public friend class CHelloCtrl;
确认在HelloCtrl.h中已加入语句#include "HelloFormView.h",为CHelloCtrl类添加成员变量CHelloFormView m_helloFormView;
修改CHelloCtrl::OnCreate函数,在此创建m_helloFormView;
修改DoHello代码,在此显示FormView; 
int CHelloCtrl::OnCreate
(LPCREATESTRUCT lpCreateStruct) 
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// 创建FormView
m_helloFormView.Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL);
return 0;
}
void CHelloCtrl::OnDraw(CDC* pdc, const
 CRect& rcBounds, const CRect& rcInvalid)
{
// 定位Hello对话框
m_helloFormView.MoveWindow(rcBounds,TRUE);
}
---- 三、引入Document/View结构技术 
---- 下面介绍在制作ActiveX控件时引入Document/View技术,制作步骤如下: 
在上面工作的基础上,在Hello工程中用ClassWizard添加一新类CPrintFrame,取其父类为CFrameWnd;
在PrintFrame.h中将CPrintFrame的构造函数CPrintFrame()和析构函数virtual ~CPrintFrame()从protected改为public;
在Hello工程中用ClassWizard添加一新类CPrintView,取其父类为CView;
在PrintView.h中将CPrintView的构造函数CPrintView()和析构函数virtual ~CPrintView()从protected改为public;
在Hello工程中用ClassWizard添加一新类CPrintDoc,取其父类为CDocument;
在PrintDoc.h中将CPrintDoc的构造函数CPrintDoc()和析构函数virtual ~CPrintDoc()从protected改为public;
在Hello工程中用ClassWizard添加一新类CPrintThread,取其父类为CWinThread;
在HelloCtrl.h文件中为CHelloCtrl类添加成员变量CPrintThread* m_pPrintThread,确认在HelloCtrl.h中已加入语句#include "PrintThread.h"; 
void CHelloCtrl::DoHello() 
{
// 创建打印线程
m_pPrintThread = (CPrintThread*)
AfxBeginThread(RUNTIME_CLASS(CPrintThread),
THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED, NULL);
m_pPrintThread- >ResumeThread();
}
在PrintThread.h中添加新成员变量 
CPrintDoc* m_pPrintDoc和CPrintFrame* m_pPrintFrame,
并在构造函数和析构函数中完成对它们的初始设置和清除,
确认在PrintThread.h中已加入语句#include 
"PrintDoc.h"和#include "PrintFrame.h";
CPrintThread::CPrintThread()
{
m_pPrintDoc=NULL;
m_pPrintFrame=NULL;
}
CPrintThread::~CPrintThread()
{
if (m_pPrintDoc!=NULL)
delete m_pPrintFrame;
if (m_pPrintFrame!=NULL)
delete m_pPrintDoc;
}
在PrintThread.cpp的CPrintThread::InitInstance中,进行创建窗体CPrintFrame,确认在PrintThread.cpp中已加入语句#include "PrintFrame.h"; 
BOOL CPrintThread::InitInstance()
{
// 创建文档/视图框架
CPrintFrame* pFrame = new CPrintFrame;
m_pMainWnd = pFrame;
m_pPrintFrame=pFrame;
m_pPrintDoc=new CPrintDoc;
CCreateContext context;
context.m_pCurrentDoc = m_pPrintDoc;
context.m_pNewViewClass = RUNTIME_CLASS(CPrintView);
pFrame- >Create(NULL,"打印主窗体",

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

相关文章

  • 2017-06-04 Helpme!!!如何在ASP使用ActiveX的问题。
  • 2017-06-04 还有问题呢?我都不知道简单还难,我就是不明白,请帮忙了,
  • 2017-06-05 如何使影片在指定的播放页面里能够播放,但又不能被用户直接下载,很急!!!
  • 2017-06-05 200分的问题!请进
  • 2017-06-04 在程序中,如何设置某个目录为共享目录?
  • 2017-06-05 VC的dll问题
  • 2017-06-05 rawsocket为什么只能抓到incoming?2贴200分求助!<2>
  • 2017-06-05 activeX的Static控件上显示CHtmlView的问题,全部家当求解
  • 2017-06-04 使用VC7编写HID设备通信程序问题
  • 2017-06-05 多线程调用同一全局函数会不会锁死

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 请问关于dll注入禁止API调用的问题,请看里面
    • 谁能给个com的proxy跟stub的例子
    • 万分紧急!!在线等!VC中,通过FindWindow获得窗口句柄之后,如何得到窗口中OCX控件对象!!
    • 如何把一个对话框工程转换成ActiveX控件?
    • 有人知道"TransformNdll"这个文件吗?
    • VC与VB混合编程
    • VC工程插入一个OCX后,VC不能退出了
    • 各位高手,编写COMVC++60时,如何调用VB编写的OCX控件?
    • 有没有微软的ActiveX控件测试工具(ActiveXControlTestContainer的源码?
    • 如何让插件在未运行的时候就创建button

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有