+ All Categories
Home > Documents > ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The...

ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The...

Date post: 17-Jan-2016
Category:
Upload: brianne-summers
View: 292 times
Download: 11 times
Share this document with a friend
Popular Tags:
95
ActiveX Controls ActiveX Controls ActiveX Controls vs Ordinary ActiveX Controls vs Ordinary Windows Controls Windows Controls Installing ActiveX Controls Installing ActiveX Controls The Calendar Control The Calendar Control ActiveX Control Container ActiveX Control Container Programming Programming Create ActiveX Control at Create ActiveX Control at Runtime Runtime
Transcript
Page 1: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ActiveX ControlsActiveX Controls

ActiveX Controls vs Ordinary ActiveX Controls vs Ordinary Windows ControlsWindows Controls

Installing ActiveX ControlsInstalling ActiveX Controls

The Calendar ControlThe Calendar Control

ActiveX Control Container ActiveX Control Container ProgrammingProgramming

Create ActiveX Control at RuntimeCreate ActiveX Control at Runtime

Page 2: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ActiveX Controls vs. ActiveX Controls vs. Ordinary Windows ControlsOrdinary Windows Controls

Ordinary controls send notification command Ordinary controls send notification command messages (standard Windows messages), such messages (standard Windows messages), such as BN_CLICKED, to the dialog. as BN_CLICKED, to the dialog.

An ActiveX control doesn't send WM_ An ActiveX control doesn't send WM_ notification messages to its container the way notification messages to its container the way ordinary controls do; instead, it "ordinary controls do; instead, it "fires eventsfires events." ."

Events don't return a value to the ActiveX Events don't return a value to the ActiveX control.control.

Examples of events are Click, KeyDown, and Examples of events are Click, KeyDown, and NewMonth.NewMonth.

All the MFC control classes are derived from All the MFC control classes are derived from CWnd, so if you want to get the text from an CWnd, so if you want to get the text from an edit control, you call edit control, you call CWnd::GetWindowTextCWnd::GetWindowText. . But even that function works by sending a But even that function works by sending a message to the control. message to the control.

Page 3: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ActiveX Controls vs. ActiveX Controls vs. Ordinary Windows ControlsOrdinary Windows Controls

How ActiveX Controls Are How ActiveX Controls Are DifferentDifferent from Ordinary Controls—Properties from Ordinary Controls—Properties and Methodsand Methods

The most prominent ActiveX Controls features The most prominent ActiveX Controls features are properties and methods. are properties and methods.

Properties have symbolic names that are Properties have symbolic names that are matched to integer indexes. matched to integer indexes.

An event has a An event has a symbolic namesymbolic name and can have an and can have an arbitrary sequence of parametersarbitrary sequence of parameters

The generated The generated Dialog Data Exchange (DDX)Dialog Data Exchange (DDX) code exchanges data between the control code exchanges data between the control properties and the client class data members. properties and the client class data members.

Page 4: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ActiveX Controls vs. ActiveX Controls vs. Ordinary Windows ControlsOrdinary Windows Controls

A DLL is used to store one or more A DLL is used to store one or more ActiveX controls, but the DLL often has ActiveX controls, but the DLL often has an an OCX filenameOCX filename extension (.ocx) extension (.ocx) instead of a DLL extension. (.dll)instead of a DLL extension. (.dll)

Page 5: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Installing ActiveX Installing ActiveX ControlsControlsCopy the ActiveX control's DLL to \Winnt\Copy the ActiveX control's DLL to \Winnt\

System32 System32

Copy associated files such as Copy associated files such as help (HLP) or help (HLP) or license (LIC)license (LIC) files to the same directory. files to the same directory.

Register the control in the Register the control in the Windows Windows Registry.Registry. Actually, the ActiveX control Actually, the ActiveX control registers itself when a client program calls registers itself when a client program calls a special exported function. a special exported function.

The Windows utility The Windows utility Regsvr32Regsvr32 is a client is a client that accepts the that accepts the control namecontrol name on the on the command line. command line.

