请教关于如何在ActiveX中增加Frame框架???? 我想在ActiveX中加多组工具条,如何建立MFC中的frame框架啊??向大家请教! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一种最原始的办法是用API直接写 在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; // 创建FormViewm_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,"打印主窗体",WS_OVERLAPPEDWINDOW,CRect(0,0,100,100),NULL,NULL,0,&context);pFrame- >InitialUpdateFrame(m_pPrintDoc, TRUE);return TRUE;}在PrintView.h的CPrintView中,添加成员函数CPrintDoc* GetDocument(),确认在PrintView.h中已加入语句#include "PrintDoc.h"; CPrintDoc* CPrintView::GetDocument(){ASSERT(m_pDocument- >IsKindOf(RUNTIME_CLASS(CPrintDoc)));return (CPrintDoc*)m_pDocument;}---- 四、实现ActiveX打印预览技术 ---- 下面介绍利用上面的技术成果来实现ActiveX的打印预览技术,实现步骤如下: 在上面工作的基础上,用ClassWizard对CPrintView类实现OnPreparePrinting函数,如下: BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo) {// 准备打印return DoPreparePrinting(pInfo);}用ClassWizard在Automation页中为CHelloCtrl添加一方法void DoPreview(),外部名亦为DoPreview; void CHelloCtrl::DoPreview() {// 进行打印预览::PostMessage(m_pPrintThread- >m_pPrintFrame- >GetActiveView()- >m_hWnd,WM_USER_PREVIEW,0,0); }在PrintView.h中添加#define WM_USER_PREVIEW WM_USER+10在PrintView.cpp中的消息映射中添加ON_MESSAGE(WM_USER_PREVIEW, DoPreview),形成如下: BEGIN_MESSAGE_MAP(CPrintView, CView)ON_MESSAGE(WM_USER_PREVIEW, DoPreview)//{{AFX_MSG_MAP(CPrintView)//}}AFX_MSG_MAPEND_MESSAGE_MAP()为类CPrintView添加成员函数LRESULT DoPreview(WPARAM wParam, LPARAM lParam)实现CPrintView::DoPreview如下: LRESULT CPrintView::DoPreview(WPARAM wParam, LPARAM lParam){// 进入打印预览OnFilePrintPreview();return 0;}为CPrintView添加public成员变量COleControl* m_pControlPreview,并初始化如下: CPrintView::CPrintView(){m_pControlPreview=NULL; // 初始化要预览的ActiveX控件类为空}在CPrintView::OnDraw中对控件内容进行显示 void CPrintView::OnDraw(CDC* pDC){if (m_pControlPreview==NULL) pDC->TextOut(0,0,"No Preview View");else {CRect controlRect;m_pControlPreview- >GetClientRect(&controlRect);CRect previewRect(0,0,controlRect.Width(),controlRect.Height()); m_pControlPreview- >OnDraw(pDC,controlRect,controlRect); } }用ClassWizard在Automation页中为CHelloCtrl添加一方法void SetPreviewControl(),外部名亦为SetPreviewControl,对其实现如下: void CHelloCtrl::SetPreviewControl() {// 设置要预览的ViewCView* pView=m_pPrintThread- >m_pPrintFrame- >GetActiveView();CPrintView* pPrintView=(CPrintView*)pView;pPrintView- >m_pControlPreview=this;}---- 在ActiveX Control Test Container测试,激活方法次序为DoHello、SetPreviewControl、DoPreview。 感谢gjd111686(数字金刚)的资料,可是我不要借助于dialog类,直接找到一种创建Frame的方法 有引入Document/View结构技术的,里不就有直接创建CFrameWnd了吗 这是控件的创建函数了.[保证你申明了CFrameWnd的指针]int CWebOfficeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct){ if (COleControl::OnCreate(lpCreateStruct) == -1) return -1; // TODO: 在此添加您专用的创建代码 m_Rect.left=lpCreateStruct->x; m_Rect.top=lpCreateStruct->y; m_Rect.right=lpCreateStruct->cx-10; m_Rect.bottom=lpCreateStruct->cy-10; m_pWebOfficeFrame->m_FileName=m_FileName; m_pWebOfficeFrame->Create(NULL,_T(""),WS_CHILD,m_Rect,this); m_pWebOfficeFrame->ShowWindow(SW_SHOW); m_pWebOfficeFrame->UpdateWindow(); m_pWebOfficeFrame->SetActiveView((CView*)m_pWebOfficeFrame->m_pWebOfficeView); return 0;} 看看微软官方网站的讲解吧,你可以照着作一个试试:Designing ActiveX Components with the MFC Document/View Modelhttp://www.microsoft.com/mind/0497/mfc.asp www.codeproject.comWTL 中,有个这样的代码 MDI 的 Activex 神奇的_tcslen,求助 detours如何插入程序去拦截socket 函数,为什么我看到的例子全是鼠标和键盘,有拦截函数的吗 windows下编写IPv6程序时用到的函数包含在那个头文件中 简单的continue和break语句问题 ActiveX控件中创建CEdit的问题! 请问定义串行化类时IMPLEMENT_SERIAL(Data,CObject,1)宏应放在哪? 求救!关于切分窗口的隐藏 如何根据按键的vk值获得该按键的名称 救命! 发布时出错,高分求解 抓取命令行程序参数问题 send和recv ==== 请教 : 如何制作自动升级/更新 程序 ====
一、引入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,"打印主窗体",
WS_OVERLAPPEDWINDOW,CRect(0,0,100,100),
NULL,NULL,0,&context);
pFrame- >InitialUpdateFrame(m_pPrintDoc, TRUE);return TRUE;
}在PrintView.h的CPrintView中,添加成员函数CPrintDoc* GetDocument(),确认在PrintView.h中已加入语句#include "PrintDoc.h";
CPrintDoc* CPrintView::GetDocument()
{
ASSERT(m_pDocument- >IsKindOf
(RUNTIME_CLASS(CPrintDoc)));
return (CPrintDoc*)m_pDocument;
}
---- 四、实现ActiveX打印预览技术 ---- 下面介绍利用上面的技术成果来实现ActiveX的打印预览技术,实现步骤如下: 在上面工作的基础上,用ClassWizard对CPrintView类实现OnPreparePrinting函数,如下:
BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 准备打印
return DoPreparePrinting(pInfo);
}
用ClassWizard在Automation页中为CHelloCtrl添加一方法void DoPreview(),外部名亦为DoPreview;
void CHelloCtrl::DoPreview()
{
// 进行打印预览
::PostMessage(m_pPrintThread- >m_pPrintFrame- >
GetActiveView()- >m_hWnd,WM_USER_PREVIEW,0,0);
}在PrintView.h中添加#define WM_USER_PREVIEW WM_USER+10在PrintView.cpp中的消息映射中添加ON_MESSAGE(WM_USER_PREVIEW, DoPreview),形成如下:
BEGIN_MESSAGE_MAP(CPrintView, CView)
ON_MESSAGE(WM_USER_PREVIEW, DoPreview)
//{{AFX_MSG_MAP(CPrintView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()为类CPrintView添加成员函数LRESULT DoPreview(WPARAM wParam, LPARAM lParam)实现CPrintView::DoPreview如下:
LRESULT CPrintView::DoPreview
(WPARAM wParam, LPARAM lParam)
{
// 进入打印预览
OnFilePrintPreview();return 0;
}
为CPrintView添加public成员变量COleControl* m_pControlPreview,并初始化如下:
CPrintView::CPrintView()
{
m_pControlPreview=NULL; //
初始化要预览的ActiveX控件类为空
}在CPrintView::OnDraw中对控件内容进行显示
void CPrintView::OnDraw(CDC* pDC)
{
if (m_pControlPreview==NULL)
pDC->TextOut(0,0,"No Preview View");
else {
CRect controlRect;
m_pControlPreview- >GetClientRect(&controlRect);
CRect previewRect(0,0,controlRect.
Width(),controlRect.Height());
m_pControlPreview- >OnDraw
(pDC,controlRect,controlRect);
}
}
用ClassWizard在Automation页中为CHelloCtrl添加一方法void SetPreviewControl(),外部名亦为SetPreviewControl,对其实现如下:
void CHelloCtrl::SetPreviewControl()
{
// 设置要预览的View
CView* pView=m_pPrintThread- >
m_pPrintFrame- >GetActiveView();
CPrintView* pPrintView=(CPrintView*)pView;
pPrintView- >m_pControlPreview=this;
}---- 在ActiveX Control Test Container测试,激活方法次序为DoHello、SetPreviewControl、DoPreview。
int CWebOfficeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1; // TODO: 在此添加您专用的创建代码
m_Rect.left=lpCreateStruct->x;
m_Rect.top=lpCreateStruct->y;
m_Rect.right=lpCreateStruct->cx-10;
m_Rect.bottom=lpCreateStruct->cy-10;
m_pWebOfficeFrame->m_FileName=m_FileName;
m_pWebOfficeFrame->Create(NULL,_T(""),WS_CHILD,m_Rect,this);
m_pWebOfficeFrame->ShowWindow(SW_SHOW);
m_pWebOfficeFrame->UpdateWindow();
m_pWebOfficeFrame->SetActiveView((CView*)m_pWebOfficeFrame->m_pWebOfficeView);
return 0;
}
http://www.microsoft.com/mind/0497/mfc.asp