COM/ActiveX

Lingfa Yang

  1. Wraps an ActiveX control in your own applications
  2. Embed ActiveX controls in Office
  3. Embed ActiveX controls in HTML
  4. Create your own ActiveX controls

| Word | Word Interop | PowerPoint | Excel | IE | WMP || dumcpp |

  1. Wraps an ActiveX control in your own applications

    Want to play music/movie in your own application? The simplest solution is to wrap an ActiveX control, for instance, Windows Media Player.

    Immediately, you get all benefit of Windows Media Player (WMP). You can play a wide range of audio and video, such as:
    void WindowMediaPlayer::open()
    {
    	QString fileFilters = tr("Video files (*.mpg *.mpeg *.avi *.wmv)\n"
    		"Audio files (*.mp3 *.wav)");
    	QString fileName = QFileDialog::getOpenFileName(this, 
    		tr("Select File"), ".", fileFilters);
    	if (fileName.isEmpty()) return;
    	openFile(fileName);
    }
    void WindowMediaPlayer::openFile(const QString &fileName)
    {
    	wmp->setProperty("URL", fileName);
    	this->setWindowTitle(fileName);
    }
    

    To set a Windows Media Player control:
    WindowMediaPlayer::WindowMediaPlayer()
    {
    	wmp = new QAxWidget;
    	//wmp->setControl("{6bf52a52-394a-11d3-b153-00c04f79faa6}");
    	wmp->setControl("WMPlayer.OCX.7"); // the same above
    	this->setCentralWidget(wmp);
    }
    

    To make a web browser in your own application you can wrap an IE seeminglessly.
    MicrosoftWebBrowser::MicrosoftWebBrowser()
    {
    	activeX = new QAxWidget;
    	//activeX->setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}");
        activeX->setControl("Shell.Explorer.2"); // The same above
    }
    

    COM/ActiveX/OLE automation is Microsoft technology used for developing reusable object oriented software components. There are tons of controls you can easily wrap up as a QAxWidget.

  2. Embed ActiveX controls in Office

    Want to listen to music and see the lyrics at the same time? Then, embed the player in a word or a PowerPoint file with the lyrics.

    Programmatically add a WMP control to PowerPoint COM:
    bool PptPackage::addWmpCtrl(const WmpContent &ax)
    {
    	PowerPoint::Slides* slides = Slides(); if(!slides) return false;
    	PowerPoint::Slide *slide = slides->Add(slides->Count()+1, 
    		PowerPoint::PpSlideLayout(12)); //ppLayoutBlank = 12
    
    	QString className = "WMPlayer.OCX.7";
    	PowerPoint::Shape *shape = slide->Shapes()->
    		AddOLEObject(100, 100, 512, 320, className, false);
    		
    	if(shape)
    	{
    		PowerPoint::OLEFormat* fmt = shape->OLEFormat();
    		QString ProgID = fmt->ProgID(); 
    		IDispatch *idispatch = fmt->Object();
    		if(idispatch)
    		{
    			WMPLib::IWMPPlayer wmp(idispatch);
    			QString url = ax.prefix() + ax.path();
    			//wmp.SetURL(	url ); // ?
    			wmp.dynamicCall("SetURL(QString)", url); // ok
    		}
    	}
    	return true;
    }
    

  3. Embed ActiveX controls in HTML

    Want to publish your nice music/movie clip? Then, simply embed the player in your web page like this:
    <object id="Player" 
    	classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" 
    	width="320" height="280" VIEWASTEXT>
    	<PARAM NAME="AutoStart" VALUE="False" />
    	<PARAM NAME="stretchToFit" VALUE="True" />
    	<!-- Use a minimal control panel -->
    	<PARAM NAME="uiMode" VALUE="full" />
    	<PARAM NAME="URL" 
    VALUE="http://hopf.chem.brandeis.edu/yanglingfa/music/Fmtest.mid" />
    </object>
    
    Use JavaScript in client-side DHTML or server-side PHP with database transaction you can build a music station.
  4. Create your own ActiveX controls

    • Image viewer
    • Toggle image viewer
    • Movie player
    • Table viewer
    • Xy Data plotter
    (underconstruction)

Dialogs | Model/View( List/Tree, Table, Network) | XML/ Office 2007 XML | COM/ActiveX | Network TCP/IP | OpenGL | Online Help ... || MyQt | Qt C++ | C/C++ | eBooks | mini_word.html