Install the ActiveX control Install the ActiveX control inin eacheach projectproject that uses it. that uses it.

Page 6: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Installing ActiveX Installing ActiveX ControlsControls

Choose Choose Add To Add To Project Project from the from the Project Project menu and menu and then then choose choose ComponentComponents And s And Controls. Controls. Select Select Registered Registered ActiveX ActiveX ControlsControls

Page 7: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Installing ActiveX Installing ActiveX ControlsControls

This gets This gets you the you the list of all list of all the the ActiveX ActiveX controls controls currently currently registered registered on your on your system. system.

Page 8: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

The Calendar ControlThe Calendar Control

Page 9: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

The Calendar ControlThe Calendar Control

   

   

   

   

   

   

Properties Methods Events

BackColor AboutBox AfterUpdate

Day NextDay BeforeUpdate

DayFont NextMonth Click

DayFontColor NextWeek DblClick

DayLength NextYear KeyDown

FirstDay PreviousDay KeyPress

GridCellEffect PreviousMonth KeyUp

GridFont PreviousWeek NewMonth

GridFontColor PreviousYear NewYear

GridLinesColor Refresh  

Month Today  

MonthLength    

ShowDateSelectors    

Page 10: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

The Calendar ControlThe Calendar Control

Each of the properties, methods, and Each of the properties, methods, and events has a corresponding integer events has a corresponding integer identifier. identifier.

Information about the names, types, Information about the names, types, parameter sequences, and integer parameter sequences, and integer IDs is IDs is stored inside the controlstored inside the control and is and is accessible to ClassWizard at accessible to ClassWizard at container container design timedesign time. .

Page 11: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Property AccessProperty Access

The ActiveX The ActiveX control control developer developer designates designates certain certain properties for properties for access at design access at design time. time.

Those Those properties are properties are specified in the specified in the property pages property pages that the control that the control displays in the displays in the dialog editor dialog editor when you right-when you right-click on a click on a control and control and choose choose Properties. Properties.

Page 12: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Property AccessProperty AccessWhen you click on When you click on the All tab, you the All tab, you will see a list of will see a list of all the design- all the design- time-accessible time-accessible properties, which properties, which might include a might include a few properties few properties not found on the not found on the Control tab Control tab All the control's All the control's properties, properties, including the including the design-time design-time properties, are properties, are accessible at accessible at runtime. Some runtime. Some properties, properties, however, might however, might be designated as be designated as read-only. read-only.

Page 13: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ClassWizard's C++ Wrapper ClassWizard's C++ Wrapper Classes for ActiveX ControlsClasses for ActiveX Controls

When you insert an ActiveX control When you insert an ActiveX control into a project, ClassWizard generates into a project, ClassWizard generates a C++ a C++ wrapper classwrapper class, derived from , derived from CWndCWnd, that is , that is tailoredtailored to your to your control's methods and properties. control's methods and properties.

The class has member functions for The class has member functions for all properties and methods, and it all properties and methods, and it has constructors that you can use to has constructors that you can use to dynamically create an instance of the dynamically create an instance of the control. control.

Page 14: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ClassWizard's C++ Wrapper ClassWizard's C++ Wrapper Classes for ActiveX ControlsClasses for ActiveX Controls

unsigned long CCalendar::GetBackColor()unsigned long CCalendar::GetBackColor()

{{

unsigned long result;unsigned long result;

InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYGET, InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL); VT_I4, (void*)&result, NULL);

return result;return result;

}}

void CCalendar::SetBackColor(unsigned long newValue)void CCalendar::SetBackColor(unsigned long newValue)

{{

static BYTE parms[] = VTS_I4;static BYTE parms[] = VTS_I4;

InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYPUT, InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYPUT,

VT_EMPTY, NULL, parms, newValue);VT_EMPTY, NULL, parms, newValue);

}}

Page 15: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ClassWizard's C++ Wrapper ClassWizard's C++ Wrapper Classes for ActiveX ControlsClasses for ActiveX Controls

short CCalendar::GetDay()short CCalendar::GetDay()

{ {

short result; short result;

InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_I2, InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);(void*)&result, NULL);

return result;return result;

}}

void CCalendar::SetDay(short nNewValue)void CCalendar::SetDay(short nNewValue)

{{

static BYTE parms[] = VTS_I2;static BYTE parms[] = VTS_I2;

InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, nNewValue); NULL, parms, nNewValue);

} }

Page 16: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ClassWizard's C++ Wrapper ClassWizard's C++ Wrapper Classes for ActiveX ControlsClasses for ActiveX Controls

COleFont CCalendar::GetDayFont()COleFont CCalendar::GetDayFont()

{{

LPDISPATCH pDispatch; LPDISPATCH pDispatch;

InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_DISPATCH, InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&pDispatch, NULL); (void*)&pDispatch, NULL);

return COleFont(pDispatch);return COleFont(pDispatch);

}}

void CCalendar::SetDayFont(LPDISPATCH newValue)void CCalendar::SetDayFont(LPDISPATCH newValue)

{{

static BYTE parms[] = VTS_DISPATCH; static BYTE parms[] = VTS_DISPATCH;

InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue); NULL, parms, newValue);

} }

Page 17: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ClassWizard's C++ Wrapper ClassWizard's C++ Wrapper Classes for ActiveX ControlsClasses for ActiveX Controls

VARIANT CCalendar::GetValue()VARIANT CCalendar::GetValue()

{ {

VARIANT result;VARIANT result;

InvokeHelper(0xc, DISPATCH_PROPERTYGET, VT_VARIANT, InvokeHelper(0xc, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL); (void*)&result, NULL);

return result;return result;

}}

void CCalendar::SetValue(const VARIANT& newValue)void CCalendar::SetValue(const VARIANT& newValue)

{{

static BYTE parms[] = VTS_VARIANT; static BYTE parms[] = VTS_VARIANT;

InvokeHelper(0xc, DISPATCH_PROPERTYPUT, VT_EMPTY, InvokeHelper(0xc, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, &newValue); NULL, parms, &newValue);

} }

Page 18: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ClassWizard's C++ Wrapper ClassWizard's C++ Wrapper Classes for ActiveX ControlsClasses for ActiveX Controls

void CCalendar::NextDay()void CCalendar::NextDay()

{ {

InvokeHelper(0x16, DISPATCH_METHOD, VT_EMPTY, NULL, InvokeHelper(0x16, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);NULL);

}}

void CCalendar::NextMonth()void CCalendar::NextMonth()

{ {

InvokeHelper(0x17, DISPATCH_METHOD, VT_EMPTY, NULL, InvokeHelper(0x17, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);NULL);

} }

Page 19: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

ClassWizard's C++ Wrapper ClassWizard's C++ Wrapper Classes for ActiveX ControlsClasses for ActiveX Controls

The first parameter of each The first parameter of each InvokeHelperInvokeHelper function match with the function match with the dispatch ID for the corresponding dispatch ID for the corresponding property or method in the Calendar property or method in the Calendar control property list.control property list.Properties always have separate Properties always have separate SetSet and and GetGet functions. functions. To call a method, simply call the To call a method, simply call the corresponding function. corresponding function.

To call the NextDay method from a To call the NextDay method from a dialog class function, you write code dialog class function, you write code such as this: such as this:

m_calendar.NextDay(); m_calendar.NextDay(); m_calendarm_calendar is an object of class is an object of class CCalendarCCalendar, , the wrapper class for the Calendar control. the wrapper class for the Calendar control.

Page 20: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Example—An ActiveX Example—An ActiveX Control Dialog Container Control Dialog Container

