ATL Used for Connection Point and Toolbar Exposure

ActiveX Control as well as container, exposing toolbar. Includes event mapping of toolbar buttons at client side.

.



Click here for larger image

Environment: VC6 , NT4 , ATL 3.0

INTRODUCTION

The control, I'm presenting here is not a utility or something like that, rather it is one kind of implementation in ATL. Where I found lots of guys in problem. I tried to implement a very simple control to show connection point implementation as well as a toolbar on the control to expose the events at client side.

Here I'm providing a interface in the form of toolbar to capture the events at client side, but implemented at server side.

The another part what I trying to do that I'm inserting this control in an MFC FRAMEWORK MDI using application CFormView just to make that different. You can map events of the toolbar for all the different views. You can insert this control on VB Forms and dialog based application in VC. I'm also trying to provide a menu with the name of the control in which there is option to remove and add the toolbor of control on control AND to hide and show the control on view.

And finally, I'm not implementing the Button Command4 handler at client side. You can implement this handle yourself.

In the demo you will get a Client exe and server dll. To run the exe first register the dll.

I had implemented as a control as well as a container so that you can insert another control into this as a child. For example I'm inserting WEBBROWSER2 Control. Overall what I want to show is that whenever you have to fire the command on any toolbar button, a request goes to the server side and than it comes back with some data from the server. Here it is on the server:

LRESULT OnCommand3( WORD wNotifyCode, 
                    WORD wID, 
                    HWND hWndCtl, 
                    BOOL& bHandled)
{
   //Firing events to implement at the client side for ToolBar
   Fire_Command3(L"U Can Get the parameter From Server Side");
   return 0;
}

And here it comes with same string on client side:

void CATLDemoClientView::OnCommand3Democtrl(LPCTSTR szStr)
{
     AfxMessageBox(szStr);  
}

which I presenting through Message Box, but you can get the kind of data like this at client side to provide a good communication using Connection point implementation.

You don't need to expose any method of control to make a call on any event , the way usually in the books you can find. OR to implememnt the WM_TIMER on server side so that you can fire any event on some specific condition. NO NEED OF ALL THIS.

But the better way is to expose some UI to the user so that the body can implement the event's on the client side, like the MFC framework does.

Here I'm inserting the control in client side in a very simple way:

int CATLDemoClientView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
   if (CFormView::OnCreate(lpCreateStruct) == -1)
         return -1;

   if(!m_oDemoCtrl.Create( "DemoControl",
                           "DemoControl",
                            WS_CHILD|WS_VISIBLE|WS_BORDER,
                            CRect(0,0,1024,800),
                            this,
                            IDC_DEMOCTRL))
   {
       AfxMessageBox("Can't Create");
   }
   else
   {
       // Adding tool bar here after getting the 
       // window handle from control properties.
       CtrlWnd=m_oDemoCtrl.GetWindow();
       m_hCtrlWnd = (HWND)CtrlWnd;
       m_oDemoCtrl.AddToolBar(&CtrlWnd);
   }

   return 0;
}

And here I m implementing a another control as a child on server side:

LRESULT OnInitDialog( UINT uMsg,
                      WPARAM wParam, 
                      LPARAM lParam, 
                      BOOL& bHandled)
{
   AtlAdviseSinkMap(this,true);

   // Containg a Web Browser Control as container
   // and intiating the interface of that control
   // you can contain any existing control as a child
   // and can hadle the functionality using toolbar 

   GetDlgControl( IDC_EXPLORER, 
                  IID_IWebBrowser2,
                  (void**)&m_spWebBrowser);
   ATLASSERT(m_spWebBrowser);
   COleVariant noArg;
   //Showing URL
   m_spWebBrowser->Navigate( L"www.codeguru.com",
                             &noArg,
                             &noArg,
                             &noArg,
                             &noArg);
   return 0;
}

Downloads

Download demo project - 91 Kb
Download source - 133 Kb


About the Author

Pardeep Kadian

Be young by heart, sharp by mind.
doesn't matter to have a whisky or wine.
Neither it belong to you nor mine.
Keep learning to always have a shine.

Comments

  • Could you tell me how to implement a Timer Connectionpoint?

    Posted by Legacy on 12/30/2001 12:00am

    Originally posted by: Benny

    Hi, Great work!!! But how can I make the server fire event by broadcasting at intervals?
    

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds