Link to home
Start Free TrialLog in
Avatar of PeterMorrone
PeterMorrone

asked on

ATL Composite Control Sample

I am new to atl-I have created an atl composit control that contains 1 activex control.  I need to do the following.

1-Have the contained control always move/size to completely fill the atl control (IE I want the atl control to basically not exist from the users perspective).

2-I need the atl control to have an OLE verb called "Edit".  The Edit action needs to call a method on the control.  How to create the Edit Verb and How to call a method on the contained control?

3-I am inserting this control into Visio (a drawing program) When ever the Edit verb is executed I need the atl control to set the dirty flag so visio will see it as needing to be saved.  When visio saves the document I need the contained active x control to be persisted in the visio document. When visio loads the document I need the contained controls info put pack in the contained control.  Basically how to get the atl control to persist the activex control.

I know this is pretty broad but I need to get something like this working fast.  Code samples/snipets appreciated.
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterMorrone
PeterMorrone

ASKER

I went to the web site but the zip files were not there....
OK, the files are up. As usual for my samples, please use "Find in Files" to search for "//SAMPLE" to see the code I added above what the Wizard gave.

1) To do this, just handle OnSize() in the composite control. Turn around and size the contained OLE control after measuring the client area of the composite control.

2) I just added an Edit verb to both the XCTRL and the COMPER control. COMPER finds the dispid on the contained control and calls it with Invoke(). You add methods using the context menu in the ClassView.

3) Edit in the COMPER control sets m_bRequiresSave to let the persistance interfaces (eg, IPersistStream and IPersistStorage) know that the content is dirty.

If you have questions about the code, just ask 'em here.

..B ekiM
Sorry; I botched one of the ZIPs, so it took too long. They're up now.

..B ekiM
Mike,

I got the files and built them both, I went to Visio and inserted the Comper control and I got a Grey square that says "ATL Composite Control".  No X  or anything like that.  Any Ideas?
Which version of which Visio product are you using?

I did my testing with Test Container, since I don't have any Visio products.  Does it work in Test Container on your machine?

..B ekiM
I am using visio 2000 professional.  I tried it in the test container and it worked ok.  I have built controls with mfc and they work fine with visio as well.  I wonder if visio requires some other interface(s).  I will check out the other items and see if visio can shed some light on the subject.
I found a testing machine that has Visio 5.0 Standard.

If I insert a Comper, it draws correctly. If I click on something else in Visio, it deactivates the control and the control shows only a grey background and "ATL Composite Control", as you describe.

If I doulbe-click on the control, it activates and then draws correctly again.

That's what the ATL Composite Control does by default if it's not in-place active.

If you want to change that behaviour, you can add an override to your composite control class:

   virtual HRESULT OnDraw(ATL_DRAWINFO& di)
   {
      // your special drawing code here!
      return S_OK;
   }

Note that ATL destroys the contained dialog box when the control goes inactive--you can't show it when the control isn't active.  (Maybe with some crazy gyrations you can, but...)

..B ekiM
1-I dont see the Ole verb "edit" on the control.  What I need is how to get the control to handle the Ole verb (in mfc you would do a ON_OLEVERB(AFX_IDS_VERB_EDIT, propwindow)).


2-The issue of not drawing the control when not in-place active really sucks.  This is real important for display as well as printing from visio.  If you can figure out a good solution I would gladly increase the points to 750.  Otherwise I suppose I will need to go back to trying the same thing with the MFC Active X control.
1-I dont see the Ole verb "edit" on the control.  What I need is how to get the control to handle the Ole verb (in mfc you would do a ON_OLEVERB(AFX_IDS_VERB_EDIT, propwindow)).


2-The issue of not drawing the control when not in-place active really sucks.  This is real important for display as well as printing from visio.  If you can figure out a good solution I would gladly increase the points to 750.  Otherwise I suppose I will need to go back to trying the same thing with the MFC Active X control.
1) Oh!  You really did want a verb!  I added a method. Most people don't use OLE verbs anymore. I'll see if I can fix that around for you today.

2) I'll look into it.

..B ekiM
All this revolves around using the control in visio.  Visio, when you right click on it presents a list of the OLE verbs the control implements and alows you to specify which verb gets executed when you double click on the Control.
Any progress on this???
I've never heard of an OLE verb named EDIT. OLEverbs include:

  OLEIVERB_PRIMARY
  OLEIVERB_SHOW
  OLEIVERB_OPEN
  OLEIVERB_HIDE
  OLEIVERB_UIACTIVATE
  OLEIVERB_INPLACEACTIVATE
  OLEIVERB_DISCARDUNDOSTATE
  OLEIVERB_PROPERTIES

When I right-click on the control, I don't see the verb list you're talking about, or a way to set which verb happens when I double-click. Can you be more explicit about the locaiton of that command?  (Again, I'm using Visio Standard, and not Professional...)

..B ekiM
From the MFC Help,
*****************
COleControl::OnEdit
virtual BOOL OnEdit( LPMSG lpMsg, HWND hWndParent, LPCRECT lpRect );
......
Remarks

Call this function to cause the control to be UI activated. This has the same effect as invoking the control's OLEIVERB_UIACTIVATE verb.

This function is typically used as the handler function for an ON_OLEVERB message map entry. This makes an “Edit” verb available on the control's “Object” menu. For example:


***********************


SO I guess the edit verb is the UIACTIVATE verb.  I could just as easily use the OLEIVERB_PROPERTIES

verb.  That would be better in fact.  These verbs appear in visio when you right click on the control, the last item in the context menu is the "Control Name Object" submenu which lists the available verbs.  IN an mfc control, doing...
ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
would cause 'Edit' to appear in the menu.  Basically I want to hook a verb and bring up my own properties window.  I dont want to use the standard property dialog that MFC or ATL provide you with so that is why with MFC I used the Edit verb.  If we can trap the Properties verb and NOT bring up a normal propery sheet but call one of my methods that would be just as good.

All visio versions work the same regarding active x handling.  The double click behavior is specified in that same context menu, under the format submenu, under the behavior option.  This will bring up a dialog box with a tab called "Double Click" one of the options is "Ole Verb" and a pull down of all available verb will be seem.


Sorry I took so long getting back to you, I was away on business.  Any  ideas on getting the control to display when not active?  This is critical.  At this point, an MFC solution would also be acceptable.  If you can get the desired behavior in either MFC or ATL, I would increase the point value to 1000.  The goal ultimately is to have a contained activex control appear in visio, have a verb to bring up a custom dialog (not the normal properties dialog, however the property verb would be ok to use if we could trap it) and have the contained control allways show and print in visio.
Well, I guess the issue here is that there is probibly no easy way to render the contained control when the container control in not inplaceactive.  This would prevent proper printing and other issues.

If you cant help me on this issue then replay as such and I will award you the points for your time and answers to date.

Thanks