Step 1:Step 1:Verify that the Calendar control is Verify that the Calendar control is registered. If the control does not appear registered. If the control does not appear in the Visual C++ Gallery's Registered in the Visual C++ Gallery's Registered ActiveX Controls page, copy the files ActiveX Controls page, copy the files MSCal.ocx, MSCal.hlp, and MSCal.cnt to MSCal.ocx, MSCal.hlp, and MSCal.cnt to your system directory and register the your system directory and register the control by running the REGCOMP program. control by running the REGCOMP program.

Step 2:Step 2:Run AppWizard to produce \vcpp32\ex08a\Run AppWizard to produce \vcpp32\ex08a\ex08a.ex08a.

Accept all of the default settings but two: Accept all of the default settings but two: select Single Document and deselect select Single Document and deselect Printing And Print Preview. Printing And Print Preview.

Page 21: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 2:Step 2:

In the In the AppWizard AppWizard Step 3 Step 3 dialog, dialog, make sure make sure the ActiveX the ActiveX Controls Controls option is option is selected, as selected, as shown shown below. below.

Page 22: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 3: Install the Calendar Step 3: Install the Calendar control in the EX08A projectcontrol in the EX08A project. .

Choose Add To Choose Add To Project from Visual Project from Visual C++'s Project menu, C++'s Project menu, and then choose and then choose Components And Components And Controls. Controls. Choose Registered Choose Registered ActiveX Controls, and ActiveX Controls, and then choose Calendar then choose Calendar Control 8.0. Control 8.0. ClassWizard ClassWizard generates two classes generates two classes in the EX08A in the EX08A directorydirectory

Page 23: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 4: Edit the Calendar Step 4: Edit the Calendar control class to handle help control class to handle help messages.messages.

Page 24: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 4:Use the dialog editor to Step 4:Use the dialog editor to create a new dialog resource. create a new dialog resource.

Control ID

Calendar control IDC_CALENDAR1

Select Date button IDC_SELECTDATE

Edit control IDC_DAY

Edit control IDC_MONTH

Edit control IDC_YEAR

Next Week button IDC_NEXTWEEK

Make the Select Date button the default Make the Select Date button the default button. Drag the Calendar control from the button. Drag the Calendar control from the control palette. control palette.

Then set an appropriate tab order. Assign Then set an appropriate tab order. Assign control IDs as shown in the following table. control IDs as shown in the following table.

Page 25: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 5: Use ClassWizard to Step 5: Use ClassWizard to create the create the CActiveXDialogCActiveXDialog class class

Message Handler FunctionMessage Handler FunctionObject ID Message Member Function

CActiveXDialog WM_INITDIALOGOnInitDialog (virtual

function)

IDC_CALENDAR1 NewMonth (event) OnNewMonthCalendar1

IDC_SELECTDATE BN_CLICKED OnSelectDate

IDC_NEXTWEEK BN_CLICKED OnNextWeek

IDOK BN_CLICKED OnOK (virtual function)

Page 26: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 6:Use ClassWizard to add data Step 6:Use ClassWizard to add data members to the members to the CActiveXDialogCActiveXDialog class.class.Click on Click on

the the Member Member Variables Variables tab, and tab, and then add then add the data the data membersmembers

Page 27: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 8: Edit the Step 8: Edit the CActiveXDialogCActiveXDialog class.class.

Add the Add the m_varValuem_varValue and and m_BackColorm_BackColor data members, and data members, and then edit the code for the five then edit the code for the five handler functions handler functions OnInitDialogOnInitDialog, , OnNewMonthCalendar1OnNewMonthCalendar1, , OnSelectDateOnSelectDate, , OnNextWeekOnNextWeek, and , and OnOKOnOK. .

Page 28: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 9 : Step 9 : Connect the dialog Connect the dialog to the view.to the view.

Use ClassWizard to map the Use ClassWizard to map the WM_LBUTTONDOWN WM_LBUTTONDOWN message, and then edit the message, and then edit the handler function handler function

Page 29: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 10: Step 10: Edit the virtual Edit the virtual OnDrawOnDraw function in the file function in the file ex08aView.cpp.ex08aView.cpp. To prompt the user to press the To prompt the user to press the

