A while back, Mitchell wrote an article about MoreOver.com and their XML news sources (which are free for developers using them for non-profit purposes). Today, Mitchell takes that idea one step further and creates an ActiveX component that uses the MoreOver.com news feeds in a similar way. The component uses the XMLHTTP library and the MSXML parser to retrieve and process the news. This article also acts as a good introduction to ActiveX controls if you have never created one before.
A Real-Time ActiveX News Control - Compiling and using our new ActiveX control (Page 5 of 6 )
Because Visual Basic is such a tightly integrated IDE, all we have to do to compile and create our ActiveX control is choose File -> Make prjXMLNews.ocx. Visual Basic will handle the entire library linking and referencing process by itself.
Once the Visual Basic compiler has finished doing its thing, we will be left with a single file, prjXMLNews.ocx. Visual Basic automatically registers our new ActiveX control for us, so all that we have to do is add it to our project.
To do this, we fire up a new instance of Visual Basic and create a standard executable. Using the Project -> Components (or Ctrl+T) menu option, we simply add our ActiveX object as an available control ns our project, like this:
Click OK and take a look at your side tool bar. You should see a new control. Move your mouse over the control, and its tooltip text should display "ctrlNews":
Now it's simply a matter of double-clicking on the control to add it to our new projects main form. Notice how the control actually shows the news items on it? Resize the control to make sure all of the news items are displayed, and then run the app.
Moving your mouse over any of the labels will show the hand cursor. Clicking on one will open the URL of that news item in a new browser window. If you take your control and play around with it a bit, you can create a neat looking form, like mine, which is shown below:
Using our new ActiveX control on a web page is easy as well. Make sure you have your ActiveX controlís source coded loaded in Visual Basic. Now, click on the Play button. This will launch the ActiveX control in a new web browser window. View the source of that page, and copy the entire <OBJECT> tag. It should look something like this:
The classid value is a unique identifier which windows stores in the registry, along with other details of our new ActiveX control, such as its AppId, and ProgId. Simply paste the <OBJECT> tag into a HTML page and save that HTML page on your machine. Fire the page up in your web browser, and our new ActiveX control will be displayed: