麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

在ActiveX控件中引入窗體技術(shù)

2019-11-17 05:32:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
一、引入Dialog技術(shù)

  下面介紹在制作ActiveX控件時(shí)引入有模式對(duì)話框技術(shù),制作步驟如下:

  創(chuàng)建一新的MFC ActiveX ControlWizard項(xiàng)目,取名為Hello,其他用缺省選項(xiàng);
 
  在ResourceView頁(yè)中新增一對(duì)話框資源,命名為IDD_HELLODIALOG,可以在對(duì)話框上放自己的控件;
 
  為對(duì)話框資源IDD_HELLODIALOG創(chuàng)建新類CHelloDialog,從CDialog繼續(xù);
 
  確認(rèn)在HelloCtrl.h中已加入語(yǔ)句#include "HelloDialog.h",為CHelloCtrl類添加成員變量CHelloDialog m_helloDialog;
 
  用ClassWizard在Automation頁(yè)中為CHelloCtrl添加一方法void DoHello(),外部名亦為DoHello;

void CHelloCtrl::DoHello() { // 顯示對(duì)話框 m_helloDialog.DoModal(); }

  可以用ActiveX Control Test Container測(cè)試Hello Control的DoHello方法。

  下面介紹在制作ActiveX控件時(shí)引入無(wú)模式對(duì)話框技術(shù),制作步驟如下:

  在上面工作的基礎(chǔ)上,用ClassWizard為CHelloCtrl添加WM_CREATE的處理函數(shù)OnCreate,在此創(chuàng)建無(wú)模式對(duì)話框;
 
  修改DoHello代碼,在此顯示對(duì)話框;

int CHelloCtrl::OnCreate (LPCREATESTRUCT lpCreateStruct) {
 if (COleControl::OnCreate(lpCreateStruct) == -1) return -1;
 // 創(chuàng)建對(duì)話框
 m_helloDialog.Create(IDD_HELLODIALOG);
 return 0;
}
void CHelloCtrl::DoHello() {
 // 顯示對(duì)話框
 m_helloDialog.ShowWindow(SW_SHOW);
}
  下面介紹制作以對(duì)話框作為界面的ActiveX控件技術(shù),制作步驟如下:

  在上面工作的基礎(chǔ)上,設(shè)置對(duì)話框資源IDD_HELLODIALOG屬性的Style頁(yè)為Style:Child、Border:Dialog Frame、Title Bar:unchecked;設(shè)置More Style頁(yè)為Visible:checked;Control:checked;設(shè)置Extended Styles頁(yè)為Static Edge:checked;
 
  在CHelloCtrl::OnCreate中寫(xiě)入m_helloDialog.Create(IDD_HELLODIALOG,this)語(yǔ)句;
 
  在CHelloCtrl::OnDraw中寫(xiě)入m_helloDialog.MoveWindow(rcBounds,TRUE);

int CHelloCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) {
 if (COleControl::OnCreate(lpCreateStruct) == -1) return -1;
 // 創(chuàng)建對(duì)話框
 m_helloDialog.Create(IDD_HELLODIALOG,this);
 return 0;
}
void CHelloCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) {
 // 定位Hello對(duì)話框
 m_helloDialog.MoveWindow(rcBounds,TRUE);
}
  二、引入FormView技術(shù)

  下面介紹在制作ActiveX控件時(shí)引入FormView技術(shù),制作步驟如下:

  在上面工作的基礎(chǔ)上,在ResourceView頁(yè)中新增一對(duì)話框資源,命名為IDD_HELLOFORMVIEW,可以在對(duì)話框上放自己的控件;
 
  設(shè)置對(duì)話框資源IDD_HELLODIALOG屬性的Style頁(yè)為Style:Child、Border:Dialog Frame、Title Bar:unchecked;設(shè)置More Style頁(yè)為Visible:checked;Control:checked;設(shè)置Extended Styles頁(yè)為Static Edge:checked;
 
  為對(duì)話框資源IDD_HELLOFORMVIEW創(chuàng)建新類CHelloFormView,從CFormView繼續(xù);
 
  在HelloFormView.h中將CHelloFormView的構(gòu)造函數(shù)CHelloFormView()和析構(gòu)函數(shù)virtual ~CHelloFormView()從PRotected改為public;
 
  在HelloFormView.h中對(duì)CHelloFormView類加入public friend class CHelloCtrl;
  
  確認(rèn)在HelloCtrl.h中已加入語(yǔ)句#include "HelloFormView.h",為CHelloCtrl類添加成員變量CHelloFormView m_helloFormView;
 
  修改CHelloCtrl::OnCreate函數(shù),在此創(chuàng)建m_helloFormView;
 
  修改DoHello代碼,在此顯示FormView;