left mouse button, replace the left mouse button, replace the code in the view class code in the view class OnDrawOnDraw function with this single line: function with this single line:

pDC->TextOut(0, 0, "Press the pDC->TextOut(0, 0, "Press the left mouse button here."); left mouse button here.");

Page 30: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

Step 11: Step 11: Build and test the Build and test the EX08A application.EX08A application.

Open the dialog, enter a date in the Open the dialog, enter a date in the three edit controls, and then click the three edit controls, and then click the Select Date button. Select Date button. Click the Next Week button. Click the Next Week button. Try moving the selected date directly Try moving the selected date directly to a new month, and observe the to a new month, and observe the message box that is triggered by the message box that is triggered by the NewMonth event.NewMonth event.Watch for the final date in another Watch for the final date in another message box when you click OK. message box when you click OK. Press the F1 key for help on the Press the F1 key for help on the Calendar control. Calendar control.

Page 31: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

31

MFC Drag and DropMFC Drag and Drop

Page 32: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

32

MFC Drag and DropMFC Drag and Drop

OLE supports this feature with its OLE supports this feature with its IDropSourceIDropSource and and IDropTargetIDropTarget interfaces plus some library code that manages interfaces plus some library code that manages the drag-and-drop process. the drag-and-drop process.

The MFC library offers good drag-and-drop support at the The MFC library offers good drag-and-drop support at the view level.view level.

Drag-and-drop transfers are immediate and independent of Drag-and-drop transfers are immediate and independent of the clipboard. the clipboard.

If the user cancels the operation, there's no "memory" of If the user cancels the operation, there's no "memory" of the object being dragged. the object being dragged.

Page 33: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

33

Drag-and-drop transfers should work consistently Drag-and-drop transfers should work consistently between applications, between windows of the between applications, between windows of the same application, and within a window. same application, and within a window.

When the user starts the operation, the cursor When the user starts the operation, the cursor should change to an arrow_rectangle should change to an arrow_rectangle combination. combination.

If the user holds down the Ctrl key, the cursor If the user holds down the Ctrl key, the cursor turns into a plus sign (+), which indicates that turns into a plus sign (+), which indicates that the object is being copied rather than moved. the object is being copied rather than moved.

MFC Drag and DropMFC Drag and Drop

Page 34: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

34

The Source Side of the TransferThe Source Side of the Transfer

COleDataSource::COleDataSource::DoDragDrop - DoDragDrop - COleDropSourceCOleDropSource

The Destination Side of the TransferThe Destination Side of the Transfer

OnDragEnterOnDragEnter Adjusts the focus rectangle and then calls Adjusts the focus rectangle and then calls OOnDragOver nDragOver

OnDragOverOnDragOver Moves the dotted focus rectangle and Moves the dotted focus rectangle and sets the drop sets the drop effect (determines cursor shape)effect (determines cursor shape)

OnDragLeaveOnDragLeave Cancels the transfer operation; returns Cancels the transfer operation; returns the rectangle the rectangle to its original position and sizeto its original position and size

OnDropOnDrop Adjusts the focus rectangle and then calls the Adjusts the focus rectangle and then calls the DoPaste DoPaste helper function to get formats from the helper function to get formats from the

data objectdata object

Page 35: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

35

The Drag-and-Drop SequenceThe Drag-and-Drop Sequence

Page 36: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

36

What is going on?What is going on?

User presses the left mouse button in the source User presses the left mouse button in the source view window. view window.

Mouse button handler calls Mouse button handler calls CRectTracker::HitTestCRectTracker::HitTest and finds out that the cursor was inside the and finds out that the cursor was inside the tracker rectangle. tracker rectangle.

Handler stores formats in a Handler stores formats in a COleDataSourceCOleDataSource object. object.

Handler calls Handler calls COleDataSource::DoDragDropCOleDataSource::DoDragDrop for for the data source. the data source.

Page 37: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

37

What is going on?What is going on?User moves the cursor to the view window of the User moves the cursor to the view window of the target application. target application.

