Introduce form technology in the ActiveX control

xiaoxiao2021-03-06  13

Introduce form technology in the ActiveX control

1. Introducing Dialog Technology --- Introducing the Mode dialog technology when making an ActiveX control, the production steps are as follows:

Create a new MFC ActiveX ControlWizard project, named Hello, other default options;

Add a dialogue resource in the ResourceView page, named IDD_HELLODIALOG, you can put your own controls on the dialog;

Create a new class Chellodialog for dialog resource IDD_HELLODIALOG, inheriting from cdialog;

Confirm that the statement #include "hellodialog.h" has been added in Helloctrl.h, add member variables for the Chelloctrl class Chellodialog M_Hellodialog;

Add a method to Chelloctrl in the Automation page in the Automation page is also dohello; Void CHELLOCTRL :: DOHELLO () {// Display dialog m_hellodialog.domodal ()

---- You can test the Dohello method for Hello Control with ActiveX Control Test Container.

---- The following describes the introduction of the Mode dialog technology when making an ActiveX control, and the production steps are as follows:

On the basis of the above work, add WM_CREATE for Chelloctrl with classwizard, create a modified mode dialog box;

DoHello modified code on this dialog; int CHelloCtrl :: OnCreate (LPCREATESTRUCT lpCreateStruct) {if (COleControl :: OnCreate (lpCreateStruct) == -1) return -1; // create dialog m_helloDialog.Create (IDD_HELLODIALOG);

Return 0;}

Void chelloctrl :: dohello ()

{// Display dialog m_hellodialog.showwindow (sw_show);}

---- Introduction to the production of ActiveX control technology as the interface as the interface, the production steps are as follows:

On the basis of the above work, set the STYLE page for the dialog resource IDD_HELLODIALOG attribute to Style: Child, Border: Dialog Frame, Title Bar: unchecked; Setting more Bar: page is visible: checked; control: checked; settings Extended Styles page for static EDGE: CHECKED;

Write the m_hellodialog.create (IDD_hellodialog, this) statement in Chelloctrl :: OnCreate;

Writing m_helloDialog.MoveWindow (rcBounds, TRUE) in the CHelloCtrl :: OnDraw; int CHelloCtrl :: OnCreate (LPCREATESTRUCT lpCreateStruct) {if (COleControl :: OnCreate (lpCreateStruct) == -1) return -1; // create dialog m_hellodialog.create (IDD_HELLODIALOG, THIS); RETURN 0;}

Void CHELLOCTRL :: Ondraw (CDC * PDC, Const CRECT & RCBOUNDS, Const CRECT & RCINVALID) {// Location Hello dialog m_hellodialog.movewindow (rcbounds, true);} ---- II, introduced FormView technology

---- Introduce FormView technology when making ActiveX controls, the production steps are as follows:

On the basis of work above, add a dialog resource in the ResourceView page, named IDD_helloformView, you can put your own controls on the dialog;

Set the STYLE page for the dialog resource IDD_HELLODIALOG attribute for Style: Child, Border: Dialog Frame, Title Bar: Unchecked; Setting More Style page for Visible: Checked; Control: Checked; Setuped Styles page for static edge: checked;

Create a new class ChelloformView for dialog resource IDD_HELLOFORMVIEW, inheriting from CFormView;

CHELLOFORMVIEW's constructor chelloformview () and destructor virtual ~ chelloformView () change to public;

Add public Friend Class Chelloctrl to the Chelloformview class in HelloformView.h;

Confirm that the statement #include "helloformview. HinClude" HelloformView.h "is added in Helloctrl.h, add member variables for the Chelloctrl class ChelloformView M_HelloformView;

Modify the chelock :: oncreate function, create m_helloformview here;

DoHello modified code on this FormView; int CHelloCtrl :: OnCreate (LPCREATESTRUCT lpCreateStruct) {if (COleControl :: OnCreate (lpCreateStruct) == -1) return -1; // Create 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) {// Positioning Hello dialog m_helloformview.moveWindow (rcbounds, true);}

---- Third, introducing Document / View Structure Technology

---- Introduce Document / View technology when making ActiveX controls, the production steps are as follows:

On the basis of work above, add a new class CPrintFrame with ClassWizard in Hello Engineering, take the parent class as cframewnd;

CPRINTFRAME constructor CPRINTFRAME () and destructive functions virtual ~ cprintframe () change from protected to public;

Add a new class CPrintView with ClassWizard in Hello Engineering, take his parent class as cView; in PrintView.h, the CPRINTVIEW constructor CprintView () and destructor virtual ~ cprintView () are changed from protected to public;

Add a new class CPrintDoc with ClassWizard in Hello Engineering, take his parent class as cDocument;

CPRINTDOC constructor cprintdoc () and destructor Virtual ~ cprintdoc () change from protected to public;

Add a new class of CPRINTTTHREAD with ClassWizard in Hello Engineering, take his parent class as cwinthread;

Add HelloCtrl.h file for CHelloCtrl class member variables CPrintThread * m_pPrintThread, confirmed HelloCtrl.h been added statement #include "PrintThread.h"; void CHelloCtrl :: DoHello () {// Create a print thread m_pPrintThread = (CPrintThread *) AFXBEGINTHREAD (runtime_class (cprintthread), thread_priority_normal, create_suspended, null; m_pprintthread-> resumethread ();}

Add a new member variable CPRINTDOC * m_pprintdoc and cprintframe * m_pprintdocrame to PRINTTHREAD.H, and complete the initial settings and clearance of them in the constructor and the destructor, confirm that the statement #include "PrintDoc.h is added in PRINTTHREAD.H. "And #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;} in the PrintThread.cpp CPrintThread :: InitInstance, the created form CPrintFrame, confirmed PrintThread. The statement #include "printframe.h" is added in the CPP; Bool Cprintthread :: InitInstance () {// Create a document / view frame 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, "Print main form", WS_OVERLAPPEDWINDOW, CRect (0,0,100,100), NULL, NULL, 0, & context); Pframe-> InitialUpdateFrame (m_pprintdoc, true);

Return True;}

In CPrintView PrintView.h, add a member function CPrintDoc * GetDocument (), confirm PrintView.h been added statement #include "PrintDoc.h"; CPrintDoc * CPrintView :: GetDocument () {ASSERT (m_pDocument-> IsKindOf ( Runtime_class (cPrintDoc))))); return (cPrintDoc *) m_pdocument;} ---- Four, implement ActiveX print preview technology

---- Introduce the above technical results to achieve ActiveX print preview technology, the implementation steps are as follows:

On the basis of the above work, to achieve with ClassWizard CPrintView OnPreparePrinting function categories, as follows: BOOL CPrintView :: OnPreparePrinting (CPrintInfo * pInfo) {// ready to print return DoPreparePrinting (pInfo);} ClassWizard is used to add a CHelloCtrl page in Automation method void DoPreview (), the external name also DoPreview; void CHelloCtrl :: DoPreview () {// print preview :: PostMessage (m_pPrintThread-> m_pPrintFrame-> GetActiveView () -> m_hWnd, WM_USER_PREVIEW, 0,0);}

Add #define WM_USER_PREVIEW WM_USER 10 in PrintView.h

Added to the message map PrintView.cpp ON_MESSAGE (WM_USER_PREVIEW, DoPreview), is formed as follows: BEGIN_MESSAGE_MAP (CPrintView, CView) ON_MESSAGE (WM_USER_PREVIEW, DoPreview) // {{AFX_MSG_MAP (CPrintView) //}} AFX_MSG_MAPEND_MESSAGE_MAP ()

Add member functions for class CPRINTVIEW (WPARAM WPARAM, LPARAM LPARAM)

Implement CPRINTVIEW :: DOPREVIEW as follows: LRESULT CPRINTVIEW :: DOPREVIEW (WPARAM WPARAM, LPARAM LPARAM) {// Enter ONFILEPRINTPREVIEW ();

Return 0;}

Add public member variables for CPrintView ColeControl * m_pcontrolpreview, and initialize the following: cprintview :: CPrintView () {m_pcontrolpreview = null; // Initialize the ActiveX control class to preview to empty}

Display Void CprintView :: OnDRAW (CDC * PDC) {if (m_pcontrolpreview == null) PDC-> TextOut (0,0, "no preview view"; else {create control; m_pControlPreview-> GetClientRect (& controlRect); CRect previewRect (0,0, controlRect.Width (), controlRect.Height ()); m_pControlPreview-> OnDraw (pDC, controlRect, controlRect);}} ClassWizard is used in Automation page CHelloCtrl the method of adding a void SetPreviewControl (), the external name also SetPreviewControl, its realization as follows: void CHelloCtrl :: SetPreviewControl () {// set to preview ViewCView * pView = m_pPrintThread-> m_pPrintFrame-> GetActiveView (); CPrintView * pPrintView = (CPRINTVIEW *) PView; pprintview-> m_pControlPreview = this;} ---- In ActiveX Control Test Container test, the activation method order is Dohello, SetPREVIEWCONTROL, DOPREVIEW.

转载请注明原文地址:https://www.9cbs.com/read-46255.html

New Post(0)