int CHelloCtrl::OnCreate (LPCREATESTRUCT lpCreateStruct) {
 if (COleControl::OnCreate(lpCreateStruct) == -1) return -1;
 // 創(chuàng)建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對(duì)話框
 m_helloFormView.MoveWindow(rcBounds,TRUE);
}
  三、引入Document/View結(jié)構(gòu)技術(shù)

  下面介紹在制作ActiveX控件時(shí)引入Document/View技術(shù),制作步驟如下:

  在上面工作的基礎(chǔ)上,在Hello工程中用ClassWizard添加一新類CPrintFrame,取其父類為CFrameWnd;
 
  在PrintFrame.h中將CPrintFrame的構(gòu)造函數(shù)CPrintFrame()和析構(gòu)函數(shù)virtual ~CPrintFrame()從protected改為public;
 
  在Hello工程中用ClassWizard添加一新類CPrintView,取其父類為CView;
 
  在PrintView.h中將CPrintView的構(gòu)造函數(shù)CPrintView()和析構(gòu)函數(shù)virtual ~CPrintView()從protected改為public;
 
  在Hello工程中用ClassWizard添加一新類CPrintDoc,取其父類為CDocument;
 
  在PrintDoc.h中將CPrintDoc的構(gòu)造函數(shù)CPrintDoc()和析構(gòu)函數(shù)virtual ~CPrintDoc()從protected改為public;
 
  在Hello工程中用ClassWizard添加一新類CPrintThread,取其父類為CWinThread;
 
  在HelloCtrl.h文件中為CHelloCtrl類添加成員變量CPrintThread* m_pPrintThread,確認(rèn)在HelloCtrl.h中已加入語(yǔ)句#include "PrintThread.h";

void CHelloCtrl::DoHello() { // 創(chuàng)建打印線程 m_pPrintThread = (CPrintThread*) AfxBeginThread(RUNTIME_CLASS(CPrintThread), THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED, NULL); m_pPrintThread- >ResumeThread();}
 
  在PrintThread.h中添加新成員變量

  CPrintDoc* m_pPrintDoc和CPrintFrame* m_pPrintFrame,并在構(gòu)造函數(shù)和析構(gòu)函數(shù)中完成對(duì)它們的初始設(shè)置和清除,確認(rèn)在PrintThread.h中已加入語(yǔ)句#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中,進(jìn)行創(chuàng)建窗體CPrintFrame,確認(rèn)在PrintThread.cpp中已加入語(yǔ)句#include "PrintFrame.h";

BOOL CPrintThread::InitInstance(){
 // 創(chuàng)建文檔/視圖框架
 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中,添加成員函數(shù)CPrintDoc* GetDocument(),確認(rèn)在PrintView.h中已加入語(yǔ)句#include "PrintDoc.h";

CPrintDoc* CPrintView::GetDocument(){
 ASSERT(m_pDocument- >ISKINdOf (RUNTIME_CLASS(CPrintDoc)));
 return (CPrintDoc*)m_pDocument;
}
  四、實(shí)現(xiàn)ActiveX打印預(yù)覽技術(shù)

  下面介紹利用上面的技術(shù)成果來(lái)實(shí)現(xiàn)ActiveX的打印預(yù)覽技術(shù),實(shí)現(xiàn)步驟如下:

  在上面工作的基礎(chǔ)上,用ClassWizard對(duì)CPrintView類實(shí)現(xiàn)OnPreparePrinting函數(shù),如下:

BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo) { // 預(yù)備打印 return DoPreparePrinting(pInfo);}
  用ClassWizard在Automation頁(yè)中為CHelloCtrl添加一方法void DoPreview(),外部名亦為DoPreview;

void CHelloCtrl::DoPreview() {
 // 進(jìn)行打印預(yù)覽
 ::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添加成員函數(shù)LRESULT DoPreview(WPARAM wParam, LPARAM lParam)
 
  實(shí)現(xiàn)CPrintView::DoPreview如下:

LRESULT CPrintView::DoPreview(WPARAM wParam, LPARAM lParam){
 // 進(jìn)入打印預(yù)覽
 OnFilePrintPreview();
 return 0;
}
  為CPrintView添加public成員變量COleControl* m_pControlPreview,并初始化如下:

CPrintView::CPrintView(){
 m_pControlPreview=NULL;
 // 初始化要預(yù)覽的ActiveX控件類為空
}
  在CPrintView::OnDraw中對(duì)控件內(nèi)容進(jìn)行顯示:

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頁(yè)中為CHelloCtrl添加一方法void SetPreviewControl(),外部名亦為SetPreviewControl,對(duì)其實(shí)現(xiàn)如下:


void CHelloCtrl::SetPreviewControl() {
 // 設(shè)置要預(yù)覽的View
 CView* pView=m_pPrintThread- > m_pPrintFrame- >GetActiveView();
 CPrintView* pPrintView=(CPrintView*)pView;
 pPrintView- >m_pControlPreview=this;
}
  在ActiveX Control Test Container測(cè)試,激活方法次序?yàn)镈oHello、SetPreviewControl、DoPreview。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 成人在线激情视频 | 综合图区亚洲 | 狠狠干91 | 成人黄色小视频网站 | 免费视频观看 | aaaaa国产欧美一区二区 | 精品国产乱码久久久久久丨区2区 | www.mitao| 国产毛片网 | 日韩视频中文 | 国产午夜精品一区二区三区四区 | 国产男女 爽爽爽爽视频 | 中文字幕天堂在线 | sese在线视频 | 久久久久久免费免费 | 国产第一页精品 | 99riav视频一区二区 | 国产啊v在线观看 | 91成人天堂久久成人 | 一级精品| 国产精品一区二区手机在线观看 | 欧美一区黄色 | 草免费视频 | 91社| 国产九九热视频 | 精品一区二区三区在线观看国产 | 香蕉久草视频 | 国产午夜三级一区二区三桃花影视 | 久久国产精品成人免费网站 | 一级做a爱片性色毛片高清 日本一区二区在线看 | 日本成年免费网站 | 成人精品视频在线 | 成人偷拍片视频在线观看 | 精品久久久一二三区播放播放播放视频 | 色啪综合| 久久国产一二三 | 亚州精品国产 | 国产羞羞视频在线观看免费应用 | 国产成人在线播放视频 | 韩毛片| 国产精品欧美日韩一区二区 |