OLE callsOLE calls IDropTarget::OnDragEnter IDropTarget::OnDragEnter and and OnDragOverOnDragOver for the for the COleDropTargetCOleDropTarget object, object, which calls the corresponding virtual functions in which calls the corresponding virtual functions in the target's view. The the target's view. The OnDragOverOnDragOver function is function is passed a passed a COleDataObjectCOleDataObject pointer for the source pointer for the source object, which the target tests for a format it can object, which the target tests for a format it can understand. understand.

OnDragOverOnDragOver returns a drop effect code, which returns a drop effect code, which OLE uses to set the cursor. OLE uses to set the cursor.

Page 38: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

38

What is going on?What is going on?

OLE calls OLE calls IDataSource::QueryContinueDragIDataSource::QueryContinueDrag on the source side to find out whether the drag on the source side to find out whether the drag operation is still in progress. The MFC operation is still in progress. The MFC COleDataSourceCOleDataSource class responds appropriately. class responds appropriately.

User releases the mouse button to drop the User releases the mouse button to drop the object in the target view window. object in the target view window.

OLE calls OLE calls IDropTarget::OnDropIDropTarget::OnDrop, which calls , which calls OnDropOnDrop for the target's view. Because for the target's view. Because OnDropOnDrop is is passed a passed a COleDataObjectCOleDataObject pointer, it can retrieve pointer, it can retrieve the desired format from that object. the desired format from that object.

When When OnDropOnDrop returns in the target program, returns in the target program, DoDragDropDoDragDrop can return in the source program. can return in the source program.

Page 39: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

39

OLE Embedded Components OLE Embedded Components and Containersand Containers

Page 40: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

40

OLE Embedded Components and OLE Embedded Components and ContainersContainersA A component component that supports that supports in-place activationin-place activation also also supports supports embedding embedding

BothBoth in-place activation and embedding in-place activation and embedding store their store their data in a container's documentdata in a container's document

The containerThe container can activate both. can activate both.

An in-place-capable component can run An in-place-capable component can run inside the inside the container application's main windowcontainer application's main window, taking over the , taking over the container's menu and toolbar, container's menu and toolbar,

An embedded component can run An embedded component can run only in its own only in its own windowwindow, and that window has a special menu that does , and that window has a special menu that does not include file commands. not include file commands.

Embedding relies on two key interfaces, Embedding relies on two key interfaces, IOleObjectIOleObject and and IOleClientSiteIOleClientSite,, which are used for in-place which are used for in-place activation as well. activation as well.

Page 41: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

41

Excel spreadsheet activated inside a Word document.Excel spreadsheet activated inside a Word document.

Page 42: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

42

MFC base classes—

COleIPFrameWnd, COleServerDoc, and COleServerItem.

• COleIPFrameWnd class is rather like CFrameWnd. It's your

application's main frame window, which contains the view.

• It has a menu associated with it, IDR_SRVR_INPLACE, which

will be merged into the container program's menu.

• The embedded menu is IDR_SRVR_EMBEDDED, and the

stand-alone menu is IDR_MAINFRAME.

•The COleServerDoc class is a replacement for CDocument.

It contains added features that support OLE connections to the

container.

.The COleServerItem class works with the COleServerDoc class.

Page 43: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

43

The EX28A Example—An MFC In-Place-Activated Mini-Server

Here are the steps for creating the program from scratch:

1.Run AppWizard to create the EX28A project in the \vcpp32\ex28a directory. Select Single Document interface. Click the Mini-Server

option in the AppWizard Step 3 dialog shown here.

Page 44: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

44

Page 45: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

45

2 Examine the generated files. You've got the familiar application, document, main frame, and

view files, but you've got two new files too.

Add a new menu command in both the embedded and in-place menus

Edit the view's OnDraw function

Edit the server item's OnDraw function.

Header Implementation

Class MFC Base Class

SrvrItem.h

SrvrItem.cpp CEx28aSrvrItem

COleServerItem

IpFrame.h IpFrame.cpp CInPlaceFrame COleIPFrameWnd

Page 46: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

46

10.Build and register the EX28A application. You must run the application directly once to update the

Registry.

11. Test the EX28A application. You need a container program that supports in-place activation. Use Microsoft Excel 97 or a later version if you have it, or build the project in the MFC DRAWCLI sample. Choose the container's Insert Object menu item. If this option does not appear on the Insert menu, it

might appear on the Edit menu instead. Then select Ex28a Document from the list.

When you first insert the EX28A object, you'll see a hatched border, which indicates that the object is in-

place active. The bounding rectangle is 3-by-3-cm square, with a 2-cm circle in the center, as illustrated

here. Output

Page 47: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

47

Page 48: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

48

ComponentComponent Object Model Object Model

Page 49: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

49

Component Object ModelComponent Object Model

COM is a powerful integrating technology.COM is a powerful integrating technology.

It allows developers to write software that It allows developers to write software that runs regardless of issues such as thread runs regardless of issues such as thread awareness and language choice.awareness and language choice.

Page 50: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

50

ComponentsComponents

Page 51: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

51

Benefits of Components Benefits of Components –– Component LibrariesComponent Libraries

Component Libraries New Program

Page 52: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

52

Benefits of COM Benefits of COM –– Distributed Distributed ComponentsComponents

Network

Page 53: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

53

Component Object ModelComponent Object Model

How should one chunk of software How should one chunk of software access the services provided by access the services provided by another chunk of software?another chunk of software?

COM: A standard approach to COM: A standard approach to access all kinds of software access all kinds of software services, regardless of how they services, regardless of how they are providedare provided

Page 54: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

54

COM is notCOM is not……

COM is not a programming languageCOM is not a programming language

COM is not DLLCOM is not DLL

COM is not only a set of API or COM is not only a set of API or functionsfunctions

Page 55: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

55

COM isCOM is……

with the benefits of object with the benefits of object orientationorientation

language independentlanguage independentCOM defines a binary interface that COM defines a binary interface that objects must supportobjects must support

with simple and efficient.with simple and efficient.

available on Windows, Windows available on Windows, Windows NT.NT.

Page 56: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

56

Basic COM ConceptBasic COM Concept

Binary Code of aServer Class

Interface

Interface

Interface

Binary Code of a Client Class

COMLibrary

Page 57: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

57

Basic COM ConceptBasic COM Concept

COM object

Server

Interface

Interface

Interface

Page 58: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

58

Basic COM ConceptBasic COM Concept

COM object

Client

Page 59: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

59

Identifying an InterfaceIdentifying an Interface

Human-readable nameHuman-readable name

Globally Unique Identifier (GUID)Globally Unique Identifier (GUID)

Interface Identifier (IID)Interface Identifier (IID)

Page 60: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

60

Interface Definition Interface Definition LanguageLanguage

uuid(E3BE7D4D-F26C-4C35-B694-uuid(E3BE7D4D-F26C-4C35-B694-ABA329A4A0E5),ABA329A4A0E5),

version(1.0),version(1.0),

helpstring("aks_ATL 1.0 Type helpstring("aks_ATL 1.0 Type Library")Library")

Page 61: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

61

Immutability of the Immutability of the InterfacesInterfaces

Once an interface has been Once an interface has been implemented in released software, it implemented in released software, it cannot be changedcannot be changed

To add new functionality or to modify To add new functionality or to modify existing functionality requires defining existing functionality requires defining an entirely new interface, with a new an entirely new interface, with a new and different IIDand different IID

The creator of the software is free to The creator of the software is free to stop supporting the original interface stop supporting the original interface but is absolutely prohibited from but is absolutely prohibited from changing itchanging it

Page 62: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

62

Changing Features to an interfaceChanging Features to an interface

The objectThe object’’s creator must define a new s creator must define a new interface, say interface, say ““multiplymultiply”” that includes that includes the new or changed methods and the the new or changed methods and the COM object continues to support COM object continues to support ““addadd”” as before, but it now also support as before, but it now also support ““multiplymultiply””..

Clients that are unaware of the Clients that are unaware of the upgrade never ask for a pointer to upgrade never ask for a pointer to ““mutiplymutiply””, they continue to use , they continue to use ““addadd”” as as beforebefore

Page 63: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

63

COM ClassesCOM Classes

Class identifier (CLSID) Class identifier (CLSID)

An object of a specific class supports a An object of a specific class supports a certain set of interfacescertain set of interfaces

An objectAn object’’s class identifies a particular s class identifies a particular implementation of a group of interfacesimplementation of a group of interfaces

Page 64: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

64

COM LibraryCOM Library

The COM library implements a The COM library implements a group of functions that supply group of functions that supply basic services to objects and their basic services to objects and their clientsclients

The COM libraryThe COM library’’s services are s services are accessed through accessed through ordinary ordinary function callsfunction calls

Page 65: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

65

System RegistrySystem RegistryThe classes of all objects that the The classes of all objects that the COM library will be asked to COM library will be asked to create on this machine must be create on this machine must be registeredregistered

Registry mapping includesRegistry mapping includes

CLSIDCLSID

Kinds of serversKinds of servers

Pathname for the file containing Pathname for the file containing the serverthe server’’s DLL or executable, s DLL or executable, or for where to find remote or for where to find remote serverserver’’s executables executable

Page 66: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

66

Creating a Single ObjectCreating a Single Object

Client

COMlibrary

Object

Server

CLSID_X

……

CLSID_Y

DLL

EXE

1 23

4

Page 67: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

67

Reusing COM ObjectsReusing COM ObjectsOne COM object canOne COM object can’’t reuse t reuse anotheranother’’s code through s code through inheritanceinheritance

Containment (delegation)Containment (delegation)

AggregationAggregation

Page 68: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

68

Marshaling and Type Marshaling and Type InformationInformation

Marshaling makes that the client Marshaling makes that the client can invoke the methods in the can invoke the methods in the same way, regardless of where same way, regardless of where the object is implementedthe object is implemented

Page 69: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

69

Kinds of COM ServersKinds of COM Servers

Machine XMachine Y

Page 70: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

70

Accessing a COM Object in Accessing a COM Object in an In-Process Serveran In-Process Server

Client Object

Client process

Page 71: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

71

Accessing a COM Object in Accessing a COM Object in a Local Servera Local Server

Proxy ObjectClient Stub

Client process Server Process

Single machine

Page 72: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

72

Accessing a COM object in Accessing a COM object in a Remote Servera Remote Server

Proxy ObjectClient Stub

Client process Server Process

Machine X Machine Y

Page 73: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

73

Page 74: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

74

CLICK FILE NEW TYPE PROJECT

NAME

Page 75: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

75

Page 76: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

76

Page 77: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

77

Page 78: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

78

GIVE COMONENT NAME

Page 79: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

79

Page 80: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

80

Page 81: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

81

TYPE NAME AND PARAMETERS

Page 82: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

82

Double Click

WRITE THE CODE

Page 83: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

83

SAVE SAVE

COMPILE by F7COMPILE by F7

COM CREATED SUCESSFULLYCOM CREATED SUCESSFULLY

Page 84: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

84

Page 85: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

85

Page 86: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

86

Page 87: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

87

Page 88: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

88

Page 89: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

89

Page 90: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

90

CLICK BROWSE AND SELECT THE COM PROJECT

Page 91: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

91

Page 92: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

92

Page 93: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

93

OPEN IT BY CLICKING THE ADD BUTTON

Page 94: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

94

RUN by F5 AND THEN CLICK ADD

Page 95: ActiveX Controls ActiveX Controls vs Ordinary Windows Controls Installing ActiveX Controls The Calendar Control ActiveX Control Container Programming Create.

95

Thanking YouThanking You


Recommended